When using sqlalchemy with postgresql, I have the following table and data:
id | data
----+----------
1 | {}
2 | {"a": 1}
(2 rows)
How do I find row(s) that does not have a key. e.g. "a" or data["a"]?
Give me all objects that does not have the key a.
id | data
----+----------
1 | {}
(1 row)
self.session.query(Json_test).filter(???)
If the column type is jsonb
you can use has_key
:
session.query(Json_test).filter(sqlalchemy.not_(Json_test.data.has_key('a')))
For both json
and jsonb
types this should work:
session.query(Json_test).filter(Json_test.data.op('->')('a')==None)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With