I am trying to query for a field in JSON column (Postgres):
class MyTable(Base):
__tablename__ = 'my_table'
data = Column(JSONB)
Query:
my_query = session.query(MyTable).limit(10).with_entities(MyTable.data['rule']).all()
I get no error, but the result is empty.
Even if I try with astext
, same empty result:
my_query = session.query(MyTable).limit(10).with_entities(MyTable.data['rule'].astext).all()
Can I use with_entities in this case? What would be the work around? Thanks.
['rule']
part be on the result, not in the with_entities field? – Paul Becotte Jul 27 at 18:34session.add(MyTable(data={"rule": "foo"})); session.flush(); session.query(MyTable)...
) Perhaps you don't have any rows in your table? – univerio Jul 27 at 19:48(u'foo',)
. When you say the result is empty,my_query
is the empty list? – univerio Jul 27 at 20:04