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.

Kindoperator
Example LanguageSQL

📝 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

stringThe text to match; if NULL the result is NULL.
patternThe pattern text: % matches any character sequence, _ matches a single character.
escape_characterOptional 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

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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏