mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-20 13:27:00 +08:00
SQL/JSON: Fix issues with DEFAULT .. ON ERROR / EMPTY
SQL/JSON query functions allow specifying an expression to return when either of ON ERROR or ON EMPTY condition occurs when evaluating the JSON path expression. The parser (transformJsonBehavior()) checks that the specified expression is one of the supported expressions, but there are two issues with how the check is done that are fixed in this commit: * No check for some expressions related to coercion, such as CoerceViaIO, that may appear in the transformed user-specified expressions that include cast(s) * An unsupported expression may be masked by a coercion-related expression, which must be flagged by checking the latter's argument expression recursively Author: Jian He <jian.universality@gmail.com> Author: Amit Langote <amitlangote09@gmail.com> Reported-by: Jian He <jian.universality@gmail.com> Discussion: https://postgr.es/m/CACJufxEqhqsfrg_p7EMyo5zak3d767iFDL8vz_4%3DZBHpOtrghw@mail.gmail.com Discussion: https://postgr.es/m/CACJufxGOerH1QJknm1noh-Kz5FqU4p7QfeZSeVT2tN_4SLXYNg@mail.gmail.com
This commit is contained in:
@ -116,6 +116,22 @@ FROM json_table_test vals
|
||||
) jt
|
||||
ON true;
|
||||
|
||||
-- Test using casts in DEFAULT .. ON ERROR expression
|
||||
SELECT * FROM JSON_TABLE(jsonb '{"d1": "H"}', '$'
|
||||
COLUMNS (js1 jsonb_test_domain PATH '$.a2' DEFAULT '"foo1"'::jsonb::text ON ERROR));
|
||||
|
||||
SELECT * FROM JSON_TABLE(jsonb '{"d1": "H"}', '$'
|
||||
COLUMNS (js1 jsonb_test_domain PATH '$.a2' DEFAULT 'foo'::jsonb_test_domain ON ERROR));
|
||||
|
||||
SELECT * FROM JSON_TABLE(jsonb '{"d1": "H"}', '$'
|
||||
COLUMNS (js1 jsonb_test_domain PATH '$.a2' DEFAULT 'foo1'::jsonb_test_domain ON ERROR));
|
||||
|
||||
SELECT * FROM JSON_TABLE(jsonb '{"d1": "foo"}', '$'
|
||||
COLUMNS (js1 jsonb_test_domain PATH '$.d1' DEFAULT 'foo2'::jsonb_test_domain ON ERROR));
|
||||
|
||||
SELECT * FROM JSON_TABLE(jsonb '{"d1": "foo"}', '$'
|
||||
COLUMNS (js1 oid[] PATH '$.d2' DEFAULT '{1}'::int[]::oid[] ON ERROR));
|
||||
|
||||
-- JSON_TABLE: Test backward parsing
|
||||
|
||||
CREATE VIEW jsonb_table_view2 AS
|
||||
|
||||
Reference in New Issue
Block a user