SQL/JSON member not found
SQLSTATE 2203A is raised when a SQL/JSON member accessor (dot operator) is applied to a JSON object and the specified key does not exist, in strict mode.
- 1SQL/JSON strict mode path expression accessing a key that does not exist in the JSON object
Strict mode access to a non-existent JSON key.
SELECT jsonb_path_query('{"a":1}'::jsonb, 'strict $.b');expected output
ERROR: JSON object does not contain key "b"
Fix 1
Use lax mode to suppress the error for missing keys
WHEN When JSON keys may be optional.
SELECT jsonb_path_query('{"a":1}'::jsonb, 'lax $.b');Why this works
Lax mode returns an empty sequence for missing keys instead of raising an error.
Fix 2
Check for key existence with the ? operator
WHEN When key presence needs to be explicitly tested.
SELECT '{"a":1}'::jsonb ? 'b'; -- falseWhy this works
The ? operator checks key existence without raising an error.
SQL/JSON strict mode semantics refined in Postgres 14.
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev