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_use_of_escape_character

SQLSTATE
2200C
Condition name
invalid_use_of_escape_character
Class
Data Exception
Source macro
ERRCODE_INVALID_USE_OF_ESCAPE_CHARACTER
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>2200C</h1>

At a glance

The SQL SIMILAR TO pattern translator rejected its escape-double-quote structure before matching. PostgreSQL 18.6 has a concrete regexp.c path that raises SQL regular expression may not contain more than two escape-double-quote separators; this is about the SQL-to-POSIX translation syntax, not generic POSIX backslash escaping.

Meaning

This condition belongs to the data-exception family for an escape form rejected while PostgreSQL translates a SQL SIMILAR TO pattern to its POSIX regular-expression form. In similar_escape_internal, an escaped double quote outside a bracket expression separates the three SQL SUBSTRING parts; the third separator is rejected. The same helper is used by the SQL SIMILAR TO translation path, where those separators do not change ordinary match behavior.

Messages

The confirmed guard raises ERROR with primary SQL regular expression may not contain more than two escape-double-quote separators; this branch has no separate DETAIL or HINT. An invalid ESCAPE string is a different SQLSTATE path, so preserve the actual message and code.

Diagnosis

This is a parser/input problem, so inspect the SQL string layer, the SIMILAR TO pattern, and its ESCAPE character separately. Count escaped double-quote separators outside bracket expressions and confirm whether the operation is SIMILAR TO or SUBSTRING ... SIMILAR; do not diagnose every backslash in a POSIX regexp as 2200C.

Response

Correct the SQL pattern or its ESCAPE representation according to the intended SIMILAR TO/SUBSTRING semantics, then re-run after checking the separator count. Do not add or remove POSIX backslashes indiscriminately.

When this branch raises ERROR, an explicit transaction must first be recovered with ROLLBACK or ROLLBACK TO SAVEPOINT for a savepoint established before the statement; in autocommit, retry only the corrected action after the failed statement completes. See the transaction and retry guide for this boundary rule.

Versions

The locked catalogue records this condition from 7.4; fixed source coverage is PostgreSQL 18.6.

Sources

Fixed source: src/backend/utils/adt/regexp.c#L758-951. The structured evidence record retains the definition, message, and scope boundaries. This is PostgreSQL’s SQL SIMILAR TO translation helper; no natural runtime was run for this page. A different escape failure may use another SQLSTATE, so choose by the actual code and message.

Source evidence

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

2200C is invalid_use_of_escape_character in SQLSTATE Class 22.

Method: Read fixed definition.

src.errcodes.18.6

The SQL SIMILAR TO translation helper similar_escape_internal treats an escaped double quote outside a bracket as a separator for the SQL SUBSTRING pattern parts; the third such separator raises 2200C. This is not a generic POSIX regular-expression backslash rule.

Method: Read the afterescape/nquotes guard and surrounding parser context.

Limits: The rule concerns this escape-double-quote syntax, not every backslash in a regex.

src.path.regexp-escape

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

Method: Use catalogue boundary.

src.errcodes.18.6

Message templates

ERROR · message.regexp

Primary

SQL regular expression may not contain more than two escape-double-quote separators

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:8e2b60f47c253b4c882e26a52af… · English manual source