我正在嘗試使用可變數(shù)組來存儲(chǔ)帶有 SQLAlchemy 和 Postgres 的數(shù)據(jù)并編寫了這些類:class MutableList(Mutable, list): def append(self, value): list.append(self, value) self.changed() def pop(self, index=0): value = list.pop(self, index) self.changed() return value @classmethod def coerce(cls, key, value): if not isinstance(value, MutableList): if isinstance(value, list): return MutableList(value) return Mutable.coerce(key, value) else: return valueclass Lead(db.Model): __tablename__ = 'leads' ... starred = db.Column(MutableList.as_mutable(db.ARRAY(db.Integer)))我可以更新加星標(biāo)的屬性,從它追加和彈出項(xiàng)目。我的問題是如何搜索在數(shù)組中具有特定項(xiàng)目的行。這是我的查詢:leads = Lead.query.order_by(Lead.post_date.desc()).filter(Lead.starred.contains(current_user.id)).all()但這給了我以下錯(cuò)誤: ARRAY.contains() not implemented for the base ARRAY type; please use the dialect-specific ARRAY type我在這里缺少什么?
如何在可變數(shù)組中使用 SQLAlchemy 進(jìn)行搜索
動(dòng)漫人物
2021-07-02 14:18:32