PostgreSQL ILIKE query with SQLAlchemy

后端 未结 2 1104
日久生厌
日久生厌 2021-01-07 18:45

I\'d like to run a query that selects all posts, case insensitive, that have titles that match \'%\' + [some_phrase] + \'%\'. That is, select all rows that have

2条回答
  •  没有蜡笔的小新
    2021-01-07 19:12

    I think it should work

    Post.query.filter(Post.title.ilike('%some_phrase%'))
    

    http://docs.sqlalchemy.org/en/latest/orm/internals.html?highlight=ilike#sqlalchemy.orm.attributes.QueryableAttribute.ilike

提交回复
热议问题