aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_expr.c
diff options
context:
space:
mode:
authorAmit Langote <amitlan@postgresql.org>2023-07-20 16:23:49 +0900
committerAmit Langote <amitlan@postgresql.org>2023-07-20 17:15:15 +0900
commit7825a1b01e400434835253b4ff38dd96d823d454 (patch)
tree0622be07bce24988ed4ff61216908fa76c870bdb /src/backend/parser/parse_expr.c
parent0a1d2a7df852f16c452eef8a83003943125162c7 (diff)
downloadpostgresql-7825a1b01e400434835253b4ff38dd96d823d454.tar.gz
postgresql-7825a1b01e400434835253b4ff38dd96d823d454.zip
Pass constructName to transformJsonValueExpr()
This allows it to pass to coerce_to_specific_type() the actual name corresponding to the specific JSON_* function expression being transformed, instead of the currently hardcoded string. Backpatched to 16 from the development branch to keep the code in sync across branches. Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/CA+HiwqHu58pO3cJ7rB6ZLwUztVdG1J66xSjDdjfan5uT5NhESw@mail.gmail.com
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r--src/backend/parser/parse_expr.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 346fd272b6d..286e85d7261 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -3222,8 +3222,8 @@ makeCaseTestExpr(Node *expr)
* default format otherwise.
*/
static Node *
-transformJsonValueExpr(ParseState *pstate, JsonValueExpr *ve,
- JsonFormatType default_format)
+transformJsonValueExpr(ParseState *pstate, const char *constructName,
+ JsonValueExpr *ve, JsonFormatType default_format)
{
Node *expr = transformExprRecurse(pstate, (Node *) ve->raw_expr);
Node *rawexpr;
@@ -3233,12 +3233,8 @@ transformJsonValueExpr(ParseState *pstate, JsonValueExpr *ve,
char typcategory;
bool typispreferred;
- /*
- * Using JSON_VALUE here is slightly bogus: perhaps we need to be passed a
- * JsonConstructorType so that we can use one of JSON_OBJECTAGG, etc.
- */
if (exprType(expr) == UNKNOWNOID)
- expr = coerce_to_specific_type(pstate, expr, TEXTOID, "JSON_VALUE");
+ expr = coerce_to_specific_type(pstate, expr, TEXTOID, constructName);
rawexpr = expr;
exprtype = exprType(expr);
@@ -3588,7 +3584,8 @@ transformJsonObjectConstructor(ParseState *pstate, JsonObjectConstructor *ctor)
{
JsonKeyValue *kv = castNode(JsonKeyValue, lfirst(lc));
Node *key = transformExprRecurse(pstate, (Node *) kv->key);
- Node *val = transformJsonValueExpr(pstate, kv->value,
+ Node *val = transformJsonValueExpr(pstate, "JSON_OBJECT()",
+ kv->value,
JS_FORMAT_DEFAULT);
args = lappend(args, key);
@@ -3768,7 +3765,9 @@ transformJsonObjectAgg(ParseState *pstate, JsonObjectAgg *agg)
Oid aggtype;
key = transformExprRecurse(pstate, (Node *) agg->arg->key);
- val = transformJsonValueExpr(pstate, agg->arg->value, JS_FORMAT_DEFAULT);
+ val = transformJsonValueExpr(pstate, "JSON_OBJECTAGG()",
+ agg->arg->value,
+ JS_FORMAT_DEFAULT);
args = list_make2(key, val);
returning = transformJsonConstructorOutput(pstate, agg->constructor->output,
@@ -3824,7 +3823,9 @@ transformJsonArrayAgg(ParseState *pstate, JsonArrayAgg *agg)
Oid aggfnoid;
Oid aggtype;
- arg = transformJsonValueExpr(pstate, agg->arg, JS_FORMAT_DEFAULT);
+ arg = transformJsonValueExpr(pstate, "JSON_ARRAYAGG()",
+ agg->arg,
+ JS_FORMAT_DEFAULT);
returning = transformJsonConstructorOutput(pstate, agg->constructor->output,
list_make1(arg));
@@ -3870,7 +3871,8 @@ transformJsonArrayConstructor(ParseState *pstate, JsonArrayConstructor *ctor)
foreach(lc, ctor->exprs)
{
JsonValueExpr *jsval = castNode(JsonValueExpr, lfirst(lc));
- Node *val = transformJsonValueExpr(pstate, jsval,
+ Node *val = transformJsonValueExpr(pstate, "JSON_ARRAY()",
+ jsval,
JS_FORMAT_DEFAULT);
args = lappend(args, val);