@@ -4395,7 +4395,7 @@ static JsonExpr *
43954395transformJsonExprCommon (ParseState * pstate , JsonFuncExpr * func )
43964396{
43974397 JsonExpr * jsexpr = makeNode (JsonExpr );
4398- Datum jsonpath ;
4398+ Node * pathspec ;
43994399 JsonFormatType format ;
44004400
44014401 if (func -> common -> pathname )
@@ -4426,12 +4426,19 @@ transformJsonExprCommon(ParseState *pstate, JsonFuncExpr *func)
44264426
44274427 jsexpr -> format = func -> common -> expr -> format ;
44284428
4429- /* parse JSON path string */
4430- jsonpath = DirectFunctionCall1 (jsonpath_in ,
4431- CStringGetDatum (func -> common -> pathspec ));
4429+ pathspec = transformExprRecurse (pstate , func -> common -> pathspec );
44324430
4433- jsexpr -> path_spec = makeConst (JSONPATHOID , -1 , InvalidOid , -1 ,
4434- jsonpath , false, false);
4431+ jsexpr -> path_spec =
4432+ coerce_to_target_type (pstate , pathspec , exprType (pathspec ),
4433+ JSONPATHOID , -1 ,
4434+ COERCION_EXPLICIT , COERCE_IMPLICIT_CAST ,
4435+ exprLocation (pathspec ));
4436+ if (!jsexpr -> path_spec )
4437+ ereport (ERROR ,
4438+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
4439+ errmsg ("JSON path expression must be type %s, not type %s" ,
4440+ "jsonpath" , format_type_be (exprType (pathspec ))),
4441+ parser_errposition (pstate , exprLocation (pathspec ))));
44354442
44364443 /* transform and coerce to json[b] passing arguments */
44374444 transformJsonPassingArgs (pstate , format , func -> common -> passing ,
0 commit comments