2203C
PostgreSQLERRORNotableData ExceptionHIGH confidence

SQL/JSON object not found

What this means

SQLSTATE 2203C is raised when a SQL/JSON member accessor is applied to a value that is not a JSON object (e.g., applied to an array or scalar).

Why it happens
  1. 1Using a dot (member) accessor on a JSON array, number, string, or boolean value in strict mode
How to reproduce

Member accessor on a non-object JSON value.

trigger — this will error
trigger — this will error
SELECT jsonb_path_query('[1,2,3]'::jsonb, 'strict $.key');

expected output

ERROR:  jsonpath member accessor can only be applied to an object

Fix

Use array subscripts for arrays, member accessors for objects

WHEN When the JSON structure type is known.

Use array subscripts for arrays, member accessors for objects
SELECT jsonb_path_query('[1,2,3]'::jsonb, '$[0]'); -- array subscript

Why this works

Use [n] for array access and .key for object member access in JSON path expressions.

Version notes
Postgres 14+

Strict mode type checking refined 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

← All PostgreSQL errors