如何使用SqlAlchemy在Postgres中查询JSON的数组?

时间:2019-05-12 17:31:31

标签: python postgresql sqlalchemy

class CastingArray(ARRAY):
    def bind_expression(self, bindvalue):
        return cast(bindvalue, self)

class Flavor(db.Model):
    __tablename__ = 'flavor'
    applications = Column(CastingArray(JSON))

flavor = Flavor(
    applications = [
      {
        "category": "Bakery",
        "recomended_dosage": 1,
        "sub_application": "Baked goods",
        "sub_application_details": [
          "Bagels",
          "Fillings"
        ]
      }
    ]
)

list_category = ["Bakery", ...],
list_sub_application_detail = ["Bagels", ...]

我想尝尝 category中的任何list_category 以及sub_application_details中的任何list_sub_application_detail

0 个答案:

没有答案