no SQL/JSON item
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.
- 1A SQL/JSON path query in strict mode finds no matching elements in the JSON value
SQL/JSON strict mode path with no match.
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.
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.
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.
Strict/lax mode distinction refined in Postgres 14.
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev