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_regular_expression

SQLSTATE
2201B
Condition name
invalid_regular_expression
Class
Data Exception
Source macro
ERRCODE_INVALID_REGULAR_EXPRESSION
Evidence
Source path confirmed
Analysis & operational context

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

At a glance

SQL regular-expression compilation and execution have separate 2201B paths, and HBA/ident configuration handling uses the same code with log-level reporting. The fixed messages and severities must be read by owner rather than merged into one generic regex failure.

Meaning

In regexp.c, a pattern that cannot compile raises ERROR with invalid regular expression: %s; a compiled pattern whose execution returns a regex-engine error raises ERROR with regular expression failed: %s. REG_NOMATCH is an ordinary no-match result, not this SQLSTATE. In hba.c, configuration regex compilation uses invalid regular expression "%s": %s at the caller's level (the normal load_hba path passes LOG), and ident-map match/backreference failures are also logged with their own primary text. These configuration messages are not SQL expression ERROR paths.

Diagnosis

Use the complete primary, severity, and context to identify the owner. For SQL regex functions, inspect the pattern and flags and distinguish compile errors from execution errors. For HBA or ident configuration, inspect the named file and line, the token's leading-slash marker and the regex text after it, and the reload/startup context; a logged configuration failure can leave the previous HBA configuration in place on reload. Do not treat a normal REG_NOMATCH as invalid syntax.

Response

Repair the pattern or flags in the owning syntax and validate that same subsystem. A SQL regex ERROR aborts the current statement, so an explicit transaction must be rolled back or rolled back to an existing savepoint before retrying; autocommit can retry only the corrected statement. A configuration LOG/debug report requires fixing the HBA or ident file and reloading or restarting according to that subsystem, not transaction rollback.

Messages

  • SQL regex compile, ERROR: invalid regular expression: %s.
  • SQL regex execution error, ERROR: regular expression failed: %s.
  • HBA regex compilation, caller-selected level (the normal load_hba path uses LOG): invalid regular expression "%s": %s; the source also adds configuration-file line context.
  • HBA ident-map execution, LOG: regular expression match for "%s" failed: %s.
  • HBA ident backreference without a captured subexpression, LOG: regular expression "%s" has no subexpressions as requested by backreference in "%s".

Versions

The locked catalogue records this condition from 7.4; fixed source coverage is PostgreSQL 18.6. The cited SQL regex and HBA/ident paths are distinct owners; extension or other subsystem messages are outside this bounded review.

Sources

Runtime verification is not_run; no regex runtime observation is claimed. The structured evidence record retains owner-specific messages, severities, and source limits.

Source evidence

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

2201B is invalid_regular_expression in SQLSTATE Class 22.

Method: Read the fixed errcodes row and macro.

src.errcodes.18.6

SQL regex compilation reports invalid regular expression: %s; execution errors other than REG_NOMATCH report regular expression failed: %s.

Method: Read the compile and execution branches.

Limits: REG_NOMATCH is a normal no-match result.

src.regexp-compile.18.6 src.regexp-execute.18.6 src.regexp-match.18.6

HBA regex compilation checks only the token leading slash and passes token->string + 1 to the regex compiler; it uses a caller-selected level and load_hba passes LOG, while ident-map regex match and missing-backreference cases use separate LOG messages.

Method: Read the HBA compiler, load_hba caller, and ident-map branches.

Limits: Configuration diagnostics are distinct from SQL expression ERROR paths.

src.hba-compile.18.6 src.hba-load.18.6 src.hba-ident-match.18.6 src.hba-ident-backref.18.6

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

Method: Use catalogue presence and history boundaries.

src.errcodes.18.6

Message templates

ERROR · message.sql-compile

Primary

invalid regular expression: %s
ERROR · message.sql-execute

Primary

regular expression failed: %s

Execution errors other than REG_NOMATCH.

caller-selected (normal load_hba path passes LOG) · message.hba-compile

Primary

invalid regular expression "%s": %s

Context

line %d of configuration file "%s"
LOG · message.hba-ident-match

Primary

regular expression match for "%s" failed: %s
LOG · message.hba-ident-backref

Primary

regular expression "%s" has no subexpressions as requested by backreference in "%s"

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:886447e4a8691ef45ea5271cc0d… · English manual source