aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_expr.c
diff options
context:
space:
mode:
authorAmit Langote <amitlan@postgresql.org>2023-07-21 19:15:34 +0900
committerAmit Langote <amitlan@postgresql.org>2023-07-21 19:15:34 +0900
commit7c7412cae3ea8f8accdec1022969a9360b74f253 (patch)
tree1ce80497cc5adbe9a33723740a296de929000664 /src/backend/parser/parse_expr.c
parent97ff8dd02ca788020021cdafb85d77d4fd3f3125 (diff)
downloadpostgresql-7c7412cae3ea8f8accdec1022969a9360b74f253.tar.gz
postgresql-7c7412cae3ea8f8accdec1022969a9360b74f253.zip
Code review for commit b6e1157e7d
b6e1157e7d made some changes to enforce that JsonValueExpr.formatted_expr is always set and is the expression that gives a JsonValueExpr its runtime value, but that's not really apparent from the comments about and the code manipulating formatted_expr. This commit fixes that. Per suggestion from Álvaro Herrera. Discussion: https://postgr.es/m/20230718155313.3wqg6encgt32adqb%40alvherre.pgsql
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r--src/backend/parser/parse_expr.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 5a05caa8744..c08c06373a9 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -3205,6 +3205,10 @@ makeJsonByteaToTextConversion(Node *expr, JsonFormat *format, int location)
/*
* Transform JSON value expression using specified input JSON format or
* default format otherwise.
+ *
+ * Returned expression is either ve->raw_expr coerced to text (if needed) or
+ * a JsonValueExpr with formatted_expr set to the coerced copy of raw_expr
+ * if the specified format requires it.
*/
static Node *
transformJsonValueExpr(ParseState *pstate, const char *constructName,
@@ -3304,6 +3308,10 @@ transformJsonValueExpr(ParseState *pstate, const char *constructName,
}
}
+ /* If returning a JsonValueExpr, formatted_expr must have been set. */
+ Assert(!IsA(expr, JsonValueExpr) ||
+ ((JsonValueExpr *) expr)->formatted_expr != NULL);
+
return expr;
}
@@ -3631,13 +3639,12 @@ transformJsonArrayQueryConstructor(ParseState *pstate,
makeString(pstrdup("a")));
colref->location = ctor->location;
- agg->arg = makeJsonValueExpr((Expr *) colref, ctor->format);
-
/*
* No formatting necessary, so set formatted_expr to be the same as
* raw_expr.
*/
- agg->arg->formatted_expr = agg->arg->raw_expr;
+ agg->arg = makeJsonValueExpr((Expr *) colref, (Expr *) colref,
+ ctor->format);
agg->absent_on_null = ctor->absent_on_null;
agg->constructor = makeNode(JsonAggConstructor);
agg->constructor->agg_order = NIL;
@@ -3906,9 +3913,7 @@ transformJsonParseArg(ParseState *pstate, Node *jsexpr, JsonFormat *format,
expr = makeJsonByteaToTextConversion(expr, format, exprLocation(expr));
*exprtype = TEXTOID;
- jve = makeJsonValueExpr((Expr *) raw_expr, format);
-
- jve->formatted_expr = (Expr *) expr;
+ jve = makeJsonValueExpr((Expr *) raw_expr, (Expr *) expr, format);
expr = (Node *) jve;
}
else