百科 / 错误代码 / Class 22 数据异常
22004 null_value_not_allowed
ERROR 已实测 详解 实测通过
- 条件名
null_value_not_allowed- 宏名称
ERRCODE_NULL_VALUE_NOT_ALLOWED- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
22004 是 null_value_not_allowed。固定 table-function 路径报告 namespace URI must not be null;其他扩展和核心函数可能有不同的 NULL 契约。
共享案例向 XMLTABLE 提供 NULL namespace URI,然后使用 URI u 和匹配的 XML 行重做表函数调用。应分开发送两条 SELECT;第一条预期失败,之后再执行修复调用。会话和清理由运行器负责。
SELECT * FROM XMLTABLE(XMLNAMESPACES (NULL AS p), '/p:row' PASSING '<p:row xmlns:p="u"/>' COLUMNS x text PATH 'p:x');
SELECT count(*) FROM XMLTABLE(XMLNAMESPACES ('u' AS p), '/p:row' PASSING '<p:row xmlns:p="u"><p:x>ok</p:x></p:row>' COLUMNS x text PATH 'p:x');
校准实测了表函数 namespace URI 路径:NULL namespace 报告 namespace URI must not be null;有效 URI 返回一行 XMLTABLE 结果,运行器的两条自动提交会话均回到 IDLE。
报文
namespace guard 以 ERROR 严重性报告 primary:namespace URI must not be null,没有独立 DETAIL 或 HINT。table-function executor 模块还分别检查 NULL row-filter 表达式和 NULL column-filter 表达式(DETAIL 会包含列名)。输出列 guard 的范围更窄:XMLTABLE 输出列标记为 NOT NULL 后,先取得值并应用 DEFAULT;只有仍为 NULL 时才报告 null is not allowed in column "%s"。这个条件不同于普通 NULL 结果或单独的 23502 约束错误;本次运行只观察了 namespace 报文。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
namespace URI must not be null
row filter expression must not be null
column filter expression must not be null
Filter for column "%s" is null.
null is not allowed in column "%s"
含义
22004 是 NULL 契约失败。固定 nodeTableFuncscan.c 路径拒绝 table function 使用的 namespace URI,消息为 namespace URI must not be null。同名条件也可能由其他函数选择,因此 NULL 函数参数、STRICT 函数返回的 NULL 和声明了 NOT NULL 的表列属于不同调查。普通 SQL NULL 结果本身不是 22004 的证据,应以实际 SQLSTATE 和诊断字段为准。
诊断
用完整 message、routine、context 和对象字段确认哪个参数或 descriptor 为 NULL。已确认的 table-function 路径要检查 namespace URI 表达式,以及提供它的 XML/行描述。普通 NULL 输入或 STRICT 函数返回 NULL 本身并不表示该条件。如果响应指向列约束,应使用实际 SQLSTATE 和 constraint 字段;不要把列 NOT NULL 错误重新标成 22004。
处置
修正消息所指的函数参数或 descriptor,或修改 table-function 定义以满足 namespace URI 契约。API 允许时应保留有意的 SQL NULL;把所有 NULL 换成空字符串可能改变 XML 或查询语义。本次固定案例使用自动提交,失败语句结束后会话仍为 IDLE;显式事务中应先回滚整个事务,或回滚到失败语句前已有的保存点,再继续执行。确认调用已修正后再重复写入。
可复现案例
在一次性实例上执行过的场景。其中 1 个附有可执行 SQL,正文相应小节里给出。
xmltable_null_namespace PG 10 / 18 有 SQL
触发
Evaluate XMLTABLE with a NULL namespace URI.
断言
- SQLSTATE is 22004
- The diagnostic identifies the XMLTABLE namespace URI
- The failed autocommit session remains IDLE
- A non-NULL namespace URI returns one row afterward
处置
Supply the namespace URI required by the XML document and keep this XMLTABLE path distinct from a table-column NOT NULL violation.
清理
Drop the case schema with an owner connection.
版本
锁定目录从 7.4 记录该条件,并在列出的正式快照及 19beta3 中出现;固定源码覆盖为 PostgreSQL 18.6。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 195 行
- 上游源码 src/backend/executor/nodeTableFuncscan.c 第 346–371 行
- 上游源码 src/backend/executor/nodeTableFuncscan.c 第 380–419 行
- 上游源码 src/backend/executor/nodeTableFuncscan.c 第 494–508 行
- 核验材料 verify/cases/22004/snippets.json
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
22004 is null_value_not_allowed in SQLSTATE Class 22.
-
The XMLTABLE table-function executor rejects a NULL namespace URI and reports 22004 before producing rows.
-
The table-function executor module has separate 22004 guards for null row-filter expressions, null column-filter expressions, and output columns marked NOT NULL whose value remains NULL after any DEFAULT expression is applied, each with a distinct primary message.
-
The locked catalogue records 22004 from 7.4 without proving an exact implementation introduction date.
-
The xmltable_null_namespace case passed on isolated PostgreSQL 18.6 and 10.21: a NULL URI raised 22004 and the valid URI repair returned one row with the session IDLE.
运行记录
| 目标 | 服务器版本 | 结果 | 覆盖案例 |
|---|---|---|---|
| latest | 18.6 (Homebrew) | passed | xmltable_null_namespace |
| pg10 | 10.21 (Debian 10.21-1.pgdg90+1) | passed | xmltable_null_namespace |
同类错误代码
Class 22 数据异常 下的其他成员。
22000data_exception22001string_data_right_truncation22002null_value_no_indicator_parameter22003numeric_value_out_of_range22005error_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_character2201Binvalid_regular_expression2201Einvalid_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