Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit565caaa

Browse files
committed
SQL/JSON: Fix default ON ERROR behavior for JSON_TABLE
Use EMPTY ARRAY instead of EMPTY.This change does not affect the runtime behavior of JSON_TABLE(),which continues to return an empty relation ON ERROR. It only alterswhether the default ON ERROR behavior is shown in the deparsed output.Reported-by: Jian He <jian.universality@gmail.com>Discussion:https://postgr.es/m/CACJufxEo4sUjKCYtda0_qt9tazqqKPmF1cqhW9KBOUeJFqQd2g@mail.gmail.comBackpatch-through: 17
1 parent6822285 commit565caaa

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

‎src/backend/parser/parse_expr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4603,13 +4603,13 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
46034603
}
46044604

46054605
/*
4606-
* Assume EMPTY ON ERROR when ON ERROR is not specified.
4606+
* Assume EMPTYARRAYON ERROR when ON ERROR is not specified.
46074607
*
46084608
* ON EMPTY cannot be specified at the top level but it can be for
46094609
* the individual columns.
46104610
*/
46114611
jsexpr->on_error=transformJsonBehavior(pstate,func->on_error,
4612-
JSON_BEHAVIOR_EMPTY,
4612+
JSON_BEHAVIOR_EMPTY_ARRAY,
46134613
jsexpr->returning);
46144614
break;
46154615

‎src/backend/utils/adt/ruleutils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11875,7 +11875,7 @@ get_json_table(TableFunc *tf, deparse_context *context, bool showimplicit)
1187511875
get_json_table_columns(tf,castNode(JsonTablePathScan,tf->plan),context,
1187611876
showimplicit);
1187711877

11878-
if (jexpr->on_error->btype!=JSON_BEHAVIOR_EMPTY)
11878+
if (jexpr->on_error->btype!=JSON_BEHAVIOR_EMPTY_ARRAY)
1187911879
get_json_behavior(jexpr->on_error,context,"ERROR");
1188011880

1188111881
if (PRETTY_INDENT(context))

‎src/test/regress/expected/sqljson_jsontable.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,3 +1150,28 @@ EXPLAIN VERBOSE SELECT * from JSON_TABLE('"a"', '$' COLUMNS (a text PATH '$') ER
11501150
Table Function Call: JSON_TABLE('"a"'::jsonb, '$' AS json_table_path_0 COLUMNS (a text PATH '$') ERROR ON ERROR)
11511151
(3 rows)
11521152

1153+
-- Test JSON_TABLE() deparsing -- don't emit default ON ERROR behavior
1154+
EXPLAIN VERBOSE SELECT * from JSON_TABLE('"a"', '$' COLUMNS (a text PATH '$'));
1155+
QUERY PLAN
1156+
-----------------------------------------------------------------------------------------------------
1157+
Table Function Scan on "json_table" (cost=0.01..1.00 rows=100 width=32)
1158+
Output: a
1159+
Table Function Call: JSON_TABLE('"a"'::jsonb, '$' AS json_table_path_0 COLUMNS (a text PATH '$'))
1160+
(3 rows)
1161+
1162+
EXPLAIN VERBOSE SELECT * from JSON_TABLE('"a"', '$' COLUMNS (a text PATH '$') EMPTY ON ERROR);
1163+
QUERY PLAN
1164+
-----------------------------------------------------------------------------------------------------
1165+
Table Function Scan on "json_table" (cost=0.01..1.00 rows=100 width=32)
1166+
Output: a
1167+
Table Function Call: JSON_TABLE('"a"'::jsonb, '$' AS json_table_path_0 COLUMNS (a text PATH '$'))
1168+
(3 rows)
1169+
1170+
EXPLAIN VERBOSE SELECT * from JSON_TABLE('"a"', '$' COLUMNS (a text PATH '$') EMPTY ARRAY ON ERROR);
1171+
QUERY PLAN
1172+
-----------------------------------------------------------------------------------------------------
1173+
Table Function Scan on "json_table" (cost=0.01..1.00 rows=100 width=32)
1174+
Output: a
1175+
Table Function Call: JSON_TABLE('"a"'::jsonb, '$' AS json_table_path_0 COLUMNS (a text PATH '$'))
1176+
(3 rows)
1177+

‎src/test/regress/sql/sqljson_jsontable.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,8 @@ SELECT * FROM JSON_TABLE(jsonb '1', '$' COLUMNS (a int exists empty object on er
547547
-- behavior
548548
EXPLAIN VERBOSESELECT*from JSON_TABLE('"a"','$' COLUMNS (atextPATH'$'));
549549
EXPLAIN VERBOSESELECT*from JSON_TABLE('"a"','$' COLUMNS (atextPATH'$') ERRORON ERROR);
550+
551+
-- Test JSON_TABLE() deparsing -- don't emit default ON ERROR behavior
552+
EXPLAIN VERBOSESELECT*from JSON_TABLE('"a"','$' COLUMNS (atextPATH'$'));
553+
EXPLAIN VERBOSESELECT*from JSON_TABLE('"a"','$' COLUMNS (atextPATH'$') EMPTYON ERROR);
554+
EXPLAIN VERBOSESELECT*from JSON_TABLE('"a"','$' COLUMNS (atextPATH'$') EMPTY ARRAYON ERROR);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp