相关疑难解决方法(0)

如何按字符串长度过滤`sqlalchemy`?

如何sqlalchemy按字符串长度过滤?

此代码段:

sess.query(db.ArticlesTable).filter(or_(
    and_(db.ArticlesTable.shorttext.length > 0),
         ...
Run Code Online (Sandbox Code Playgroud)

给了我以下错误:

File "./aggregate_news.py", line 69, in is_acceptable
    db.ArticlesTable.shorttext.length > 0),
  File ".../sqlalchemy/orm/attributes.py", line 211, in __getattr__
    key)
AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' 
    object associated with ArticlesTable.shorttext has an attribute 'length'
Run Code Online (Sandbox Code Playgroud)

在哪里ArticlesTable:

class ArticlesTable(Base):
    __tablename__ = TABLE_ARTICLES
    id = Column(Integer, primary_key=True)
    shorttext = Column(String)
    ...
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy

12
推荐指数
1
解决办法
6826
查看次数

标签 统计

python ×1

sqlalchemy ×1