Rails + PostgreSQL-使用类似 [英] Rails + PostgreSQL -Using Like

查看:129
本文介绍了Rails + PostgreSQL-使用类似的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下两个查询:

SELECT users.* FROM "users" WHERE (fname || lname LIKE '%james%')

SELECT users.* FROM "users" WHERE (fname || lname LIKE '%James%')

我在用户表中有一条记录,其中fname = James

I have a record in the User Table with fname = James

我遇到的问题是第一个查询返回0个结果,第二个返回正确的结果。

The problem I'm having is the first query returns 0 results, and the 2nd returns the correct result.

我希望LIKE不区分大小写。有想法吗?谢谢

I want the LIKE to be case insensitive. Ideas? Thanks

推荐答案

选择用户。*从用户位置(fname || lname ILIKE'%james %')

ILIKE =不区分大小写的LIKE。请注意,这特定于PostgreSQL,而不是SQL标准。

ILIKE = case-insenstive LIKE. Note that this is specific to PostgreSQL, and not a SQL standard.

这篇关于Rails + PostgreSQL-使用类似的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆