@@ -4414,7 +4414,7 @@ static JsonExpr *
44144414transformJsonExprCommon (ParseState * pstate , JsonFuncExpr * func )
44154415{
44164416 JsonExpr * jsexpr = makeNode (JsonExpr );
4417- Datum jsonpath ;
4417+ Node * pathspec ;
44184418 JsonFormatType format ;
44194419
44204420 if (func -> common -> pathname )
@@ -4445,12 +4445,19 @@ transformJsonExprCommon(ParseState *pstate, JsonFuncExpr *func)
44454445
44464446 jsexpr -> format = func -> common -> expr -> format ;
44474447
4448- /* parse JSON path string */
4449- jsonpath = DirectFunctionCall1 (jsonpath_in ,
4450- CStringGetDatum (func -> common -> pathspec ));
4448+ pathspec = transformExprRecurse (pstate , func -> common -> pathspec );
44514449
4452- jsexpr -> path_spec = makeConst (JSONPATHOID , -1 , InvalidOid , -1 ,
4453- jsonpath , false, false);
4450+ jsexpr -> path_spec =
4451+ coerce_to_target_type (pstate , pathspec , exprType (pathspec ),
4452+ JSONPATHOID , -1 ,
4453+ COERCION_EXPLICIT , COERCE_IMPLICIT_CAST ,
4454+ exprLocation (pathspec ));
4455+ if (!jsexpr -> path_spec )
4456+ ereport (ERROR ,
4457+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
4458+ errmsg ("JSON path expression must be type %s, not type %s" ,
4459+ "jsonpath" , format_type_be (exprType (pathspec ))),
4460+ parser_errposition (pstate , exprLocation (pathspec ))));
44544461
44554462 /* transform and coerce to json[b] passing arguments */
44564463 transformJsonPassingArgs (pstate , format , func -> common -> passing ,
0 commit comments