// conditional reference

SQL ILIKE operator

name ILIKE 'smith%' matches Smith, SMITH and smith. Only PostgreSQL has the operator; the other engines decide case sensitivity through collation or need UPPER.

Categoria
Condicional
Returns
boolean
In this category
39 of 43

Sintaxe

expression ILIKE pattern [ESCAPE char]

Suporte a mecanismos

MotorSupportNotas
SQL Server Different name or syntax LIKE follows the collation; default _CI_ collations already ignore case
PostgreSQL Sim Supported under this name.
MySQL Different name or syntax LIKE under a _ci collation, the utf8mb4 default
SQLite Different name or syntax LIKE ignores case for ASCII letters only
Oracle Different name or syntax UPPER(col) LIKE UPPER(pattern), or REGEXP_LIKE(col, pattern, 'i')

Exemplos

PostgreSQL

SELECT 'Apple' ILIKE 'apple' AS is_ilike, 'Apple' LIKE 'apple' AS is_like;  -- t, f

SQL Server

SELECT CASE WHEN 'Apple' LIKE 'apple' THEN 1 ELSE 0 END AS default_ci,
       CASE WHEN 'Apple' LIKE 'apple' COLLATE Latin1_General_CS_AS THEN 1 ELSE 0 END AS cs;  -- 1, 0 under a CI default

SQLite

SELECT 'Apple' LIKE 'apple' AS ascii, 'Ä' LIKE 'ä' AS non_ascii;  -- 1, 0

Oracle

SELECT CASE WHEN REGEXP_LIKE('Apple', '^app', 'i') THEN 'match' END AS m FROM dual;  -- match

Bom saber

  • A plain B-tree index does not help ILIKE. Use a trigram index (pg_trgm with gin_trgm_ops) or an expression index on lower(col) queried as lower(col) LIKE 'abc%'.
  • SQLite's LIKE folds ASCII only: 'Ä' LIKE 'ä' is 0.
  • ILIKE is the ~~* operator, and NOT ILIKE is !~~*. EXPLAIN output shows these forms.
  • On MySQL, LIKE BINARY or a _bin or _cs collation makes LIKE case-sensitive again.

Questions about ILIKE

Is ILIKE slower than LIKE?

Without an index, both scan and the cost is similar. With an index the difference is large: a prefix LIKE can use a suitable B-tree index, ILIKE needs a trigram or lower() expression index.

Does MySQL have ILIKE?

No. MySQL's default collations are case-insensitive, so LIKE already matches regardless of case.

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.