postgresqlwhere-clausesql-likecase-insensitive

How to make "case-insensitive" query in Postgresql?


Is there any way to write case-insensitive queries in PostgreSQL, E.g. I want that following 3 queries return same result.

SELECT id FROM groups where name='administrator'

SELECT id FROM groups where name='ADMINISTRATOR'

SELECT id FROM groups where name='Administrator'

Solution

  • Use LOWER function to convert the strings to lower case before comparing.

    Try this:

    SELECT id 
      FROM groups
     WHERE LOWER(name)=LOWER('Administrator')