22025 — invalid_escape_sequence
22025
At a glance
An escape sequence is invalid for its specific consumer. Fixed paths distinguish a LIKE escape argument that is not empty or one character, a LIKE pattern ending in an escape character, a regular-expression translation escape argument with the same length rule, and malformed \u/\U Unicode escapes.
| Field | Value |
|---|---|
| SQLSTATE | 22025 |
| Condition | invalid_escape_sequence |
| Status | active |
| Known present by | 7.4 |
| Locked snapshots | 9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3 |
| Macros | ERRCODE_INVALID_ESCAPE_SEQUENCE |
| Aliases | — |
Representative messages
The representative consumers use these primary texts and hint:
| Consumer / guard | Primary and hint |
|---|---|
| LIKE or SQL regular-expression translation escape length | invalid escape string; HINT: Escape string must be empty or one character. |
| LIKE pattern with a trailing escape | LIKE pattern must not end with escape character |
| malformed scanner Unicode escape | invalid Unicode escape; HINT: Unicode escapes must be \uXXXX or \UXXXXXXXX. |
Meaning
22025 is emitted by consumer-specific escape guards. LIKE requires its ESCAPE string to be empty or one character and rejects a pattern ending with the escape character. The SQL regular-expression translation helper applies the same empty-or-one-character rule to its escape argument. The core scanner reports malformed Unicode escape syntax with the \uXXXX/\UXXXXXXXX hint. These are distinct from 22019’s escape-character semantics and 2200C’s SIMILAR separator overflow; a regexp_replace option or start/occurrence parameter is a 22023 parameter-validation path instead.
Diagnosis
Identify the consumer before editing backslashes: LIKE escape argument, LIKE pattern, SQL regular-expression translation, or an extended string literal’s Unicode scanner. Check whether the escape value is an empty string or one character, whether the LIKE pattern ends after an escape, and whether a Unicode escape has exactly the required \u/\U width. Do not call every regular-expression replacement or SIMILAR syntax error 22025; use the SQLSTATE and primary message actually reported.
Response
Provide the escape string and pattern required by the named consumer, preserving an intentional empty string as empty rather than SQL NULL. For malformed Unicode syntax, use \uXXXX or \UXXXXXXXX as required by the scanner. If an ERROR occurred in an explicit transaction, roll back or roll back to the existing savepoint before retrying; autocommit can retry the corrected statement.
Versions
The locked catalogue records this condition from 7.4; the fixed source paths here are PostgreSQL 18.6. No natural runtime observation is claimed for this page.
Related
Sources
LIKE guards are in src/backend/utils/adt/like_match.c#L159-165 and #L439-449; the SQL regular-expression translation escape-length guard is src/backend/utils/adt/regexp.c#L793-805; malformed Unicode escape syntax is in src/backend/parser/scan.l#L697-704. The structured evidence record retains the exact primaries, hint, and consumer boundaries; no natural runtime was run.