PostgreSQL error code
PostgreSQL error 22034
22034 is the SQLSTATE PostgreSQL reports for more than one sql json item, in class 22, Data Exception.
| SQLSTATE | 22034 |
|---|---|
| Condition name | more_than_one_sql_json_item |
| Class | 22 — Data Exception |
Reproduce it, then fix it
JSON_VALUE returns a single scalar, and this path matches two. JSON_QUERY with WITH WRAPPER returns them all as an array. Without ERROR ON ERROR, JSON_VALUE would quietly return NULL. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
SELECT JSON_VALUE(jsonb '{"tags": ["sale", "new"]}', '$.tags[*]' ERROR ON ERROR);SELECT JSON_QUERY(jsonb '{"tags": ["sale", "new"]}', '$.tags[*]' WITH WRAPPER);