22025
PostgreSQLERRORNotableData ExceptionHIGH confidence
invalid escape sequence
What this means
SQLSTATE 22025 is raised when a LIKE or SIMILAR TO pattern contains a backslash escape sequence at the end of the string (incomplete escape), or when the escape character is followed by something that does not form a valid escape.
Why it happens
- 1A LIKE pattern ends with the escape character, leaving it without a following character to escape
- 2An escape sequence in a SIMILAR TO pattern is incomplete
How to reproduce
LIKE pattern ending in an unfinished escape sequence.
trigger — this will error
trigger — this will error
SELECT * FROM files WHERE name LIKE 'report\'; -- escape at end
expected output
ERROR: invalid escape sequence
Fix
Ensure the escape character is followed by a valid character to escape
WHEN When building LIKE patterns programmatically.
Ensure the escape character is followed by a valid character to escape
SELECT * FROM files WHERE name LIKE 'report\\'; -- escaped backslash
Why this works
Double the escape character to match a literal backslash, or ensure the pattern always has a character after the escape.
Sources
Official documentation ↗
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev