Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails + PostgreSQL -Using Like

I have the following two queries:

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

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

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

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

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

like image 957
AnApprentice Avatar asked Jan 22 '23 00:01

AnApprentice


1 Answers

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

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

like image 169
Ben Lee Avatar answered Jan 25 '23 05:01

Ben Lee