2202EERRORTier 2 — Caution✅ HIGH confidencearray subscript error
What this means
SQLSTATE 2202E is raised when an array subscript (index) is used that falls outside the valid bounds of the array. Unlike some languages, Postgres does not raise this for simple out-of-bounds reads — it returns NULL — but it does raise it for invalid subscript expressions used in array slicing or construction.
Why it happens
- 1Array subscript expression evaluates to a non-integer or NULL in a context that requires a valid integer index
- 2Using a subscript that violates array dimension constraints
How to reproduce
Constructing an array with an invalid subscript expression.
SELECT ARRAY[1,2,3]['a']; -- non-integer subscriptFix 1: Ensure array subscripts are integer expressions
When subscripting arrays in SQL or PL/pgSQL.
SELECT ARRAY[1,2,3][2]; -- valid integer subscriptWhy this works
Postgres arrays require integer subscripts. Cast or convert subscript expressions to INTEGER if necessary.
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 array subscript errors. Stable across versions.
See also
🔗 Related errors
📄 Reference pages