@@ -1029,6 +1029,18 @@ transformRangeTableSample(ParseState *pstate, RangeTableSample *rts)
1029
1029
return tablesample ;
1030
1030
}
1031
1031
1032
+ static Node *
1033
+ makeStringConst (char * str , int location )
1034
+ {
1035
+ A_Const * n = makeNode (A_Const );
1036
+
1037
+ n -> val .type = T_String ;
1038
+ n -> val .val .str = str ;
1039
+ n -> location = location ;
1040
+
1041
+ return (Node * )n ;
1042
+ }
1043
+
1032
1044
/*
1033
1045
* getRTEForSpecialRelationTypes
1034
1046
*
@@ -1072,6 +1084,7 @@ transformJsonTableColumn(JsonTableColumn *jtc, Node *contextItemExpr,
1072
1084
JsonValueExpr * jvexpr = makeNode (JsonValueExpr );
1073
1085
JsonCommon * common = makeNode (JsonCommon );
1074
1086
JsonOutput * output = makeNode (JsonOutput );
1087
+ JsonPathSpec pathspec ;
1075
1088
1076
1089
jfexpr -> op = jtc -> coltype == JTC_REGULAR ? IS_JSON_VALUE : IS_JSON_QUERY ;
1077
1090
jfexpr -> common = common ;
@@ -1092,7 +1105,7 @@ transformJsonTableColumn(JsonTableColumn *jtc, Node *contextItemExpr,
1092
1105
common -> passing = passingArgs ;
1093
1106
1094
1107
if (jtc -> pathspec )
1095
- common -> pathspec = jtc -> pathspec ;
1108
+ pathspec = jtc -> pathspec ;
1096
1109
else
1097
1110
{
1098
1111
/* Construct default path as '$."column_name"' */
@@ -1103,9 +1116,11 @@ transformJsonTableColumn(JsonTableColumn *jtc, Node *contextItemExpr,
1103
1116
appendStringInfoString (& path , "$." );
1104
1117
escape_json (& path , jtc -> name );
1105
1118
1106
- common -> pathspec = path .data ;
1119
+ pathspec = path .data ;
1107
1120
}
1108
1121
1122
+ common -> pathspec = makeStringConst (pathspec , -1 );
1123
+
1109
1124
jvexpr -> expr = (Expr * ) contextItemExpr ;
1110
1125
jvexpr -> format .type = JS_FORMAT_DEFAULT ;
1111
1126
jvexpr -> format .encoding = JS_ENC_DEFAULT ;
@@ -1606,6 +1621,7 @@ transformJsonTable(ParseState *pstate, JsonTable *jt)
1606
1621
JsonCommon * jscommon ;
1607
1622
JsonTablePlan * plan = jt -> plan ;
1608
1623
char * rootPathName = jt -> common -> pathname ;
1624
+ char * rootPath ;
1609
1625
bool is_lateral ;
1610
1626
1611
1627
cxt .table = jt ;
@@ -1637,7 +1653,7 @@ transformJsonTable(ParseState *pstate, JsonTable *jt)
1637
1653
#endif
1638
1654
1639
1655
jscommon = copyObject (jt -> common );
1640
- jscommon -> pathspec = pstrdup ("$" );
1656
+ jscommon -> pathspec = makeStringConst ( pstrdup ("$" ), -1 );
1641
1657
1642
1658
jfe -> op = IS_JSON_TABLE ;
1643
1659
jfe -> common = jscommon ;
@@ -1661,10 +1677,19 @@ transformJsonTable(ParseState *pstate, JsonTable *jt)
1661
1677
1662
1678
cxt .contextItemTypid = exprType (tf -> docexpr );
1663
1679
1680
+ if (!IsA (jt -> common -> pathspec , A_Const ) ||
1681
+ castNode (A_Const , jt -> common -> pathspec )-> val .type != T_String )
1682
+ ereport (ERROR ,
1683
+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
1684
+ errmsg ("only string constants supported in JSON_TABLE path specification" ),
1685
+ parser_errposition (pstate ,
1686
+ exprLocation (jt -> common -> pathspec ))));
1687
+
1688
+ rootPath = castNode (A_Const , jt -> common -> pathspec )-> val .val .str ;
1689
+
1664
1690
tf -> plan = (Node * ) transformJsonTableColumns (pstate , & cxt , plan ,
1665
1691
jt -> columns ,
1666
- jt -> common -> pathspec ,
1667
- & rootPathName ,
1692
+ rootPath , & rootPathName ,
1668
1693
jt -> common -> location );
1669
1694
1670
1695
tf -> ordinalitycol = -1 ; /* undefine ordinality column number */
0 commit comments