Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8173736

Browse files
author
Nikita Glukhov
committed
Use nodes JsonFomat and JsonReturning in JSON_TABLE
1 parent 828b0c8 commit 8173736

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

src/backend/parser/gram.y

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15179,8 +15179,7 @@ json_table_regular_column_definition:
1517915179
n->coltype = JTC_REGULAR;
1518015180
n->name = $1;
1518115181
n->typeName = $2;
15182-
n->format.type = JS_FORMAT_DEFAULT;
15183-
n->format.encoding = JS_ENC_DEFAULT;
15182+
n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
1518415183
n->wrapper = JSW_NONE;
1518515184
n->omit_quotes = false;
1518615185
n->pathspec = $3;
@@ -15217,7 +15216,7 @@ json_table_formatted_column_definition:
1521715216
n->coltype = JTC_FORMATTED;
1521815217
n->name = $1;
1521915218
n->typeName = $2;
15220-
n->format = $4;
15219+
n->format = castNode(JsonFormat, $4);
1522115220
n->pathspec = $5;
1522215221
n->wrapper = $6;
1522315222
if (n->wrapper != JSW_NONE && $7 != JS_QUOTES_UNSPEC)

src/backend/parser/parse_expr.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4912,13 +4912,12 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
49124912
break;
49134913

49144914
case IS_JSON_TABLE:
4915-
jsexpr->returning.format.type = JS_FORMAT_DEFAULT;
4916-
jsexpr->returning.format.encoding = JS_ENC_DEFAULT;
4917-
jsexpr->returning.format.location = -1;
4918-
jsexpr->returning.typid = exprType(contextItemExpr);
4919-
jsexpr->returning.typmod = -1;
4915+
jsexpr->returning = makeNode(JsonReturning);
4916+
jsexpr->returning->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
4917+
jsexpr->returning->typid = exprType(contextItemExpr);
4918+
jsexpr->returning->typmod = -1;
49204919

4921-
if (jsexpr->returning.typid != JSONBOID)
4920+
if (jsexpr->returning->typid != JSONBOID)
49224921
ereport(ERROR,
49234922
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
49244923
errmsg("JSON_TABLE() is not yet implemented for json type"),

src/backend/parser/parse_jsontable.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ transformJsonTableColumn(JsonTableColumn *jtc, Node *contextItemExpr,
7070
JsonCommon *common = makeNode(JsonCommon);
7171
JsonOutput *output = makeNode(JsonOutput);
7272
JsonPathSpec pathspec;
73-
JsonFormat default_format;
73+
JsonFormat *default_format;
7474

7575
jfexpr->op = jtc->coltype == JTC_REGULAR ? IS_JSON_VALUE : IS_JSON_QUERY;
7676
jfexpr->common = common;
@@ -84,10 +84,10 @@ transformJsonTableColumn(JsonTableColumn *jtc, Node *contextItemExpr,
8484
jfexpr->location = jtc->location;
8585

8686
output->typeName = jtc->typeName;
87-
output->returning.format = jtc->format;
87+
output->returning = makeNode(JsonReturning);
88+
output->returning->format = jtc->format;
8889

89-
default_format.type = JS_FORMAT_DEFAULT;
90-
default_format.encoding = JS_ENC_DEFAULT;
90+
default_format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
9191

9292
common->pathname = NULL;
9393
common->expr = makeJsonValueExpr((Expr *) contextItemExpr, default_format);

src/backend/utils/adt/ruleutils.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10496,7 +10496,7 @@ get_json_table_columns(TableFunc *tf, JsonTableParentNode *node,
1049610496

1049710497
if (colexpr->op == IS_JSON_QUERY)
1049810498
appendStringInfoString(buf,
10499-
colexpr->format.type == JS_FORMAT_JSONB ?
10499+
colexpr->format->format == JS_FORMAT_JSONB ?
1050010500
" FORMAT JSONB" : " FORMAT JSON");
1050110501

1050210502
appendStringInfoString(buf, " PATH ");
@@ -10538,17 +10538,17 @@ get_json_table(TableFunc *tf, deparse_context *context, bool showimplicit)
1053810538

1053910539
get_rule_expr(jexpr->raw_expr, context, showimplicit);
1054010540

10541-
if (jexpr->format.type != JS_FORMAT_DEFAULT)
10541+
if (jexpr->format->format != JS_FORMAT_DEFAULT)
1054210542
{
1054310543
appendStringInfoString(buf,
10544-
jexpr->format.type == JS_FORMAT_JSONB ?
10544+
jexpr->format->format == JS_FORMAT_JSONB ?
1054510545
" FORMAT JSONB" : " FORMAT JSON");
1054610546

10547-
if (jexpr->format.encoding != JS_ENC_DEFAULT)
10547+
if (jexpr->format->encoding != JS_ENC_DEFAULT)
1054810548
{
1054910549
const char *encoding =
10550-
jexpr->format.encoding == JS_ENC_UTF16 ? "UTF16" :
10551-
jexpr->format.encoding == JS_ENC_UTF32 ? "UTF32" :
10550+
jexpr->format->encoding == JS_ENC_UTF16 ? "UTF16" :
10551+
jexpr->format->encoding == JS_ENC_UTF32 ? "UTF32" :
1055210552
"UTF8";
1055310553

1055410554
appendStringInfo(buf, " ENCODING %s", encoding);

src/include/nodes/parsenodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ typedef struct JsonTableColumn
15811581
char *name; /* column name */
15821582
TypeName *typeName; /* column type name */
15831583
JsonPathSpec pathspec; /* path specification, if any */
1584-
JsonFormat format; /* JSON format clause, if specified */
1584+
JsonFormat *format; /* JSON format clause, if specified */
15851585
JsonWrapper wrapper; /* WRAPPER behavior for formatted columns */
15861586
bool omit_quotes; /* omit or keep quotes on scalar strings? */
15871587
List *columns; /* nested columns */

0 commit comments

Comments
 (0)