PG
PRO
22039ERRORTier 2 — Caution✅ HIGH confidence

SQL/JSON array not found

Category: Data ExceptionVersions: Postgres 14+

What this means

SQLSTATE 22039 is raised when a SQL/JSON operation expects a JSON array but the path expression resolves to a non-array value.

Why it happens

  1. 1Applying an array-specific SQL/JSON operation to an object, string, number, or boolean JSON value

How to reproduce

Array SQL/JSON operation on a non-array value.

trigger — this will ERROR
SELECT jsonb_path_query('{"a":1}'::jsonb, 'strict $.a[0]');
ERROR: jsonpath array subscript is not implemented for type object

Fix 1: Verify the JSON value is an array before subscripting

When the JSON structure is not guaranteed to be an array.

fix
SELECT jsonb_typeof('{"a":1}'::jsonb -> 'a'); -- check type first

Why this works

Use jsonb_typeof() to confirm the value is an array before applying array subscripts.

Version notes

Postgres 14+SQL/JSON strict array access refined in Postgres 14.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

🔧 Source ref: Class 22 — Data Exception

Confidence assessment

✅ HIGH confidence

Standard SQLSTATE. Stable.

See also

📄 Reference pages

SQL/JSON Path Languagejsonb_typeof
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →