ExecInitJsonExpr_minor_refactor.nocfbot

application/octet-stream

Filename: ExecInitJsonExpr_minor_refactor.nocfbot
Type: application/octet-stream
Part: 0
Message: Re: remaining sql/json patches
diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c
index cfbd9272..7208bffd 100644
--- a/src/backend/executor/execExpr.c
+++ b/src/backend/executor/execExpr.c
@@ -4314,18 +4314,22 @@ ExecInitJsonExpr(JsonExpr *jexpr, ExprState *state,
 								 jexpr->result_coercion,
 								 jexpr->on_error->btype == JSON_BEHAVIOR_ERROR,
 								 resv, resnull);
-
 		/*
-		 * Step to jump to the EEOP_JSONEXPR_FINISH step skipping over item
-		 * coercion steps that will be added below, if any.
-		 */
-		if (jexpr->item_coercions)
+		* Set information for RETURNING type's input function used by
+		* ExecEvalJsonExprCoercion().
+		*/
+		if (jexpr->omit_quotes ||
+			(jexpr->result_coercion && jexpr->result_coercion->via_io))
 		{
-			jumps_to_coerce_finish = lappend_int(jumps_to_coerce_finish,
-												 state->steps_len);
-			scratch->opcode = EEOP_JUMP;
-			scratch->d.jump.jumpdone = -1;	/* computed later */
-			ExprEvalPushStep(state, scratch);
+			Oid			typinput;
+			FmgrInfo   *finfo;
+
+			/* lookup the result type's input function */
+			getTypeInputInfo(jexpr->returning->typid, &typinput,
+							&jsestate->input.typioparam);
+			finfo = palloc0(sizeof(FmgrInfo));
+			fmgr_info(typinput, finfo);
+			jsestate->input.finfo = finfo;
 		}
 	}
 	else
@@ -4334,6 +4338,16 @@ ExecInitJsonExpr(JsonExpr *jexpr, ExprState *state,
 	/* Steps for coercions of JsonItemType values for JSON_VALUE_OP. */
 	if (jexpr->item_coercions)
 	{
+		/*
+		 * Step to jump to the EEOP_JSONEXPR_FINISH step skipping over item
+		 * coercion steps that will be added below, if any.
+		 */
+		jumps_to_coerce_finish = lappend_int(jumps_to_coerce_finish,
+												state->steps_len);
+		scratch->opcode = EEOP_JUMP;
+		scratch->d.jump.jumpdone = -1;	/* computed later */
+		ExprEvalPushStep(state, scratch);
+
 		if (coercion_step_off < 0)
 			coercion_step_off = state->steps_len;
 
@@ -4567,24 +4581,6 @@ ExecInitJsonExpr(JsonExpr *jexpr, ExprState *state,
 		as = &state->steps[lfirst_int(lc)];
 		as->d.jump.jumpdone = state->steps_len;
 	}
-
-	/*
-	 * Set information for RETURNING type's input function used by
-	 * ExecEvalJsonExprCoercion().
-	 */
-	if (jexpr->omit_quotes ||
-		(jexpr->result_coercion && jexpr->result_coercion->via_io))
-	{
-		Oid			typinput;
-		FmgrInfo   *finfo;
-
-		/* lookup the result type's input function */
-		getTypeInputInfo(jexpr->returning->typid, &typinput,
-						 &jsestate->input.typioparam);
-		finfo = palloc0(sizeof(FmgrInfo));
-		fmgr_info(typinput, finfo);
-		jsestate->input.finfo = finfo;
-	}
 }
 
 /*
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 6c8918c6..39e0944a 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -4346,9 +4346,10 @@ transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
 			 * Initialize JsonCoercion nodes to coerce the scalar value
 			 * returned by JsonPathValue() to the "returning" type.
 			 */
-			jsexpr->item_coercions =
-				InitJsonItemCoercions(pstate, jsexpr->returning,
-									  exprType(jsexpr->formatted_expr));
+			if (jsexpr->result_coercion)
+				jsexpr->item_coercions =
+					InitJsonItemCoercions(pstate, jsexpr->returning,
+										exprType(jsexpr->formatted_expr));
 
 			jsexpr->on_empty = transformJsonBehavior(pstate, on_empty,
 													 JSON_BEHAVIOR_NULL,