hugsql

richiardiandrea 2021-03-15T20:14:21.005700Z

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.summers 2021-03-15T20:56:50.006800Z

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

richiardiandrea 2021-03-15T23:39:05.007100Z

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));

👍 1