22035
PostgreSQLERRORNotableData ExceptionHIGH confidence

no SQL/JSON item

What this means

SQLSTATE 22035 is raised when a SQL/JSON path expression in a strict mode context matches no items and an error should be raised rather than returning an empty result.

Why it happens
  1. 1A SQL/JSON path query in strict mode finds no matching elements in the JSON value
How to reproduce

SQL/JSON strict mode path with no match.

trigger — this will error
trigger — this will error
SELECT jsonb_path_query('{"a":1}'::jsonb, 'strict $.b');

expected output

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

Fix 1

Use lax mode (default) to return empty set instead of error

WHEN When the path may not match and an empty result is acceptable.

Use lax mode (default) to return empty set instead of error
SELECT jsonb_path_query('{"a":1}'::jsonb, 'lax $.b');

Why this works

Lax mode suppresses errors for missing keys and returns an empty sequence, which is usually more practical.

Fix 2

Check for key existence before accessing

WHEN When the key may be optional.

Check for key existence before accessing
SELECT jsonb_path_query('{"a":1}'::jsonb, '$.b') WHERE '{"a":1}'::jsonb ? 'b';

Why this works

The ? operator checks for key existence before the path query.

Version notes
Postgres 14+

Strict/lax mode distinction 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