2200C — invalid_use_of_escape_character
2200C
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.
| Field | Value |
|---|---|
| SQLSTATE | 2200C |
| Condition | invalid_use_of_escape_character |
| 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_USE_OF_ESCAPE_CHARACTER |
| Aliases | — |
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.
Related
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.