diff options
| author | Amit Langote | 2024-04-18 05:33:47 +0000 |
|---|---|---|
| committer | Amit Langote | 2024-04-18 05:45:48 +0000 |
| commit | b4fad46b6bc8a9bf46ff689bcb1bd4edf8f267af (patch) | |
| tree | 48accd814bfb6c712699b8f26734fbf06c949b3e /src/test | |
| parent | 40126ac68f2ff96351cd6071350eb2d5cbd50145 (diff) | |
SQL/JSON: Improve some error messages
This improves some error messages emitted by SQL/JSON query functions
by mentioning column name when available, such as when they are
invoked as part of evaluating JSON_TABLE() columns. To do so, a new
field column_name is added to both JsonFuncExpr and JsonExpr that is
only populated when creating those nodes for transformed JSON_TABLE()
columns.
While at it, relevant error messages are reworded for clarity.
Reported-by: Jian He <jian.universality@gmail.com>
Suggested-by: Jian He <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CACJufxG_e0QLCgaELrr2ZNz7AxPeGCNKAORe3fHtFCQLsH4J4Q@mail.gmail.com
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/sqljson_jsontable.out | 10 | ||||
| -rw-r--r-- | src/test/regress/expected/sqljson_queryfuncs.out | 30 | ||||
| -rw-r--r-- | src/test/regress/sql/sqljson_jsontable.sql | 3 |
3 files changed, 25 insertions, 18 deletions
diff --git a/src/test/regress/expected/sqljson_jsontable.out b/src/test/regress/expected/sqljson_jsontable.out index a00eec8a6f4..9eecd97f45c 100644 --- a/src/test/regress/expected/sqljson_jsontable.out +++ b/src/test/regress/expected/sqljson_jsontable.out @@ -492,11 +492,11 @@ FROM ON true; ERROR: invalid input syntax for type integer: "err" SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int PATH '$.a' ERROR ON EMPTY)) jt; -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path of column "a" SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int PATH 'strict $.a' ERROR ON ERROR) ERROR ON ERROR) jt; ERROR: jsonpath member accessor can only be applied to an object SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int PATH 'lax $.a' ERROR ON EMPTY) ERROR ON ERROR) jt; -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path of column "a" SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a int PATH '$' DEFAULT 1 ON EMPTY DEFAULT 2 ON ERROR)) jt; a --- @@ -637,6 +637,10 @@ SELECT * FROM JSON_TABLE(jsonb '{"a": 123}', '$' || '.' || 'a' COLUMNS (foo int) ERROR: only string constants are supported in JSON_TABLE path specification LINE 1: SELECT * FROM JSON_TABLE(jsonb '{"a": 123}', '$' || '.' || '... ^ +-- JsonPathQuery() error message mentioning column name +SELECT * FROM JSON_TABLE('{"a": [{"b": "1"}, {"b": "2"}]}', '$' COLUMNS (b json path '$.a[*].b' ERROR ON ERROR)); +ERROR: JSON path expression for column "b" should return single item without wrapper +HINT: Use WITH WRAPPER clause to wrap SQL/JSON items into array. -- JSON_TABLE: nested paths -- Duplicate path names SELECT * FROM JSON_TABLE( @@ -849,7 +853,7 @@ SELECT sub.* FROM s, xx int path '$.c', NESTED PATH '$.a.za[1]' columns (NESTED PATH '$.z21[*]' COLUMNS (z21 int path '$?(@ >= $"x")' ERROR ON ERROR)) )) sub; -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path of column "z21" -- Parent columns xx1, xx appear before NESTED ones SELECT sub.* FROM s, (VALUES (23)) x(x), generate_series(13, 13) y, diff --git a/src/test/regress/expected/sqljson_queryfuncs.out b/src/test/regress/expected/sqljson_queryfuncs.out index 9e86b0da10c..49b014b1ec8 100644 --- a/src/test/regress/expected/sqljson_queryfuncs.out +++ b/src/test/regress/expected/sqljson_queryfuncs.out @@ -339,7 +339,7 @@ SELECT JSON_VALUE(jsonb '[]', '$'); (1 row) SELECT JSON_VALUE(jsonb '[]', '$' ERROR ON ERROR); -ERROR: JSON path expression in JSON_VALUE should return singleton scalar item +ERROR: JSON path expression in JSON_VALUE should return single scalar item SELECT JSON_VALUE(jsonb '{}', '$'); json_value ------------ @@ -347,7 +347,7 @@ SELECT JSON_VALUE(jsonb '{}', '$'); (1 row) SELECT JSON_VALUE(jsonb '{}', '$' ERROR ON ERROR); -ERROR: JSON path expression in JSON_VALUE should return singleton scalar item +ERROR: JSON path expression in JSON_VALUE should return single scalar item SELECT JSON_VALUE(jsonb '1', '$.a'); json_value ------------ @@ -363,9 +363,9 @@ SELECT JSON_VALUE(jsonb '1', 'strict $.a' DEFAULT 'error' ON ERROR); (1 row) SELECT JSON_VALUE(jsonb '1', 'lax $.a' ERROR ON ERROR); -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path SELECT JSON_VALUE(jsonb '1', 'lax $.a' ERROR ON EMPTY ERROR ON ERROR); -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path SELECT JSON_VALUE(jsonb '1', 'strict $.a' DEFAULT 2 ON ERROR); json_value ------------ @@ -397,9 +397,9 @@ SELECT JSON_VALUE(jsonb '1', 'lax $.a' DEFAULT '2' ON EMPTY DEFAULT '3' ON ERROR (1 row) SELECT JSON_VALUE(jsonb '1', 'lax $.a' ERROR ON EMPTY DEFAULT '3' ON ERROR); -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path SELECT JSON_VALUE(jsonb '[1,2]', '$[*]' ERROR ON ERROR); -ERROR: JSON path expression in JSON_VALUE should return singleton scalar item +ERROR: JSON path expression in JSON_VALUE should return single scalar item SELECT JSON_VALUE(jsonb '[1,2]', '$[*]' DEFAULT '0' ON ERROR); json_value ------------ @@ -758,7 +758,7 @@ SELECT JSON_QUERY(jsonb '[]', '$[*]' EMPTY OBJECT ON EMPTY); (1 row) SELECT JSON_QUERY(jsonb '[]', '$[*]' ERROR ON EMPTY); -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path SELECT JSON_QUERY(jsonb '[]', '$[*]' DEFAULT '"empty"' ON EMPTY); json_query ------------ @@ -766,18 +766,18 @@ SELECT JSON_QUERY(jsonb '[]', '$[*]' DEFAULT '"empty"' ON EMPTY); (1 row) SELECT JSON_QUERY(jsonb '[]', '$[*]' ERROR ON EMPTY NULL ON ERROR); -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path SELECT JSON_QUERY(jsonb '[]', '$[*]' ERROR ON EMPTY EMPTY ARRAY ON ERROR); -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path SELECT JSON_QUERY(jsonb '[]', '$[*]' ERROR ON EMPTY EMPTY OBJECT ON ERROR); -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path SELECT JSON_QUERY(jsonb '[]', '$[*]' ERROR ON EMPTY ERROR ON ERROR); -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path SELECT JSON_QUERY(jsonb '[]', '$[*]' ERROR ON ERROR); -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path SELECT JSON_QUERY(jsonb '[1,2]', '$[*]' ERROR ON ERROR); -ERROR: JSON path expression in JSON_QUERY should return singleton item without wrapper -HINT: Use WITH WRAPPER clause to wrap SQL/JSON item sequence into array. +ERROR: JSON path expression in JSON_QUERY should return single item without wrapper +HINT: Use WITH WRAPPER clause to wrap SQL/JSON items into array. SELECT JSON_QUERY(jsonb '[1,2]', '$[*]' DEFAULT '"empty"' ON ERROR); json_query ------------ @@ -1033,7 +1033,7 @@ SELECT JSON_QUERY(jsonb '{"a": 1}', '$.b' RETURNING sqljsonb_int_not_null); (1 row) SELECT JSON_QUERY(jsonb '{"a": 1}', '$.b' RETURNING sqljsonb_int_not_null ERROR ON ERROR); -ERROR: no SQL/JSON item +ERROR: no SQL/JSON item found for specified path -- Test timestamptz passing and output SELECT JSON_QUERY(jsonb 'null', '$ts' PASSING timestamptz '2018-02-21 12:34:56 +10' AS ts); json_query diff --git a/src/test/regress/sql/sqljson_jsontable.sql b/src/test/regress/sql/sqljson_jsontable.sql index 3752ccc446b..29c0c6ba529 100644 --- a/src/test/regress/sql/sqljson_jsontable.sql +++ b/src/test/regress/sql/sqljson_jsontable.sql @@ -290,6 +290,9 @@ FROM JSON_TABLE( -- Should fail (not supported) SELECT * FROM JSON_TABLE(jsonb '{"a": 123}', '$' || '.' || 'a' COLUMNS (foo int)); +-- JsonPathQuery() error message mentioning column name +SELECT * FROM JSON_TABLE('{"a": [{"b": "1"}, {"b": "2"}]}', '$' COLUMNS (b json path '$.a[*].b' ERROR ON ERROR)); + -- JSON_TABLE: nested paths -- Duplicate path names |
