22019
PostgreSQLERRORNotableData ExceptionHIGH confidence
invalid escape character
What this means
SQLSTATE 22019 is raised when an ESCAPE clause in a LIKE or SIMILAR TO expression specifies a multi-character string or an empty string, which is not a valid escape character specification.
Why it happens
- 1LIKE ESCAPE specifying a string with more than one character
- 2LIKE ESCAPE specifying an empty string
How to reproduce
LIKE with a multi-character escape string.
trigger — this will error
trigger — this will error
SELECT * FROM items WHERE name LIKE '50!%' ESCAPE '!!'; -- two chars
expected output
ERROR: invalid escape string HINT: Escape string must be empty or one character.
Fix
Use exactly one character as the escape character
WHEN When using LIKE ESCAPE.
Use exactly one character as the escape character
SELECT * FROM items WHERE name LIKE '50!%' ESCAPE '!';
Why this works
The ESCAPE clause requires exactly one character. Choose a character that does not appear in normal data.
Sources
Official documentation ↗
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev