22033
PostgreSQLERRORNotableData ExceptionHIGH confidence
invalid SQL/JSON subscript
What this means
SQLSTATE 22033 is raised when a SQL/JSON subscript expression is invalid — for example, a non-integer subscript used to access a JSON array element.
Why it happens
- 1Using a non-integer or out-of-range subscript on a JSON array via the SQL/JSON subscript operator
How to reproduce
Invalid subscript on a JSONB array.
trigger — this will error
trigger — this will error
SELECT ('[1,2,3]'::jsonb)['a']; -- string subscript on arrayexpected output
ERROR: invalid subscript type
Fix
Use integer subscripts for JSON arrays
WHEN When accessing JSON array elements by index.
Use integer subscripts for JSON arrays
SELECT ('[1,2,3]'::jsonb)[1]; -- zero-based or 1-based depending on contextWhy this works
JSON arrays are indexed by integer position. Use -> or ->> operators or integer subscripts.
Version notes
Postgres 14+
SQL/JSON subscript syntax introduced in Postgres 14.
Sources
Official documentation ↗
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev