@@ -1059,6 +1059,18 @@ transformRangeTableSample(ParseState *pstate, RangeTableSample *rts)
10591059 return tablesample ;
10601060}
10611061
1062+ static Node *
1063+ makeStringConst (char * str , int location )
1064+ {
1065+ A_Const * n = makeNode (A_Const );
1066+
1067+ n -> val .type = T_String ;
1068+ n -> val .val .str = str ;
1069+ n -> location = location ;
1070+
1071+ return (Node * )n ;
1072+ }
1073+
10621074/*
10631075 * getRTEForSpecialRelationTypes
10641076 *
@@ -1102,6 +1114,7 @@ transformJsonTableColumn(JsonTableColumn *jtc, Node *contextItemExpr,
11021114 JsonValueExpr * jvexpr = makeNode (JsonValueExpr );
11031115 JsonCommon * common = makeNode (JsonCommon );
11041116 JsonOutput * output = makeNode (JsonOutput );
1117+ JsonPathSpec pathspec ;
11051118
11061119 jfexpr -> op = jtc -> coltype == JTC_REGULAR ? IS_JSON_VALUE : IS_JSON_QUERY ;
11071120 jfexpr -> common = common ;
@@ -1122,7 +1135,7 @@ transformJsonTableColumn(JsonTableColumn *jtc, Node *contextItemExpr,
11221135 common -> passing = passingArgs ;
11231136
11241137 if (jtc -> pathspec )
1125- common -> pathspec = jtc -> pathspec ;
1138+ pathspec = jtc -> pathspec ;
11261139 else
11271140 {
11281141 /* Construct default path as '$."column_name"' */
@@ -1133,9 +1146,11 @@ transformJsonTableColumn(JsonTableColumn *jtc, Node *contextItemExpr,
11331146 appendStringInfoString (& path , "$." );
11341147 escape_json (& path , jtc -> name );
11351148
1136- common -> pathspec = path .data ;
1149+ pathspec = path .data ;
11371150 }
11381151
1152+ common -> pathspec = makeStringConst (pathspec , -1 );
1153+
11391154 jvexpr -> expr = (Expr * ) contextItemExpr ;
11401155 jvexpr -> format .type = JS_FORMAT_DEFAULT ;
11411156 jvexpr -> format .encoding = JS_ENC_DEFAULT ;
@@ -1629,6 +1644,7 @@ transformJsonTable(ParseState *pstate, JsonTable *jt)
16291644 JsonCommon * jscommon ;
16301645 JsonTablePlan * plan = jt -> plan ;
16311646 char * rootPathName = jt -> common -> pathname ;
1647+ char * rootPath ;
16321648 bool is_lateral ;
16331649
16341650 cxt .table = jt ;
@@ -1658,7 +1674,7 @@ transformJsonTable(ParseState *pstate, JsonTable *jt)
16581674 }
16591675
16601676 jscommon = copyObject (jt -> common );
1661- jscommon -> pathspec = pstrdup ("$" );
1677+ jscommon -> pathspec = makeStringConst ( pstrdup ("$" ), -1 );
16621678
16631679 jfe -> op = IS_JSON_TABLE ;
16641680 jfe -> common = jscommon ;
@@ -1682,10 +1698,19 @@ transformJsonTable(ParseState *pstate, JsonTable *jt)
16821698
16831699 cxt .contextItemTypid = exprType (tf -> docexpr );
16841700
1701+ if (!IsA (jt -> common -> pathspec , A_Const ) ||
1702+ castNode (A_Const , jt -> common -> pathspec )-> val .type != T_String )
1703+ ereport (ERROR ,
1704+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
1705+ errmsg ("only string constants supported in JSON_TABLE path specification" ),
1706+ parser_errposition (pstate ,
1707+ exprLocation (jt -> common -> pathspec ))));
1708+
1709+ rootPath = castNode (A_Const , jt -> common -> pathspec )-> val .val .str ;
1710+
16851711 tf -> plan = (Node * ) transformJsonTableColumns (pstate , & cxt , plan ,
16861712 jt -> columns ,
1687- jt -> common -> pathspec ,
1688- & rootPathName ,
1713+ rootPath , & rootPathName ,
16891714 jt -> common -> location );
16901715
16911716 tf -> ordinalitycol = -1 ; /* undefine ordinality column number */
0 commit comments