@@ -4535,7 +4535,7 @@ static JsonExpr *
45354535transformJsonExprCommon (ParseState * pstate , JsonFuncExpr * func )
45364536{
45374537 JsonExpr * jsexpr = makeNode (JsonExpr );
4538- Datum jsonpath ;
4538+ Node * pathspec ;
45394539 JsonFormatType format ;
45404540
45414541 if (func -> common -> pathname )
@@ -4566,12 +4566,19 @@ transformJsonExprCommon(ParseState *pstate, JsonFuncExpr *func)
45664566
45674567 jsexpr -> format = func -> common -> expr -> format ;
45684568
4569- /* parse JSON path string */
4570- jsonpath = DirectFunctionCall1 (jsonpath_in ,
4571- CStringGetDatum (func -> common -> pathspec ));
4569+ pathspec = transformExprRecurse (pstate , func -> common -> pathspec );
45724570
4573- jsexpr -> path_spec = makeConst (JSONPATHOID , -1 , InvalidOid , -1 ,
4574- jsonpath , false, false);
4571+ jsexpr -> path_spec =
4572+ coerce_to_target_type (pstate , pathspec , exprType (pathspec ),
4573+ JSONPATHOID , -1 ,
4574+ COERCION_EXPLICIT , COERCE_IMPLICIT_CAST ,
4575+ exprLocation (pathspec ));
4576+ if (!jsexpr -> path_spec )
4577+ ereport (ERROR ,
4578+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
4579+ errmsg ("JSON path expression must be type %s, not type %s" ,
4580+ "jsonpath" , format_type_be (exprType (pathspec ))),
4581+ parser_errposition (pstate , exprLocation (pathspec ))));
45754582
45764583 /* transform and coerce to json[b] passing arguments */
45774584 transformJsonPassingArgs (pstate , format , func -> common -> passing ,
0 commit comments