// strings reference

SQL case-insensitive comparison

UPPER(col) = UPPER(?) kills indexes. Every engine has a collation-level answer that keeps matching fast and locale-correct.

Category
Strings
Returns
string
In this category
32 of 172

Syntax

col = 'value' COLLATE ci_collation
col ILIKE 'value'

Each block is a separate form. The support table and the examples show which engine takes which.

Engine support

EngineSupportNotes
SQL Server Yes Supported under this name.
PostgreSQL Yes Supported under this name.
MySQL Yes Supported under this name.
SQLite Yes Supported under this name.
Oracle Yes Supported under this name.

Examples

PostgreSQL

SELECT * FROM users WHERE email ILIKE '[email protected]';

SQLite

SELECT 'abc' = 'ABC' COLLATE NOCASE AS eq;  -- 1

Oracle

SELECT * FROM users
WHERE email = '[email protected]';  -- with NLS_COMP=LINGUISTIC + NLS_SORT=BINARY_CI

Good to know

  • SQL Server: default collations are already case-insensitive; pick a _CS collation per column or query for the rare case-sensitive match.
  • PostgreSQL: = is case-sensitive; use ILIKE, the citext extension type, or a *_ci ICU collation (PG 12+).
  • MySQL: default collations end in _ci (case-insensitive); _bin and utf8mb4_0900_as_cs are the case-sensitive ones.
  • SQLite: = is case-sensitive while LIKE is case-insensitive for ASCII only; declare columns COLLATE NOCASE to make = insensitive too.

Questions about Case-insensitive comparison

Is UPPER(col) = UPPER('x') wrong?

It works but disables a plain index on col and can be locale-wrong (Turkish I). A case-insensitive collation or citext does the same job and can use an ordinary index; PostgreSQL's ILIKE matches case-insensitively but cannot use a plain b-tree index either.

Why does my WHERE clause behave differently in SQLite?

SQLite's LIKE ignores case for ASCII only, while = is exact. Adding COLLATE NOCASE to the column definition lines them up.

Do case-insensitive collations ignore accents?

SQL Server's _AI collations and MySQL's _ai_ci do; _AS/_as_cs keep accents significant. Pick the combination deliberately per column.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.