@@ -4535,7 +4535,7 @@ static JsonExpr *
4535
4535
transformJsonExprCommon (ParseState * pstate , JsonFuncExpr * func )
4536
4536
{
4537
4537
JsonExpr * jsexpr = makeNode (JsonExpr );
4538
- Datum jsonpath ;
4538
+ Node * pathspec ;
4539
4539
JsonFormatType format ;
4540
4540
4541
4541
if (func -> common -> pathname )
@@ -4566,12 +4566,19 @@ transformJsonExprCommon(ParseState *pstate, JsonFuncExpr *func)
4566
4566
4567
4567
jsexpr -> format = func -> common -> expr -> format ;
4568
4568
4569
- /* parse JSON path string */
4570
- jsonpath = DirectFunctionCall1 (jsonpath_in ,
4571
- CStringGetDatum (func -> common -> pathspec ));
4569
+ pathspec = transformExprRecurse (pstate , func -> common -> pathspec );
4572
4570
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 ))));
4575
4582
4576
4583
/* transform and coerce to json[b] passing arguments */
4577
4584
transformJsonPassingArgs (pstate , format , func -> common -> passing ,
0 commit comments