select open change scope Open full search

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

SQLSTATE / CLASS 22 · DATA EXCEPTION

sql_json_array_not_found

SQLSTATE
22039
Condition name
sql_json_array_not_found
Class
Data Exception
Source macro
ERRCODE_SQL_JSON_ARRAY_NOT_FOUND
Evidence
Source path confirmed
Analysis & operational context

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

<h1>22039</h1>

At a glance

An array-only JSON path accessor or item method reached a non-array item without permitted auto-wrap or structural-error suppression. Fixed wildcard, indexed, and .size() paths expose separate array-type primaries; an out-of-bounds subscript is 22033.

Messages

Representative primary texts are:

Guard Primary
Wildcard array accessor receives a non-array jsonpath wildcard array accessor can only be applied to an array
Indexed array accessor receives a non-array jsonpath array accessor can only be applied to an array
.size() receives a non-array without permitted auto-wrap jsonpath item method .%s() can only be applied to an array

Meaning

The jpiAnyArray wildcard, jpiIndexArray indexed accessor, and .size() item-method branches can each auto-wrap a non-array item when jspAutoWrap(cxt) is enabled by lax mode. If auto-wrap is not permitted, jspIgnoreStructuralErrors can suppress the structural mismatch; when neither applies, the corresponding array-only branch reports 22039. A valid array with an invalid index reaches the separate 22033 subscript guard, so 22039 does not mean an empty array or an out-of-range index.

Diagnosis

Use the exact accessor or method named in the primary and inspect the item returned immediately before it. Separate a scalar/object input from a valid array whose index is outside its bounds, and check whether lax structural-error handling or auto-wrap/unwrap is part of the SQL/JSON path mode.

Response

Make the path select an array, normalize the input shape, or choose a scalar-compatible operation. If variable documents are expected, handle the scalar/array branch explicitly instead of relying on a structural mismatch to become an empty 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 array accessor and .size() guards are PostgreSQL 18.6. No natural runtime observation is claimed for this page.

Sources

The wildcard, indexed, and auto-wrap checks are jsonpath_exec.c#L836-979; the .size() array check is #L1101-1117. The strict/lax structural and throw-return macros are #L235-249. The structured evidence record binds the exact array messages and 22033 boundary; no natural runtime was run.

Source evidence

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

22039 is sql_json_array_not_found in SQLSTATE Class 22.

Method: Read fixed definition.

src.errcodes.18.6

The fixed jpiAnyArray wildcard, jpiIndexArray indexed accessor, and .size() item-method branches can each auto-wrap a non-array item when jspAutoWrap(cxt) is enabled by lax mode. If auto-wrap is not permitted, jspIgnoreStructuralErrors can suppress the structural mismatch; when neither applies, the corresponding array-only branch reports 22039. Array index out-of-bounds is a separate 22033 guard.

Method: Read the complete array wildcard/index and size-method guards, including structural-error suppression and the adjacent subscript boundary.

Limits: Source confirmation is not a natural runtime observation.

src.jsonpath.array-accessors src.jsonpath.array-size src.jsonpath.context-flags src.jsonpath.execute-context

The locked catalogue records 22039 from 12.0 without proving exact implementation introduction.

Method: Use catalogue boundary.

src.errcodes.18.6

Message templates

ERROR · message.wildcard-array

Primary

jsonpath wildcard array accessor can only be applied to an array
ERROR · message.index-array

Primary

jsonpath array accessor can only be applied to an array
ERROR · message.size-array

Primary

jsonpath item method .%s() can only be applied to an array

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Version history 1
  1. PG 11 → 12added

Definition snapshot: english-manuals:68b742ad06c3aad77bc6a253a84… · English manual source