Query a specific JSON column (postgres) with sqlalchemy

后端 未结 2 1421
天命终不由人
天命终不由人 2021-01-06 09:37

I have a model with a JSON field:

class Item(db.Model)
   ...
   data = db.Column(JSON, nullable=False)
   ...

The data contains some JSON

2条回答
  •  隐瞒了意图╮
    2021-01-06 10:10

    You need to use Float instead of Integer as argument of cast

    db.session.query(func.count(Item)).filter(
              Item.data['surcharge'].cast(Float) > 1
          ).all()
    

提交回复
热议问题