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

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

Wiki / SQLSTATE

22004 — null_value_not_allowed

参数或值不允许为 NULL。

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

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

aliases
未知
class name
Data Exception
condition name
null_value_not_allowed
lang
en
sqlstate
22004

版本定义 PG 18

22004

速览 {#at-a-glance}

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。

报文 {#messages}

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 报文。

含义 {#meaning}

22004 是 NULL 契约失败。固定 nodeTableFuncscan.c 路径拒绝 table function 使用的 namespace URI,消息为 namespace URI must not be null。同名条件也可能由其他函数选择,因此 NULL 函数参数、STRICT 函数返回的 NULL 和声明了 NOT NULL 的表列属于不同调查。普通 SQL NULL 结果本身不是 22004 的证据,应以实际 SQLSTATE 和诊断字段为准。

诊断 {#diagnosis}

用完整 message、routine、context 和对象字段确认哪个参数或 descriptor 为 NULL。已确认的 table-function 路径要检查 namespace URI 表达式,以及提供它的 XML/行描述。普通 NULL 输入或 STRICT 函数返回 NULL 本身并不表示该条件。如果响应指向列约束,应使用实际 SQLSTATE 和 constraint 字段;不要把列 NOT NULL 错误重新标成 22004。

处置 {#response}

修正消息所指的函数参数或 descriptor,或修改 table-function 定义以满足 namespace URI 契约。API 允许时应保留有意的 SQL NULL;把所有 NULL 换成空字符串可能改变 XML 或查询语义。本次固定案例使用自动提交,失败语句结束后会话仍为 IDLE;显式事务中应先回滚整个事务,或回滚到失败语句前已有的保存点,再继续执行。确认调用已修正后再重复写入。

版本 {#versions}

锁定目录从 7.4 记录该条件,并在列出的正式快照及 19beta3 中出现;固定源码覆盖为 PostgreSQL 18.6。

相关条件 {#related}

22000 是其他 Data Exception 路径,22002 是 ECPG 指示变量条件;若实际响应是 NOT NULL 约束错误,应按 23502 调查。

来源 {#sources}

已确认的 table-function 检查见 nodeTableFuncscan.c#L368-L370;相邻的 filter/output guard 见 nodeTableFuncscan.c#L380-L419 和 nodeTableFuncscan.c#L494-L508。结构化证据记录固定了这些路径,并把其他 NULL 契约保持为条件性说明。

比较版本

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

cases · xmltable_null_namespace
{
  "assertions": [
    "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"
  ],
  "case_id": "xmltable_null_namespace",
  "cleanup": "Drop the case schema with an owner connection.",
  "has_snippet": true,
  "position": 0,
  "preconditions": [],
  "repair": "Supply the namespace URI required by the XML document and keep this XMLTABLE path distinct from a table-column NOT NULL violation.",
  "trigger": "Evaluate XMLTABLE with a NULL namespace URI.",
  "versions": [
    "10",
    "18"
  ]
}
claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read fixed definition.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "22004 is null_value_not_allowed in SQLSTATE Class 22."
}
claims · mechanism.xmltable-namespace
{
  "claim_id": "mechanism.xmltable-namespace",
  "limits": "Other functions may use 22004 for different NULL contracts.",
  "method": "Read the complete namespace evaluation and NULL guard.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.path.xmltable"
  ],
  "statement": "The XMLTABLE table-function executor rejects a NULL namespace URI and reports 22004 before producing rows."
}
claims · mechanism.xmltable-null-guards
{
  "claim_id": "mechanism.xmltable-null-guards",
  "limits": "The selected runtime covers only the namespace URI guard.",
  "method": "Read the complete tfuncInitialize guard sequence.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.path.xmltable-filters",
    "src.path.xmltable-output"
  ],
  "statement": "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."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use catalogue boundary.",
  "position": 3,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 22004 from 7.4 without proving an exact implementation introduction date."
}
claims · runtime.observation
{
  "claim_id": "runtime.observation",
  "limits": "The observation covers XMLTABLE namespace evaluation only.",
  "method": "Execute the shared registry and inspect selected summaries.",
  "position": 4,
  "runtime": [
    "runtime.22004-data1-latest.latest",
    "runtime.22004-data1-pg10.pg10"
  ],
  "sources": [
    "manifest.22004",
    "snippet-registry.22004"
  ],
  "statement": "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."
}
messages · message.xmltable
{
  "limits": "",
  "message_id": "message.xmltable",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.xmltable",
    "primary_template": "namespace URI must not be null",
    "severity_source": "ERROR",
    "sources": [
      "src.path.xmltable"
    ],
    "sqlstate": "22004"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.xmltable"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "namespace URI must not be null",
      "position": 0,
      "role": "",
      "template": "namespace URI must not be null"
    }
  ]
}
messages · message.xmltable-row-filter
{
  "limits": "",
  "message_id": "message.xmltable-row-filter",
  "path": "",
  "position": 1,
  "raw": {
    "id": "message.xmltable-row-filter",
    "primary_template": "row filter expression must not be null",
    "severity_source": "ERROR",
    "sources": [
      "src.path.xmltable-filters"
    ],
    "sqlstate": "22004"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.xmltable-filters"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "row filter expression must not be null",
      "position": 0,
      "role": "",
      "template": "row filter expression must not be null"
    }
  ]
}
messages · message.xmltable-column-filter
{
  "limits": "",
  "message_id": "message.xmltable-column-filter",
  "path": "",
  "position": 2,
  "raw": {
    "detail_template": "Filter for column \"%s\" is null.",
    "id": "message.xmltable-column-filter",
    "primary_template": "column filter expression must not be null",
    "severity_source": "ERROR",
    "sources": [
      "src.path.xmltable-filters"
    ],
    "sqlstate": "22004"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.xmltable-filters"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "column filter expression must not be null",
      "position": 0,
      "role": "",
      "template": "column filter expression must not be null"
    },
    {
      "kind": "detail",
      "literal": "Filter for column \" \" is null.",
      "position": 1,
      "role": "",
      "template": "Filter for column \"%s\" is null."
    }
  ]
}
messages · message.xmltable-column-output
{
  "limits": "",
  "message_id": "message.xmltable-column-output",
  "path": "",
  "position": 3,
  "raw": {
    "guard_context": "XMLTABLE output column is marked NOT NULL and remains NULL after the output value and any DEFAULT expression have been evaluated",
    "id": "message.xmltable-column-output",
    "primary_template": "null is not allowed in column \"%s\"",
    "severity_source": "ERROR",
    "sources": [
      "src.path.xmltable-output"
    ],
    "sqlstate": "22004"
  },
  "severity": "ERROR",
  "sources": [
    "src.path.xmltable-output"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "null is not allowed in column \" \"",
      "position": 0,
      "role": "",
      "template": "null is not allowed in column \"%s\""
    }
  ]
}
runtimes · runtime.22004-data1-latest.latest · 18.6 (Homebrew) · passed
{
  "cases": [
    "xmltable_null_namespace"
  ],
  "limits": "",
  "position": 0,
  "raw": {
    "cases": [
      "xmltable_null_namespace"
    ],
    "id": "runtime.22004-data1-latest.latest",
    "observed": {
      "sqlstate": "22004",
      "status_after_repair": "IDLE"
    },
    "raw": "verify/results/22004-data1-latest/latest/raw.jsonl",
    "raw_sha256": "245e7dc22a58a7411347c9d7ef3732ee19b16b83bd6935946330e15f883bf863",
    "run_id": "22004-data1-latest",
    "server_version": "18.6 (Homebrew)",
    "server_version_num": 180006,
    "snippet_registry": {
      "path": "verify/cases/22004/snippets.json",
      "sha256": "a71cda2337e992c422232fa9f7fabc158411970e959daba3c571f521e65ece0c"
    },
    "status": "passed",
    "summary": "verify/results/22004-data1-latest/latest/summary.json",
    "summary_sha256": "6d2a04c9fec0b2253747c2961000f74500aa992f83b58123a15bc0eaa3a02575",
    "target": "latest"
  },
  "run_id": "22004-data1-latest",
  "runtime_id": "runtime.22004-data1-latest.latest",
  "server_version": "18.6 (Homebrew)",
  "status": "passed",
  "target": "latest"
}
runtimes · runtime.22004-data1-pg10.pg10 · 10.21 (Debian 10.21-1.pgdg90+1) · passed
{
  "cases": [
    "xmltable_null_namespace"
  ],
  "limits": "",
  "position": 1,
  "raw": {
    "cases": [
      "xmltable_null_namespace"
    ],
    "id": "runtime.22004-data1-pg10.pg10",
    "observed": {
      "sqlstate": "22004",
      "status_after_repair": "IDLE"
    },
    "raw": "verify/results/22004-data1-pg10/pg10/raw.jsonl",
    "raw_sha256": "05609b74ec6458e635c31330ee36d4ce3a5e8695b078bb1dfd29caf290eac3da",
    "run_id": "22004-data1-pg10",
    "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
    "server_version_num": 100021,
    "snippet_registry": {
      "path": "verify/cases/22004/snippets.json",
      "sha256": "a71cda2337e992c422232fa9f7fabc158411970e959daba3c571f521e65ece0c"
    },
    "status": "passed",
    "summary": "verify/results/22004-data1-pg10/pg10/summary.json",
    "summary_sha256": "ec256223667ce3481fe0284a6455601713b9a863e4320a55e02e0728a5b6373c",
    "target": "pg10"
  },
  "run_id": "22004-data1-pg10",
  "runtime_id": "runtime.22004-data1-pg10.pg10",
  "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
  "status": "passed",
  "target": "pg10"
}
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#L195"
}
sources · src.calls.REL_18_6
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 1,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6",
  "tag": "",
  "url": ""
}
sources · src.path.xmltable
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/executor/nodeTableFuncscan.c",
  "position": 2,
  "sha256": "0a9faaa9e45bb460dd98e4688f088711d459333eb8bd94255779f2c0218df82b",
  "source_id": "src.path.xmltable",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeTableFuncscan.c#L346-L371"
}
sources · src.path.xmltable-filters
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/executor/nodeTableFuncscan.c",
  "position": 3,
  "sha256": "0a9faaa9e45bb460dd98e4688f088711d459333eb8bd94255779f2c0218df82b",
  "source_id": "src.path.xmltable-filters",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeTableFuncscan.c#L380-L419"
}
sources · src.path.xmltable-output
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/executor/nodeTableFuncscan.c",
  "position": 4,
  "sha256": "0a9faaa9e45bb460dd98e4688f088711d459333eb8bd94255779f2c0218df82b",
  "source_id": "src.path.xmltable-output",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeTableFuncscan.c#L494-L508"
}
sources · snippet-registry.22004
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "verify/cases/22004/snippets.json",
  "position": 5,
  "sha256": "a71cda2337e992c422232fa9f7fabc158411970e959daba3c571f521e65ece0c",
  "source_id": "snippet-registry.22004",
  "tag": "",
  "url": ""
}
sources · manifest.22004
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "verify/cases/22004/cases.json",
  "position": 6,
  "sha256": "b0dc8a3d3580f20a4d8abb23ce148c4919b6e085aa06f772d6feb1c0e282107d",
  "source_id": "manifest.22004",
  "tag": "workspace",
  "url": "verify/cases/22004/cases.json"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:7217004fde97f287aa753af91e961d30d12352d258f3ac102dcfe7ae4fc443bf

正文语言: zh-Hans · english-manuals:7217004fde97f287aa753af91e961d30d12352d258f3ac102dcfe7ae4fc443bf