Reputation: 151
I am trying to query with in json column in postgresql with flask-sqlalchemy
.
here is my code
house_ = House()
results = house_.query.filter(
House.information['branch_name'].astext == 'release0'
).all()
I am not sure what is wrong.
I tried to use .cast(Unicode)
instead of astext
as well.
Getting error as below:
NotImplementedError: Operator 'getitem' is not supported on this expression
Upvotes: 1
Views: 1519
Reputation: 1313
You shold use 'op' method in your query, like this:
Session.query(Model).filter(Model.json_field.op('->')('KEY') == VALUE)
Also, you can use - >> JSON operator for auto-cast value to text. Also, you can read more about Postgresql JSON(B) operators :)
Upvotes: 6