我尝试使用可变数组来存储SQLAlchemy和Postgres中的数据,并编写了以下类:
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 value
class Lead(db.Model):
__tablename__ = 'leads'
...
starred = db.Column(MutableList.as_mutable(db.ARRAY(db.Integer)))
我可以更新started属性,从中添加和弹出项目。我的问题是如何搜索数组中具有特定项的行。我的问题是:
^{pr2}$但这给了我以下错误:ARRAY.contains() not implemented for the base ARRAY type; please use the dialect-specific ARRAY type
我错过了什么?在
似乎} 。相反,您应该使用特定于方言的类型(如错误中所述)^{} 。简而言之:
db.ARRAY
是SQL标准/多供应商数组类型^{用这个。在
相关问题 更多 >
编程相关推荐