PostgreSQL ILIKE 查询与 SQLAlchemy [英] PostgreSQL ILIKE query with SQLAlchemy
本文介绍了PostgreSQL ILIKE 查询与 SQLAlchemy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想运行一个查询,选择所有标题与 '%' + [some_phrase] + '%'
匹配的帖子,不区分大小写.也就是说,选择标题中包含一些短语的所有行,不区分大小写.根据我所做的研究,看起来我需要使用 Postgres 的 ILIKE 查询来匹配不区分大小写的.如何使用 SQLAlchemy 执行这样的查询?
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 titles that contain some phrase, case insensitive. From the research I've done, it looks like I need to use Postgres's ILIKE query for it to match case insensitive. How can I execute a query like this with SQLAlchemy?
class Post(db.Model):
id = db.Column(db.Integer, primary_key = True)
title = db.Column(db.String(250))
content = db.Column(db.String(5000))
推荐答案
我觉得应该可以
Post.query.filter(Post.title.ilike('%some_phrase%'))
这篇关于PostgreSQL ILIKE 查询与 SQLAlchemy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文