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?session.add(MyTable(data={"rule": "foo"})); session.flush(); session.query(MyTable)...) Perhaps you don't have any rows in your table?(u'foo',). When you say the result is empty,my_queryis the empty list?