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
Post a Comment