选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 错误代码 / Class 22 数据异常

22004 null_value_not_allowed

ERROR 已实测 详解 实测通过

类别
Class 22 数据异常
严重等级
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

来源:src/backend/executor/nodeTableFuncscan.c @ REL_18_6

主消息 row filter expression must not be null

来源:src/backend/executor/nodeTableFuncscan.c @ REL_18_6

主消息 column filter expression must not be null
DETAIL Filter for column "%s" is null.

来源:src/backend/executor/nodeTableFuncscan.c @ REL_18_6

主消息 null is not allowed in column "%s"

来源:src/backend/executor/nodeTableFuncscan.c @ REL_18_6

含义

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。

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

  • 22004 is null_value_not_allowed in SQLSTATE Class 22.

    核实方式Read fixed definition.

    来源src/backend/utils/errcodes.txt

  • The XMLTABLE table-function executor rejects a NULL namespace URI and reports 22004 before producing rows.

    核实方式Read the complete namespace evaluation and NULL guard.

    不覆盖Other functions may use 22004 for different NULL contracts.

    来源src/backend/executor/nodeTableFuncscan.c

  • 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.

    核实方式Read the complete tfuncInitialize guard sequence.

    不覆盖The selected runtime covers only the namespace URI guard.

    来源src/backend/executor/nodeTableFuncscan.c · src/backend/executor/nodeTableFuncscan.c

  • The locked catalogue records 22004 from 7.4 without proving an exact implementation introduction date.

    核实方式Use catalogue boundary.

    来源src/backend/utils/errcodes.txt

  • 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.

    核实方式Execute the shared registry and inspect selected summaries.

    不覆盖The observation covers XMLTABLE namespace evaluation only.

    来源verify/cases/22004/snippets.json

运行记录

目标服务器版本结果覆盖案例
latest 18.6 (Homebrew) passed xmltable_null_namespace
pg10 10.21 (Debian 10.21-1.pgdg90+1) passed xmltable_null_namespace

同类错误代码

Class 22 数据异常 下的其他成员。