百科 / 错误代码 / Class 22 数据异常
2201B invalid_regular_expression
ERROR 源码确认 参考 未实测
- 条件名
invalid_regular_expression- 宏名称
ERRCODE_INVALID_REGULAR_EXPRESSION- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
SQL 正则编译和执行有不同的 2201B 路径,HBA/ident 配置处理则复用本码并按日志级别报告。必须按归属分别读取固定报文和严重级别,不能合并成一个笼统的正则失败。
含义
在 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 路径。
诊断
结合完整 primary、严重级别和上下文确认归属。对 SQL 正则函数,检查模式和 flags,区分编译错误与执行错误。对 HBA 或 ident 配置,检查报文指出的文件、行号、token 的前导斜杠标记及其后交给编译器的正则文本,以及重载/启动上下文;重载时记录的配置失败可能保留旧的 HBA 配置。不要把正常的 REG_NOMATCH 当作语法无效。
处理
按所属语法修正模式或 flags,并在同一子系统中验证。SQL 正则 ERROR 会中止当前语句,因此显式事务需先 ROLLBACK 或回到已有保存点再重试,自动提交只重试修正后的语句。配置 LOG/debug 报文需要修正 HBA 或 ident 文件并按该子系统重载或重启,不是回滚事务。
报文
- 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"。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
invalid regular expression: %s
regular expression failed: %s
来源:src/backend/utils/adt/regexp.c @ REL_18_6 · src/backend/utils/adt/regexp.c @ REL_18_6
适用范围:Execution errors other than REG_NOMATCH.
invalid regular expression "%s": %s
line %d of configuration file "%s"
来源:src/backend/libpq/hba.c @ REL_18_6 · src/backend/libpq/hba.c @ REL_18_6
regular expression match for "%s" failed: %s
regular expression "%s" has no subexpressions as requested by backreference in "%s"
版本
锁定目录从 7.4 起记录该条件;固定源码覆盖 PostgreSQL 18.6。引用的 SQL 正则和 HBA/ident 路径属于不同归属;扩展或其他子系统的报文不在本次有限审阅范围内。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 190 行
- 上游源码 src/backend/libpq/hba.c
- 上游源码 src/backend/libpq/hba.c
- 上游源码 src/backend/libpq/hba.c
- 上游源码 src/backend/libpq/hba.c
- 上游源码 src/backend/utils/adt/regexp.c
- 上游源码 src/backend/utils/adt/regexp.c
- 上游源码 src/backend/utils/adt/regexp.c
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
2201B is invalid_regular_expression in SQLSTATE Class 22.
-
SQL regex compilation reports invalid regular expression: %s; execution errors other than REG_NOMATCH report regular expression failed: %s.
-
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.
-
The locked catalogue records 2201B from 7.4 without proving an exact implementation introduction date.
同类错误代码
Class 22 数据异常 下的其他成员。
22000data_exception22001string_data_right_truncation22002null_value_no_indicator_parameter22003numeric_value_out_of_range22004null_value_not_allowed22005error_in_assignment22007invalid_datetime_format22008datetime_field_overflow22009invalid_time_zone_displacement_value2200Bescape_character_conflict2200Cinvalid_use_of_escape_character2200Dinvalid_escape_octet2200Fzero_length_character_string2200Gmost_specific_type_mismatch2200Hsequence_generator_limit_exceeded2200Lnot_an_xml_document2200Minvalid_xml_document2200Ninvalid_xml_content2200Sinvalid_xml_comment2200Tinvalid_xml_processing_instruction22010invalid_indicator_parameter_value22011substring_error22012division_by_zero22013invalid_preceding_or_following_size22014invalid_argument_for_ntile_function22015interval_field_overflow22016invalid_argument_for_nth_value_function22018invalid_character_value_for_cast22019invalid_escape_character2201Einvalid_argument_for_logarithm2201Finvalid_argument_for_power_function2201Ginvalid_argument_for_width_bucket_function2201Winvalid_row_count_in_limit_clause2201Xinvalid_row_count_in_result_offset_clause22021character_not_in_repertoire22022indicator_overflow22023invalid_parameter_value22024unterminated_c_string22025invalid_escape_sequence22026string_data_length_mismatch22027trim_error2202Earray_subscript_error2202Ginvalid_tablesample_repeat2202Hinvalid_tablesample_argument22030duplicate_json_object_key_value22031invalid_argument_for_sql_json_datetime_function22032invalid_json_text22033invalid_sql_json_subscript22034more_than_one_sql_json_item22035no_sql_json_item22036non_numeric_sql_json_item22037non_unique_keys_in_a_json_object22038singleton_sql_json_item_required22039sql_json_array_not_found2203Asql_json_member_not_found2203Bsql_json_number_not_found2203Csql_json_object_not_found2203Dtoo_many_json_array_elements2203Etoo_many_json_object_members2203Fsql_json_scalar_required2203Gsql_json_item_cannot_be_cast_to_target_type22P01floating_point_exception22P02invalid_text_representation22P03invalid_binary_representation22P04bad_copy_file_format22P05untranslatable_character22P06nonstandard_use_of_escape_character