more than one SQL/JSON item
SQLSTATE 22034 is raised when a SQL/JSON path expression used in a scalar context returns more than one item. The expression is expected to produce a single value but the path matches multiple elements.
- 1Using jsonb_path_query_first() or a scalar SQL/JSON context where the path matches multiple array elements
SQL/JSON scalar query matching multiple elements.
SELECT jsonb_path_query_first('[1,2,3]'::jsonb, '$[*]');
-- $[*] matches all 3 elementsexpected output
ERROR: more than one SQL/JSON item
Fix 1
Use jsonb_path_query() to retrieve all matching items
WHEN When the path may match multiple elements.
SELECT * FROM jsonb_path_query('[1,2,3]'::jsonb, '$[*]');Why this works
jsonb_path_query() returns a set of rows, one per match, rather than requiring a single result.
Fix 2
Narrow the path expression to match a single element
WHEN When exactly one result is expected.
SELECT jsonb_path_query_first('[1,2,3]'::jsonb, '$[0]'); -- first elementWhy this works
Specifying a concrete index or a more specific path ensures at most one match.
SQL/JSON path functions available from Postgres 12; improved in 14+.
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev