Skip to content

22038 — singleton_sql_json_item_required

Source-backed reference for PostgreSQL SQLSTATE 22038.

22038

At a glance

A SQL/JSON path operation expected one result of a required type, but received another cardinality or type. The fixed paths cover a singleton boolean result and the two numeric operands of binary jsonpath arithmetic; the SQL function and the @@ operator have different default silent behavior.

Field Value
SQLSTATE 22038
Condition singleton_sql_json_item_required
Status active
Known present by 12.0
Locked snapshots 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3
Macros ERRCODE_SINGLETON_SQL_JSON_ITEM_REQUIRED
Aliases

Messages

Representative primary texts are:

Guard Primary
Non-singleton or non-boolean jsonb_path_match result in throwing mode single boolean result is expected
Left binary arithmetic operand is not one numeric item left operand of jsonpath operator %s is not a single numeric value
Right binary arithmetic operand is not one numeric item right operand of jsonpath operator %s is not a single numeric value

Meaning

jsonb_path_match_internal treats exactly two C arguments as the @@ operator path: jsonb_path_match_opr leaves silent=true, so a non-singleton or non-boolean result becomes NULL. The SQL function is declared as jsonb_path_match(target, path, vars DEFAULT '{}', silent DEFAULT false); even a call written with two SQL arguments is expanded with both defaults, so it is non-silent and can raise 22038 unless the caller supplies silent=true. A four-argument call follows its supplied silent value. A single JSON null returns SQL NULL. Binary arithmetic separately evaluates each operand sequence, and both sides must contain exactly one numeric item. The shared evaluator may unwrap arrays in lax mode before this singleton check.

Diagnosis

Identify whether the syntax is the @@ operator or the jsonb_path_match function, and inspect the actual argument/default expansion before interpreting a NULL result. A path that yields several values, a non-boolean match result, or a left/right item that is not numeric belongs to this singleton/type boundary. Distinguish it from 22034 JSON_QUERY/JSON_VALUE cardinality, 2203F scalar-type enforcement, and 22036 numeric item-method conversion.

Response

Narrow the path or select one item explicitly. For binary arithmetic, make both operands resolve to one numeric item. Choose @@ when its suppressing behavior is intended, or call jsonb_path_match(..., false) when a mismatch should remain an ERROR; use silent=true only when NULL is the intended result. If an ERROR occurred in an explicit transaction, roll back or roll back to the existing savepoint before retrying; autocommit can retry the corrected action.

Versions

The locked catalogue records this condition from 12.0; the fixed match and binary-arithmetic paths are PostgreSQL 18.6. No natural runtime observation is claimed for this page.

22034, 2203F, 22036

Sources

The match wrapper and singleton guard are jsonpath_exec.c#L453-491; binary arithmetic singleton checks are #L2087-2155; the shared strict/lax and throw-return macros are #L235-249. The SQL defaults are fixed in system_functions.sql#L539-544, the direct function and @@ implementation signatures in pg_proc.dat#L10520-10522 and #L10547-10549, and the operator binding in pg_operator.dat#L3262-3264. The structured evidence record keeps both paths and exact primaries; no natural runtime was run.