python - How to filter in `sqlalchemy` by string length? -


how filter in sqlalchemy string length?

this code snippet:

sess.query(db.articlestable).filter(or_(     and_(db.articlestable.shorttext.length > 0),          ... 

gave me following error:

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 articlestable.shorttext has attribute 'length' 

where articlestable is:

class articlestable(base):     __tablename__ = table_articles     id = column(integer, primary_key=true)     shorttext = column(string)     ... 

you need use func sql function generator create length() function:

from sqlalchemy.sql.expression import func  sess.query(db.articlestable).filter(or_(     and_(func.length(db.articlestable.shorttext) > 0), 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -