4

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

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks guys. I gave this the answer as it has an explanation.
3

Try using

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

Notice the 'I' in LIKE

Comments

0

Queries with "LIKE" or "ILIKE" are pretty slow, especially for tables with many entries. I think it would be faster if you use the full text search ability of PostgreSQL.

PostgreSQL textsearch docs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.