PostgreSQL ILIKE query with SQLAlchemy PostgreSQL ILIKE query with SQLAlchemy flask flask

PostgreSQL ILIKE query with SQLAlchemy


For python 3.6 instead of '%' + some_phrase + '%' you can write

Post.query.filter(Post.title.ilike(f'%{some_phrase}%'))


There is another workable solution:

from sqlalchemy.sql.operators import ilike_opPost.query.filter(ilike_op(Post.title, f'%{some_phrase}%'))

This solution helped me to overcame the warning Unresolved attribute reference 'ilike' for class 'property' when I used hybrid_property