Skip to content

Commit 785480c

Browse files
committed
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. Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/CA+HiwqE4XTdfb1nW=Ojoy_tQSRhYt-q_kb6i5d4xcKyrLC1Nbg@mail.gmail.com
1 parent c17164a commit 785480c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/backend/parser/parse_expr.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,8 +3222,8 @@ makeCaseTestExpr(Node *expr)
32223222
* default format otherwise.
32233223
*/
32243224
static Node *
3225-
transformJsonValueExpr(ParseState *pstate, JsonValueExpr *ve,
3226-
JsonFormatType default_format)
3225+
transformJsonValueExpr(ParseState *pstate, char *constructName,
3226+
JsonValueExpr *ve, JsonFormatType default_format)
32273227
{
32283228
Node *expr = transformExprRecurse(pstate, (Node *) ve->raw_expr);
32293229
Node *rawexpr;
@@ -3233,12 +3233,8 @@ transformJsonValueExpr(ParseState *pstate, JsonValueExpr *ve,
32333233
char typcategory;
32343234
bool typispreferred;
32353235

3236-
/*
3237-
* Using JSON_VALUE here is slightly bogus: perhaps we need to be passed a
3238-
* JsonConstructorType so that we can use one of JSON_OBJECTAGG, etc.
3239-
*/
32403236
if (exprType(expr) == UNKNOWNOID)
3241-
expr = coerce_to_specific_type(pstate, expr, TEXTOID, "JSON_VALUE");
3237+
expr = coerce_to_specific_type(pstate, expr, TEXTOID, constructName);
32423238

32433239
rawexpr = expr;
32443240
exprtype = exprType(expr);
@@ -3588,7 +3584,8 @@ transformJsonObjectConstructor(ParseState *pstate, JsonObjectConstructor *ctor)
35883584
{
35893585
JsonKeyValue *kv = castNode(JsonKeyValue, lfirst(lc));
35903586
Node *key = transformExprRecurse(pstate, (Node *) kv->key);
3591-
Node *val = transformJsonValueExpr(pstate, kv->value,
3587+
Node *val = transformJsonValueExpr(pstate, "JSON_OBJECT()",
3588+
kv->value,
35923589
JS_FORMAT_DEFAULT);
35933590

35943591
args = lappend(args, key);
@@ -3768,7 +3765,9 @@ transformJsonObjectAgg(ParseState *pstate, JsonObjectAgg *agg)
37683765
Oid aggtype;
37693766

37703767
key = transformExprRecurse(pstate, (Node *) agg->arg->key);
3771-
val = transformJsonValueExpr(pstate, agg->arg->value, JS_FORMAT_DEFAULT);
3768+
val = transformJsonValueExpr(pstate, "JSON_OBJECTAGG()",
3769+
agg->arg->value,
3770+
JS_FORMAT_DEFAULT);
37723771
args = list_make2(key, val);
37733772

37743773
returning = transformJsonConstructorOutput(pstate, agg->constructor->output,
@@ -3824,7 +3823,9 @@ transformJsonArrayAgg(ParseState *pstate, JsonArrayAgg *agg)
38243823
Oid aggfnoid;
38253824
Oid aggtype;
38263825

3827-
arg = transformJsonValueExpr(pstate, agg->arg, JS_FORMAT_DEFAULT);
3826+
arg = transformJsonValueExpr(pstate, "JSON_ARRAYAGG()",
3827+
agg->arg,
3828+
JS_FORMAT_DEFAULT);
38283829

38293830
returning = transformJsonConstructorOutput(pstate, agg->constructor->output,
38303831
list_make1(arg));
@@ -3870,7 +3871,8 @@ transformJsonArrayConstructor(ParseState *pstate, JsonArrayConstructor *ctor)
38703871
foreach(lc, ctor->exprs)
38713872
{
38723873
JsonValueExpr *jsval = castNode(JsonValueExpr, lfirst(lc));
3873-
Node *val = transformJsonValueExpr(pstate, jsval,
3874+
Node *val = transformJsonValueExpr(pstate, "JSON_ARRAY()",
3875+
jsval,
38743876
JS_FORMAT_DEFAULT);
38753877

38763878
args = lappend(args, val);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy