select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 22 · DATA EXCEPTION

invalid_escape_sequence

SQLSTATE
22025
Condition name
invalid_escape_sequence
Class
Data Exception
Source macro
ERRCODE_INVALID_ESCAPE_SEQUENCE
Evidence
Source path confirmed
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>22025</h1>

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.

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.

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.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

22025 is invalid_escape_sequence in SQLSTATE Class 22

Method: Read the fixed errcodes row and macro.

src.errcodes.18.6

Fixed PostgreSQL 18.6 LIKE, SQL regular-expression translation, and core scanner paths bind distinct escape-length, trailing-pattern, and malformed-Unicode guards.

Method: Read complete source contexts for the representative guards.

Limits: Source confirmation is not a natural runtime observation.

src.like.pattern src.like.escape src.regexp.escape src.scan.unicode

The locked catalogue records 22025 from 7.4 without proving an exact implementation introduction date.

Method: Use catalogue presence and history boundaries.

src.errcodes.18.6

SIMILAR separator overflow and regexp_replace parameter validation use different SQLSTATE paths (2200C/22023) and are not folded into 22025.

Method: Read the adjacent consumers and their explicit errcodes.

src.regexp.escape src.like.escape

Message templates

ERROR · message.invalid-escape-like

Primary

invalid escape string

Hint

Escape string must be empty or one character.
ERROR · message.like-trailing

Primary

LIKE pattern must not end with escape character
ERROR · message.invalid-escape-regexp

Primary

invalid escape string

Hint

Escape string must be empty or one character.
ERROR · message.invalid-unicode

Primary

invalid Unicode escape

Hint

Unicode escapes must be \uXXXX or \UXXXXXXXX.

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Definition snapshot: english-manuals:39558e236143d6c98f68c656f48… · English manual source