LIKE and ESCAPE
Core idea
LIKE matches a whole string against a pattern: % matches zero or more characters, and _ matches one character. ESCAPE lets you search for literal wildcard characters.
Minimal example
SELECT name FROM products WHERE name LIKE 'P%' ORDER BY id;Expected SQLite rows:
PenPencilHow it works
In the second example, ! is the chosen escape character, so !% means a literal percent sign. Case sensitivity depends on engine and collation: SQLite LIKE normally ignores ASCII case, unlike ordinary PostgreSQL LIKE with a deterministic case-sensitive collation. These examples do not rely on that difference.
Practical example
SELECT '50% off' LIKE '50!%%' ESCAPE '!';Expected SQLite rows:
1SQLite represents true as 1; PostgreSQL returns a Boolean true.
Common mistake and practice
LIKE is not a regular expression. Try matching names beginning with P and verify that Pen and Pencil appear. For application input use bound parameters and escape wildcard characters when literal matching is intended.