How to filter in `sqlalchemy` by string length?

后端 未结 1 722
醉梦人生
醉梦人生 2020-12-20 12:25

How to filter in sqlalchemy by string length?

This code snippet:

sess.query(db.ArticlesTable).filter(or_(
    and_(db.ArticlesTable.shor         


        
相关标签:
1条回答
  • 2020-12-20 13:03

    You need to use the func SQL function generator to create a LENGTH() function:

    from sqlalchemy.sql.expression import func
    
    sess.query(db.ArticlesTable).filter(or_(
        and_(func.length(db.ArticlesTable.shorttext) > 0),
    
    0 讨论(0)
提交回复
热议问题