2201B — invalid_regular_expression
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.
English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.
Reading PG 18·Select a recorded version
- aliases
- Unknown
- class name
- Data Exception
- condition name
- invalid_regular_expression
- lang
- en
- sqlstate
- 2201B
Definition PG 18
At a glance {#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 {#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 {#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 {#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 {#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_hbapath usesLOG):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 {#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.
Related {#related}
Sources {#sources}
src/backend/utils/adt/regexp.c#L204-L224contains the SQL regex compileERROR;#L285-L305and#L2050-L2070contain execution-error variants.src/backend/libpq/hba.c#L298-L340contains HBA regex compilation with caller-selectedelevel;#L2635-L2683showsload_hbapassingLOG;#L2835-L2864and#L2880-L2887contain the separate ident-mapLOGmessages.
Runtime verification is not_run; no regex runtime observation is claimed. The structured evidence record retains owner-specific messages, severities, and source limits.
Compare versions
SQLSTATE evidence and recorded runtime versions
claims · identity
{
"claim_id": "identity",
"limits": "",
"method": "Read the fixed errcodes row and macro.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "2201B is invalid_regular_expression in SQLSTATE Class 22."
}claims · sql-regex-path
{
"claim_id": "sql-regex-path",
"limits": "REG_NOMATCH is a normal no-match result.",
"method": "Read the compile and execution branches.",
"position": 1,
"runtime": [],
"sources": [
"src.regexp-compile.18.6",
"src.regexp-execute.18.6",
"src.regexp-match.18.6"
],
"statement": "SQL regex compilation reports invalid regular expression: %s; execution errors other than REG_NOMATCH report regular expression failed: %s."
}claims · hba-config-path
{
"claim_id": "hba-config-path",
"limits": "Configuration diagnostics are distinct from SQL expression ERROR paths.",
"method": "Read the HBA compiler, load_hba caller, and ident-map branches.",
"position": 2,
"runtime": [],
"sources": [
"src.hba-compile.18.6",
"src.hba-load.18.6",
"src.hba-ident-match.18.6",
"src.hba-ident-backref.18.6"
],
"statement": "HBA regex compilation checks only the token leading slash and passes token-\u003estring + 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."
}claims · history
{
"claim_id": "history",
"limits": "",
"method": "Use catalogue presence and history boundaries.",
"position": 3,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "The locked catalogue records 2201B from 7.4 without proving an exact implementation introduction date."
}messages · message.sql-compile
{
"limits": "",
"message_id": "message.sql-compile",
"path": "",
"position": 0,
"raw": {
"id": "message.sql-compile",
"primary_template": "invalid regular expression: %s",
"severity_source": "ERROR",
"sources": [
"src.regexp-compile.18.6"
],
"sqlstate": "2201B"
},
"severity": "ERROR",
"sources": [
"src.regexp-compile.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "invalid regular expression:",
"position": 0,
"role": "",
"template": "invalid regular expression: %s"
}
]
}messages · message.sql-execute
{
"limits": "Execution errors other than REG_NOMATCH.",
"message_id": "message.sql-execute",
"path": "",
"position": 1,
"raw": {
"id": "message.sql-execute",
"limits": "Execution errors other than REG_NOMATCH.",
"primary_template": "regular expression failed: %s",
"severity_source": "ERROR",
"sources": [
"src.regexp-execute.18.6",
"src.regexp-match.18.6"
],
"sqlstate": "2201B"
},
"severity": "ERROR",
"sources": [
"src.regexp-execute.18.6",
"src.regexp-match.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "regular expression failed:",
"position": 0,
"role": "",
"template": "regular expression failed: %s"
}
]
}messages · message.hba-compile
{
"limits": "",
"message_id": "message.hba-compile",
"path": "",
"position": 2,
"raw": {
"context_template": "line %d of configuration file \"%s\"",
"id": "message.hba-compile",
"primary_template": "invalid regular expression \"%s\": %s",
"severity_source": "caller-selected (normal load_hba path passes LOG)",
"sources": [
"src.hba-compile.18.6",
"src.hba-load.18.6"
],
"sqlstate": "2201B"
},
"severity": "caller-selected (normal load_hba path passes LOG)",
"sources": [
"src.hba-compile.18.6",
"src.hba-load.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "invalid regular expression \" \":",
"position": 0,
"role": "",
"template": "invalid regular expression \"%s\": %s"
},
{
"kind": "context",
"literal": "line of configuration file \" \"",
"position": 1,
"role": "",
"template": "line %d of configuration file \"%s\""
}
]
}messages · message.hba-ident-match
{
"limits": "",
"message_id": "message.hba-ident-match",
"path": "",
"position": 3,
"raw": {
"id": "message.hba-ident-match",
"primary_template": "regular expression match for \"%s\" failed: %s",
"severity_source": "LOG",
"sources": [
"src.hba-ident-match.18.6"
],
"sqlstate": "2201B"
},
"severity": "LOG",
"sources": [
"src.hba-ident-match.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "regular expression match for \" \" failed:",
"position": 0,
"role": "",
"template": "regular expression match for \"%s\" failed: %s"
}
]
}messages · message.hba-ident-backref
{
"limits": "",
"message_id": "message.hba-ident-backref",
"path": "",
"position": 4,
"raw": {
"id": "message.hba-ident-backref",
"primary_template": "regular expression \"%s\" has no subexpressions as requested by backreference in \"%s\"",
"severity_source": "LOG",
"sources": [
"src.hba-ident-backref.18.6"
],
"sqlstate": "2201B"
},
"severity": "LOG",
"sources": [
"src.hba-ident-backref.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "regular expression \" \" has no subexpressions as requested by backreference in \" \"",
"position": 0,
"role": "",
"template": "regular expression \"%s\" has no subexpressions as requested by backreference in \"%s\""
}
]
}sources · src.errcodes.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/errcodes.txt",
"position": 0,
"sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
"source_id": "src.errcodes.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L190"
}sources · src.regexp-compile.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/regexp.c",
"position": 1,
"sha256": "8c54fe9e937ce03111b39da7bca89b22d6cb2de6b9ce5f7caf90c76bc7218e0e",
"source_id": "src.regexp-compile.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/regexp.c#L204-224"
}sources · src.regexp-execute.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/regexp.c",
"position": 2,
"sha256": "8c54fe9e937ce03111b39da7bca89b22d6cb2de6b9ce5f7caf90c76bc7218e0e",
"source_id": "src.regexp-execute.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/regexp.c#L285-305"
}sources · src.regexp-match.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/regexp.c",
"position": 3,
"sha256": "8c54fe9e937ce03111b39da7bca89b22d6cb2de6b9ce5f7caf90c76bc7218e0e",
"source_id": "src.regexp-match.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/regexp.c#L2050-2070"
}sources · src.hba-compile.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/libpq/hba.c",
"position": 4,
"sha256": "b31049f83ce504979493155e9f496ab26b5f642969acc1d5280c32a86e7d1db3",
"source_id": "src.hba-compile.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/libpq/hba.c#L298-340"
}sources · src.hba-load.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/libpq/hba.c",
"position": 5,
"sha256": "b31049f83ce504979493155e9f496ab26b5f642969acc1d5280c32a86e7d1db3",
"source_id": "src.hba-load.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/libpq/hba.c#L2635-2683"
}sources · src.hba-ident-match.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/libpq/hba.c",
"position": 6,
"sha256": "b31049f83ce504979493155e9f496ab26b5f642969acc1d5280c32a86e7d1db3",
"source_id": "src.hba-ident-match.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/libpq/hba.c#L2835-2864"
}sources · src.hba-ident-backref.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/libpq/hba.c",
"position": 7,
"sha256": "b31049f83ce504979493155e9f496ab26b5f642969acc1d5280c32a86e7d1db3",
"source_id": "src.hba-ident-backref.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/libpq/hba.c#L2880-2887"
}Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · english-manuals:4488f4511bd88a97a2c80792c0a9d4833dd4c4af7935aa9a9b6fa4ae691452dd
Text language: en · english-manuals:4488f4511bd88a97a2c80792c0a9d4833dd4c4af7935aa9a9b6fa4ae691452dd