Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SqlAlchemy Postgres JSON how to filter with question mark operator?

I'm struggling to convert this to an ORM filter query:

select count(*) from issues WHERE pending_notifications ? 'flooby';

pending_notifications is a JSONB field containing a simple JSON array.

I'm not sure how to structure the filter using the question mark operator

I believe a Postgres ARRAY would work like this:

query.filter(pending_notifications.any('flooby'))

But I'm using JSONB and the filter syntax is not the same.

Any suggestions

like image 512
Duke Dougal Avatar asked Sep 02 '25 04:09

Duke Dougal


1 Answers

You can use the .op() method to use any verbatim operator:

query.filter(pending_notifications.op("?")("flooby"))
like image 108
univerio Avatar answered Sep 04 '25 20:09

univerio