22033ERRORTier 2 — Caution✅ HIGH confidenceinvalid SQL/JSON subscript
Category: Data ExceptionVersions: Postgres 14+
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
SELECT ('[1,2,3]'::jsonb)['a']; -- string subscript on arrayERROR: invalid subscript type
Fix 1: Use integer subscripts for JSON arrays
When accessing JSON array elements by index.
fix
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 docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 22 — Data Exception
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE for SQL/JSON subscript validation. Postgres 14+ feature.
See also
📄 Reference pages
JSON SubscriptingJSONB Operators
⚙️ 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 →