Fork me on GitHub
#hugsql
<
2021-03-15
>
richiardiandrea20:03:21

Hi there is there anyone using Postgres JSONB operators with Hugsql? I am seeing this

[SELECT * FROM reports
ā”‚ WHERE image_descriptors @> '[{"image-id":"' ? '"}]'; fe4cf22c-6779-492f-b2a0-f7180c00a964]
But it does not work at the moment - original query being
-- :name report-by-image-id :? :*
SELECT * FROM reports
WHERE image_descriptors @> '[{"image-id":"' :image-id '"}]';

curtis.summers20:03:50

I think you should concatenate your strings in SQL: @> '[{"image-id":"' || :image-id || '"}]';

richiardiandrea23:03:05

thanks Curtis for your answer, that makes sense I eventually went for

SELECT * FROM reports
WHERE image_descriptors @> jsonb_build_array(json_build_object('image-id', :image-id));

šŸ‘ 3