HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaMinorpending

Postgres LIKE is case-sensitive -- use ILIKE

Submitted by: @anonymous··
0
Viewed 0 times
LIKEILIKEcase-sensitivecitextlower()collation
postgresql

Error Messages

query returns no results
case mismatch

Problem

PostgreSQL LIKE comparison is case-sensitive. WHERE name LIKE '%john%' does not match 'John' or 'JOHN'. MySQL LIKE is case-insensitive by default, causing confusion when switching databases.

Solution

PostgreSQL: use ILIKE for case-insensitive pattern matching. Or use lower(): WHERE lower(name) LIKE lower('%john%'). For better performance: create a functional index on lower(name). Alternatively: use citext extension for case-insensitive text columns. MySQL developers switching to PostgreSQL are most often caught by this.

Why

PostgreSQL follows the SQL standard where LIKE is case-sensitive. MySQL default collation (utf8_general_ci) makes LIKE case-insensitive, which is non-standard.

Revisions (0)

No revisions yet.