↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

2201B — invalid_regular_expression

正则表达式无效,编译或执行阶段被拒绝。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Data Exception
condition name
invalid_regular_expression
lang
en
sqlstate
2201B

版本定义 PG 18

速览 {#at-a-glance}

SQL 正则编译和执行有不同的 2201B 路径,HBA/ident 配置处理则复用本码并按日志级别报告。必须按归属分别读取固定报文和严重级别,不能合并成一个笼统的正则失败。

含义 {#meaning}

在 regexp.c 中,无法编译的模式以 ERROR 报告 invalid regular expression: %s;已经编译的模式若执行返回正则引擎错误,则以 ERROR 报告 regular expression failed: %s。REG_NOMATCH 是正常的不匹配结果,不是本 SQLSTATE。在 hba.c 中,配置正则编译使用 invalid regular expression "%s": %s,严重级别由调用方提供(正常的 load_hba 路径传入 LOG);ident 映射的匹配或反向引用失败也有各自的日志 primary。这些配置报文不是 SQL 表达式的 ERROR 路径。

诊断 {#diagnosis}

结合完整 primary、严重级别和上下文确认归属。对 SQL 正则函数,检查模式和 flags,区分编译错误与执行错误。对 HBA 或 ident 配置,检查报文指出的文件、行号、token 的前导斜杠标记及其后交给编译器的正则文本,以及重载/启动上下文;重载时记录的配置失败可能保留旧的 HBA 配置。不要把正常的 REG_NOMATCH 当作语法无效。

处理 {#response}

按所属语法修正模式或 flags,并在同一子系统中验证。SQL 正则 ERROR 会中止当前语句,因此显式事务需先 ROLLBACK 或回到已有保存点再重试,自动提交只重试修正后的语句。配置 LOG/debug 报文需要修正 HBA 或 ident 文件并按该子系统重载或重启,不是回滚事务。

报文 {#messages}

  • SQL 正则编译,ERROR:invalid regular expression: %s。
  • SQL 正则执行错误,ERROR:regular expression failed: %s。
  • HBA 正则编译,调用方选择的级别(正常 load_hba 路径使用 LOG):invalid regular expression "%s": %s;源码还附加配置文件行上下文。
  • HBA ident 映射执行,LOG:regular expression match for "%s" failed: %s。
  • HBA ident 反向引用没有捕获子表达式,LOG:regular expression "%s" has no subexpressions as requested by backreference in "%s"。

版本 {#versions}

锁定目录从 7.4 起记录该条件;固定源码覆盖 PostgreSQL 18.6。引用的 SQL 正则和 HBA/ident 路径属于不同归属;扩展或其他子系统的报文不在本次有限审阅范围内。

相关 {#related}

2200C、2200D

来源 {#sources}

运行核验为 not_run;本页不宣称正则运行观察。结构化证据记录保留按归属区分的报文、严重级别和源码限制。

比较版本

SQLSTATE 证据与已记录的运行版本

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"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:4488f4511bd88a97a2c80792c0a9d4833dd4c4af7935aa9a9b6fa4ae691452dd

正文语言: zh-Hans · english-manuals:4488f4511bd88a97a2c80792c0a9d4833dd4c4af7935aa9a9b6fa4ae691452dd