Skip to content Skip to sidebar Skip to footer

How To Filter In `sqlalchemy` By String Length?

How to filter in sqlalchemy by string length? This code snippet: sess.query(db.ArticlesTable).filter(or_( and_(db.ArticlesTable.shorttext.length > 0), ... gave me

Solution 1:

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),

Post a Comment for "How To Filter In `sqlalchemy` By String Length?"