From 1de5a1fab5de6447936f062cfa9231c8890f9721 Mon Sep 17 00:00:00 2001 From: jian he Date: Tue, 23 Jan 2024 16:31:12 +0800 Subject: [PATCH v1 1/1] minor refactor transformJsonFuncExpr JSON_VALUE by default is omit_quote, however transformJsonExprCommon will initialize it to false via 'makeNode(JsonExpr)'. So set it explicitly. no need to set jsexpr->result_coercion at transformJsonExprCommon, since makeNode will make jsexpr->result_coercion be NULL; Accordingly, we also need refactor function coerceJsonFuncExprOutput. make JSON_VALUE result_coercion via CaseTestExpr. --- src/backend/parser/parse_expr.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index b1908c36..3f03aef0 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -4358,6 +4358,7 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func) jsexpr->returning->typid = TEXTOID; jsexpr->returning->typmod = -1; } + jsexpr->omit_quotes = true; jsexpr->result_coercion = coerceJsonFuncExprOutput(pstate, jsexpr); /* @@ -4426,10 +4427,6 @@ transformJsonExprCommon(ParseState *pstate, JsonFuncExpr *func, jsexpr->format = func->context_item->format; - /* Both set in the caller. */ - jsexpr->result_coercion = NULL; - jsexpr->omit_quotes = false; - pathspec = transformExprRecurse(pstate, func->pathspec); jsexpr->path_spec = @@ -4510,7 +4507,8 @@ coerceJsonFuncExprOutput(ParseState *pstate, JsonExpr *jsexpr) * Use a JsonCoercion node to implement a non-default QUOTES or WRAPPER * behavior. */ - if (jsexpr->omit_quotes || jsexpr->wrapper != JSW_UNSPEC) + if (jsexpr->op == JSON_QUERY_OP && + (jsexpr->omit_quotes || jsexpr->wrapper != JSW_UNSPEC)) { JsonCoercion *coercion = makeJsonCoercion(returning); -- 2.34.1