mirror of
https://github.com/postgres/postgres.git
synced 2025-06-27 23:21:58 +03:00
Simplify transformJsonAggConstructor() API
There's no need for callers to pass aggregate names so that the function can resolve them to OIDs, when callers can just pass aggregate OIDs directly to begin with.
This commit is contained in:
@ -3611,11 +3611,10 @@ transformJsonArrayQueryConstructor(ParseState *pstate,
|
|||||||
static Node *
|
static Node *
|
||||||
transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
|
transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
|
||||||
JsonReturning *returning, List *args,
|
JsonReturning *returning, List *args,
|
||||||
const char *aggfn, Oid aggtype,
|
Oid aggfnoid, Oid aggtype,
|
||||||
JsonConstructorType ctor_type,
|
JsonConstructorType ctor_type,
|
||||||
bool unique, bool absent_on_null)
|
bool unique, bool absent_on_null)
|
||||||
{
|
{
|
||||||
Oid aggfnoid;
|
|
||||||
Node *node;
|
Node *node;
|
||||||
Expr *aggfilter;
|
Expr *aggfilter;
|
||||||
|
|
||||||
@ -3623,9 +3622,6 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
|
|||||||
transformWhereClause(pstate, agg_ctor->agg_filter,
|
transformWhereClause(pstate, agg_ctor->agg_filter,
|
||||||
EXPR_KIND_FILTER, "FILTER") : NULL;
|
EXPR_KIND_FILTER, "FILTER") : NULL;
|
||||||
|
|
||||||
aggfnoid = DatumGetInt32(DirectFunctionCall1(regprocin,
|
|
||||||
CStringGetDatum(aggfn)));
|
|
||||||
|
|
||||||
if (agg_ctor->over)
|
if (agg_ctor->over)
|
||||||
{
|
{
|
||||||
/* window function */
|
/* window function */
|
||||||
@ -3703,7 +3699,7 @@ transformJsonObjectAgg(ParseState *pstate, JsonObjectAgg *agg)
|
|||||||
Node *key;
|
Node *key;
|
||||||
Node *val;
|
Node *val;
|
||||||
List *args;
|
List *args;
|
||||||
const char *aggfnname;
|
Oid aggfnoid;
|
||||||
Oid aggtype;
|
Oid aggtype;
|
||||||
|
|
||||||
key = transformExprRecurse(pstate, (Node *) agg->arg->key);
|
key = transformExprRecurse(pstate, (Node *) agg->arg->key);
|
||||||
@ -3717,13 +3713,13 @@ transformJsonObjectAgg(ParseState *pstate, JsonObjectAgg *agg)
|
|||||||
{
|
{
|
||||||
if (agg->absent_on_null)
|
if (agg->absent_on_null)
|
||||||
if (agg->unique)
|
if (agg->unique)
|
||||||
aggfnname = "pg_catalog.jsonb_object_agg_unique_strict";
|
aggfnoid = F_JSONB_OBJECT_AGG_UNIQUE_STRICT;
|
||||||
else
|
else
|
||||||
aggfnname = "pg_catalog.jsonb_object_agg_strict";
|
aggfnoid = F_JSONB_OBJECT_AGG_STRICT;
|
||||||
else if (agg->unique)
|
else if (agg->unique)
|
||||||
aggfnname = "pg_catalog.jsonb_object_agg_unique";
|
aggfnoid = F_JSONB_OBJECT_AGG_UNIQUE;
|
||||||
else
|
else
|
||||||
aggfnname = "pg_catalog.jsonb_object_agg";
|
aggfnoid = F_JSONB_OBJECT_AGG;
|
||||||
|
|
||||||
aggtype = JSONBOID;
|
aggtype = JSONBOID;
|
||||||
}
|
}
|
||||||
@ -3731,19 +3727,19 @@ transformJsonObjectAgg(ParseState *pstate, JsonObjectAgg *agg)
|
|||||||
{
|
{
|
||||||
if (agg->absent_on_null)
|
if (agg->absent_on_null)
|
||||||
if (agg->unique)
|
if (agg->unique)
|
||||||
aggfnname = "pg_catalog.json_object_agg_unique_strict";
|
aggfnoid = F_JSON_OBJECT_AGG_UNIQUE_STRICT;
|
||||||
else
|
else
|
||||||
aggfnname = "pg_catalog.json_object_agg_strict";
|
aggfnoid = F_JSON_OBJECT_AGG_STRICT;
|
||||||
else if (agg->unique)
|
else if (agg->unique)
|
||||||
aggfnname = "pg_catalog.json_object_agg_unique";
|
aggfnoid = F_JSON_OBJECT_AGG_UNIQUE;
|
||||||
else
|
else
|
||||||
aggfnname = "pg_catalog.json_object_agg";
|
aggfnoid = F_JSON_OBJECT_AGG;
|
||||||
|
|
||||||
aggtype = JSONOID;
|
aggtype = JSONOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
return transformJsonAggConstructor(pstate, agg->constructor, returning,
|
return transformJsonAggConstructor(pstate, agg->constructor, returning,
|
||||||
args, aggfnname, aggtype,
|
args, aggfnoid, aggtype,
|
||||||
JSCTOR_JSON_OBJECTAGG,
|
JSCTOR_JSON_OBJECTAGG,
|
||||||
agg->unique, agg->absent_on_null);
|
agg->unique, agg->absent_on_null);
|
||||||
}
|
}
|
||||||
@ -3760,7 +3756,7 @@ transformJsonArrayAgg(ParseState *pstate, JsonArrayAgg *agg)
|
|||||||
{
|
{
|
||||||
JsonReturning *returning;
|
JsonReturning *returning;
|
||||||
Node *arg;
|
Node *arg;
|
||||||
const char *aggfnname;
|
Oid aggfnoid;
|
||||||
Oid aggtype;
|
Oid aggtype;
|
||||||
|
|
||||||
arg = transformJsonValueExpr(pstate, agg->arg, JS_FORMAT_DEFAULT);
|
arg = transformJsonValueExpr(pstate, agg->arg, JS_FORMAT_DEFAULT);
|
||||||
@ -3770,19 +3766,17 @@ transformJsonArrayAgg(ParseState *pstate, JsonArrayAgg *agg)
|
|||||||
|
|
||||||
if (returning->format->format_type == JS_FORMAT_JSONB)
|
if (returning->format->format_type == JS_FORMAT_JSONB)
|
||||||
{
|
{
|
||||||
aggfnname = agg->absent_on_null ?
|
aggfnoid = agg->absent_on_null ? F_JSONB_AGG_STRICT : F_JSONB_AGG;
|
||||||
"pg_catalog.jsonb_agg_strict" : "pg_catalog.jsonb_agg";
|
|
||||||
aggtype = JSONBOID;
|
aggtype = JSONBOID;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
aggfnname = agg->absent_on_null ?
|
aggfnoid = agg->absent_on_null ? F_JSON_AGG_STRICT : F_JSON_AGG;
|
||||||
"pg_catalog.json_agg_strict" : "pg_catalog.json_agg";
|
|
||||||
aggtype = JSONOID;
|
aggtype = JSONOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
return transformJsonAggConstructor(pstate, agg->constructor, returning,
|
return transformJsonAggConstructor(pstate, agg->constructor, returning,
|
||||||
list_make1(arg), aggfnname, aggtype,
|
list_make1(arg), aggfnoid, aggtype,
|
||||||
JSCTOR_JSON_ARRAYAGG,
|
JSCTOR_JSON_ARRAYAGG,
|
||||||
false, agg->absent_on_null);
|
false, agg->absent_on_null);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user