Pattern matching operator LIKE
Last updated: 2026-11-04
Pattern matching operator LIKE
LIKE matches text against an SQL pattern. % matches any sequence of characters including none, _ matches exactly one character, and the whole pattern is case sensitive (use ILIKE for case-insensitive matching). To match a literal % or _ inside the pattern, declare an escape character with ESCAPE. If either operand is NULL the result is NULL.
| Kind | operator |
|---|---|
| Example Language | SQL |
📝 Syntax
string LIKE pattern [ESCAPE escape_character]
Precedence: LIKE sits in the range/membership/pattern-matching tier, below all other operators (including `||`) but above the comparison operators `< > = <= >= <>`. So `'a' || 'b' LIKE 'ab'` concatenates first, then matches. LIKE is not `=`: a NULL operand yields NULL rather than false.
⚙️ Parameters
| string | The text to match; if NULL the result is NULL. |
|---|---|
| pattern | The pattern text: % matches any character sequence, _ matches a single character. |
| escape_character | Optional escape character declared with ESCAPE; the default is backslash. |
Returns:The boolean true, false, or NULL when either operand is NULL.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
SELECT id, title FROM t_like WHERE title LIKE '%SQL%' ORDER BY id
id | title
---+-----------
1 | PostgreSQL
2 | MySQL
(2 rows)
SELECT id, title FROM t_like WHERE title LIKE '____' ORDER BY id
id | title
---+------
4 | Post
(1 row)
SELECT id, title FROM t_like WHERE title LIKE '100!% Coverage' ESCAPE '!' ORDER BY id
id | title
---+--------------
3 | 100% Coverage
(1 row)
SELECT id, title FROM t_like WHERE title LIKE 'a!_b' ESCAPE '!' ORDER BY id
id | title
---+------
5 | a_b
(1 row)
SELECT id, title LIKE '%SQL%' IS NULL AS like_is_null FROM t_like WHERE id = 6
id | like_is_null
---+-------------
6 | true
(1 row)
📌 Key Points
- NULL propagation: a NULL operand makes LIKE return NULL and WHERE filters the row out.
- % matches any sequence of characters and _ matches exactly one; both can appear anywhere in the pattern.
- To match a literal % or _, declare an escape character, e.g. `LIKE '100!% Coverage' ESCAPE '!'`.
- LIKE is case sensitive; use ILIKE for case-insensitive matching.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QWhy does LIKE treat % as a wildcard?
A% and _ are reserved wildcards in SQL patterns. To match them literally, declare an escape character: `title LIKE '100!% Coverage' ESCAPE '!'` matches only the literal text 100% Coverage.