2202E
PostgreSQLERRORNotableData ExceptionHIGH confidence

array 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
  1. 1Array subscript expression evaluates to a non-integer or NULL in a context that requires a valid integer index
  2. 2Using a subscript that violates array dimension constraints
How to reproduce

Constructing an array with an invalid subscript expression.

trigger — this will error
trigger — this will error
SELECT ARRAY[1,2,3]['a']; -- non-integer subscript

expected output

ERROR:  array subscript must have integer type

Fix

Ensure array subscripts are integer expressions

WHEN When subscripting arrays in SQL or PL/pgSQL.

Ensure array subscripts are integer expressions
SELECT ARRAY[1,2,3][2]; -- valid integer subscript

Why this works

Postgres arrays require integer subscripts. Cast or convert subscript expressions to INTEGER if necessary.

Sources
Official documentation ↗

Class 22 — Data Exception

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors