select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 22 · DATA EXCEPTION

null_value_not_allowed

SQLSTATE
22004
Condition name
null_value_not_allowed
Class
Data Exception
Source macro
ERRCODE_NULL_VALUE_NOT_ALLOWED
Evidence
Observed at runtime in the source evidence
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>22004</h1>

At a glance

22004 is null_value_not_allowed. The fixed table-function path rejects a null namespace URI; many other extensions and core functions use the same condition for different null contracts.

The shared case supplies a NULL XMLTABLE namespace URI, then repeats the table-function call with URI u and a matching XML row. Send the two SELECT statements separately; the first is expected to fail before the repaired call runs. The runner controls the session and cleanup.

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');

Calibration observed the table-function namespace URI path: a NULL namespace reported namespace URI must not be null; a valid URI returned one XMLTABLE row, and both runner autocommit sessions returned to IDLE.

Messages

The namespace guard raises ERROR with primary namespace URI must not be null, with no separate DETAIL or HINT. The table-function executor module also has distinct ERROR guards for a null row-filter expression and a null column-filter expression (with a column-name DETAIL). Its output-column guard is narrower: after the XMLTABLE output column is marked NOT NULL, the value is obtained and any DEFAULT expression is applied; only when it is still NULL does it raise null is not allowed in column "%s". That output-column condition is distinct from an ordinary NULL result or a separate 23502 constraint error. The selected runtime observed only the namespace message.

Meaning

22004 is a NULL contract failure. In the fixed nodeTableFuncscan.c path, the rejected value is a namespace URI used by a table function: namespace URI must not be null. The same condition name can be selected by other functions, so a NULL function argument, a NULL result from a STRICT function, and a table column declared NOT NULL are different investigations. A normal SQL NULL result is not evidence of 22004; use the actual SQLSTATE and diagnostic fields.

Diagnosis

Use the full message, routine, context, and object fields to identify which parameter or descriptor was NULL. For the confirmed table-function path, inspect the namespace URI expression and the table-function XML/row description that supplied it. A plain NULL input or a STRICT function returning NULL does not by itself indicate this condition. If the response instead names a column constraint, use its actual SQLSTATE and constraint fields; do not relabel a column NOT NULL violation as 22004.

Response

Fix the function parameter or descriptor that the message identifies, or change the table-function definition so the namespace URI contract is satisfied. Preserve intentional SQL NULLs where the API permits them; replacing every NULL with an empty string can change XML or query semantics. The frozen case used autocommit, so the failed statement left the session IDLE; inside an explicit transaction, roll back the transaction or roll back to a pre-existing savepoint before continuing. Validate the corrected call before repeating a write.

Versions

The locked catalogue records this condition from 7.4 in the listed formal snapshots and 19beta3; fixed source coverage is PostgreSQL 18.6.

Sources

The confirmed table-function check is nodeTableFuncscan.c#L368-L370; the neighboring filter/output guards are in nodeTableFuncscan.c#L380-L419 and nodeTableFuncscan.c#L494-L508. The structured evidence record pins these paths and keeps other NULL contracts conditional.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

22004 is null_value_not_allowed in SQLSTATE Class 22.

Method: Read fixed definition.

src.errcodes.18.6

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

Method: Read the complete namespace evaluation and NULL guard.

Limits: Other functions may use 22004 for different NULL contracts.

src.path.xmltable

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.

Method: Read the complete tfuncInitialize guard sequence.

Limits: The selected runtime covers only the namespace URI guard.

src.path.xmltable-filters src.path.xmltable-output

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

Method: Use catalogue boundary.

src.errcodes.18.6

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.

Method: Execute the shared registry and inspect selected summaries.

Limits: The observation covers XMLTABLE namespace evaluation only.

manifest.22004 snippet-registry.22004

Message templates

ERROR · message.xmltable

Primary

namespace URI must not be null
ERROR · message.xmltable-row-filter

Primary

row filter expression must not be null
ERROR · message.xmltable-column-filter

Primary

column filter expression must not be null

Detail

Filter for column "%s" is null.
ERROR · message.xmltable-column-output

Primary

null is not allowed in column "%s"

Reproduction & repair cases

xmltable_null_namespace · PG 10, 18

Preconditions

    Trigger: Evaluate XMLTABLE with a NULL namespace URI.

    Expected 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

    Repair: Supply the namespace URI required by the XML document and keep this XMLTABLE path distinct from a table-column NOT NULL violation.

    Cleanup: Drop the case schema with an owner connection.

    Recorded runtime evidence

    18.6 (Homebrew) · passed

    Run: 22004-data1-latest

    {
      "sqlstate": "22004",
      "status_after_repair": "IDLE"
    }
    10.21 (Debian 10.21-1.pgdg90+1) · passed

    Run: 22004-data1-pg10

    {
      "sqlstate": "22004",
      "status_after_repair": "IDLE"
    }

    Definition snapshot: english-manuals:ee45c592a41d8b3dff5f73c1761… · English manual source