PostgreSQL ILIKE query with SQLAlchemy

后端 未结 2 1015
日久生厌
日久生厌 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:09

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

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

提交回复
热议问题