PostgreSQL Source Code git master
parse_agg.h File Reference
Include dependency graph for parse_agg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void transformAggregateCall (ParseState *pstate, Aggref *agg, List *args, List *aggorder, bool agg_distinct)
 
NodetransformGroupingFunc (ParseState *pstate, GroupingFunc *p)
 
void transformWindowFuncCall (ParseState *pstate, WindowFunc *wfunc, WindowDef *windef)
 
void parseCheckAggregates (ParseState *pstate, Query *qry)
 
Listexpand_grouping_sets (List *groupingSets, bool groupDistinct, int limit)
 
int get_aggregate_argtypes (Aggref *aggref, Oid *inputTypes)
 
Oid resolve_aggregate_transtype (Oid aggfuncid, Oid aggtranstype, Oid *inputTypes, int numArguments)
 
bool agg_args_support_sendreceive (Aggref *aggref)
 
void build_aggregate_transfn_expr (Oid *agg_input_types, int agg_num_inputs, int agg_num_direct_inputs, bool agg_variadic, Oid agg_state_type, Oid agg_input_collation, Oid transfn_oid, Oid invtransfn_oid, Expr **transfnexpr, Expr **invtransfnexpr)
 
void build_aggregate_serialfn_expr (Oid serialfn_oid, Expr **serialfnexpr)
 
void build_aggregate_deserialfn_expr (Oid deserialfn_oid, Expr **deserialfnexpr)
 
void build_aggregate_finalfn_expr (Oid *agg_input_types, int num_finalfn_inputs, Oid agg_state_type, Oid agg_result_type, Oid agg_input_collation, Oid finalfn_oid, Expr **finalfnexpr)
 

Function Documentation

◆ agg_args_support_sendreceive()

bool agg_args_support_sendreceive ( Aggref aggref)

Definition at line 2112 of file parse_agg.c.

2113{
2114 ListCell *lc;
2115
2116 foreach(lc, aggref->args)
2117 {
2118 HeapTuple typeTuple;
2119 Form_pg_type pt;
2120 TargetEntry *tle = (TargetEntry *) lfirst(lc);
2121 Oid type = exprType((Node *) tle->expr);
2122
2123 /*
2124 * RECORD is a special case: it has typsend/typreceive functions, but
2125 * record_recv only works if passed the correct typmod to identify the
2126 * specific anonymous record type. array_agg_deserialize cannot do
2127 * that, so we have to disclaim support for the case.
2128 */
2129 if (type == RECORDOID)
2130 return false;
2131
2132 typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type));
2133 if (!HeapTupleIsValid(typeTuple))
2134 elog(ERROR, "cache lookup failed for type %u", type);
2135
2136 pt = (Form_pg_type) GETSTRUCT(typeTuple);
2137
2138 if (!pt->typbyval &&
2139 (!OidIsValid(pt->typsend) || !OidIsValid(pt->typreceive)))
2140 {
2141 ReleaseSysCache(typeTuple);
2142 return false;
2143 }
2144 ReleaseSysCache(typeTuple);
2145 }
2146 return true;
2147}
#define OidIsValid(objectId)
Definition: c.h:777
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
#define lfirst(lc)
Definition: pg_list.h:172
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
unsigned int Oid
Definition: postgres_ext.h:32
List * args
Definition: primnodes.h:487
Definition: nodes.h:135
Expr * expr
Definition: primnodes.h:2239
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:220
const char * type

References Aggref::args, elog, ERROR, TargetEntry::expr, exprType(), GETSTRUCT(), HeapTupleIsValid, lfirst, ObjectIdGetDatum(), OidIsValid, ReleaseSysCache(), SearchSysCache1(), and type.

Referenced by preprocess_aggref().

◆ build_aggregate_deserialfn_expr()

void build_aggregate_deserialfn_expr ( Oid  deserialfn_oid,
Expr **  deserialfnexpr 
)

Definition at line 2263 of file parse_agg.c.

2265{
2266 List *args;
2267 FuncExpr *fexpr;
2268
2269 /* deserialfn always takes BYTEA, INTERNAL and returns INTERNAL */
2271 make_agg_arg(INTERNALOID, InvalidOid));
2272
2273 fexpr = makeFuncExpr(deserialfn_oid,
2274 INTERNALOID,
2275 args,
2276 InvalidOid,
2277 InvalidOid,
2279 *deserialfnexpr = (Expr *) fexpr;
2280}
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
Definition: makefuncs.c:594
static Node * make_agg_arg(Oid argtype, Oid argcollation)
Definition: parse_agg.c:2327
#define list_make2(x1, x2)
Definition: pg_list.h:214
#define InvalidOid
Definition: postgres_ext.h:37
@ COERCE_EXPLICIT_CALL
Definition: primnodes.h:766
Definition: pg_list.h:54

References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, InvalidOid, list_make2, make_agg_arg(), and makeFuncExpr().

Referenced by build_pertrans_for_aggref().

◆ build_aggregate_finalfn_expr()

void build_aggregate_finalfn_expr ( Oid agg_input_types,
int  num_finalfn_inputs,
Oid  agg_state_type,
Oid  agg_result_type,
Oid  agg_input_collation,
Oid  finalfn_oid,
Expr **  finalfnexpr 
)

Definition at line 2287 of file parse_agg.c.

2294{
2295 List *args;
2296 int i;
2297
2298 /*
2299 * Build expr tree for final function
2300 */
2301 args = list_make1(make_agg_arg(agg_state_type, agg_input_collation));
2302
2303 /* finalfn may take additional args, which match agg's input types */
2304 for (i = 0; i < num_finalfn_inputs - 1; i++)
2305 {
2306 args = lappend(args,
2307 make_agg_arg(agg_input_types[i], agg_input_collation));
2308 }
2309
2310 *finalfnexpr = (Expr *) makeFuncExpr(finalfn_oid,
2311 agg_result_type,
2312 args,
2313 InvalidOid,
2314 agg_input_collation,
2316 /* finalfn is currently never treated as variadic */
2317}
int i
Definition: isn.c:77
List * lappend(List *list, void *datum)
Definition: list.c:339
#define list_make1(x1)
Definition: pg_list.h:212

References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, i, InvalidOid, lappend(), list_make1, make_agg_arg(), and makeFuncExpr().

Referenced by ExecInitAgg(), and initialize_peragg().

◆ build_aggregate_serialfn_expr()

void build_aggregate_serialfn_expr ( Oid  serialfn_oid,
Expr **  serialfnexpr 
)

Definition at line 2240 of file parse_agg.c.

2242{
2243 List *args;
2244 FuncExpr *fexpr;
2245
2246 /* serialfn always takes INTERNAL and returns BYTEA */
2247 args = list_make1(make_agg_arg(INTERNALOID, InvalidOid));
2248
2249 fexpr = makeFuncExpr(serialfn_oid,
2250 BYTEAOID,
2251 args,
2252 InvalidOid,
2253 InvalidOid,
2255 *serialfnexpr = (Expr *) fexpr;
2256}

References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, InvalidOid, list_make1, make_agg_arg(), and makeFuncExpr().

Referenced by build_pertrans_for_aggref().

◆ build_aggregate_transfn_expr()

void build_aggregate_transfn_expr ( Oid agg_input_types,
int  agg_num_inputs,
int  agg_num_direct_inputs,
bool  agg_variadic,
Oid  agg_state_type,
Oid  agg_input_collation,
Oid  transfn_oid,
Oid  invtransfn_oid,
Expr **  transfnexpr,
Expr **  invtransfnexpr 
)

Definition at line 2179 of file parse_agg.c.

2189{
2190 List *args;
2191 FuncExpr *fexpr;
2192 int i;
2193
2194 /*
2195 * Build arg list to use in the transfn FuncExpr node.
2196 */
2197 args = list_make1(make_agg_arg(agg_state_type, agg_input_collation));
2198
2199 for (i = agg_num_direct_inputs; i < agg_num_inputs; i++)
2200 {
2201 args = lappend(args,
2202 make_agg_arg(agg_input_types[i], agg_input_collation));
2203 }
2204
2205 fexpr = makeFuncExpr(transfn_oid,
2206 agg_state_type,
2207 args,
2208 InvalidOid,
2209 agg_input_collation,
2211 fexpr->funcvariadic = agg_variadic;
2212 *transfnexpr = (Expr *) fexpr;
2213
2214 /*
2215 * Build invtransfn expression if requested, with same args as transfn
2216 */
2217 if (invtransfnexpr != NULL)
2218 {
2219 if (OidIsValid(invtransfn_oid))
2220 {
2221 fexpr = makeFuncExpr(invtransfn_oid,
2222 agg_state_type,
2223 args,
2224 InvalidOid,
2225 agg_input_collation,
2227 fexpr->funcvariadic = agg_variadic;
2228 *invtransfnexpr = (Expr *) fexpr;
2229 }
2230 else
2231 *invtransfnexpr = NULL;
2232 }
2233}

References generate_unaccent_rules::args, COERCE_EXPLICIT_CALL, i, InvalidOid, lappend(), list_make1, make_agg_arg(), makeFuncExpr(), and OidIsValid.

Referenced by build_pertrans_for_aggref(), and initialize_peragg().

◆ expand_grouping_sets()

List * expand_grouping_sets ( List groupingSets,
bool  groupDistinct,
int  limit 
)

Definition at line 1947 of file parse_agg.c.

1948{
1949 List *expanded_groups = NIL;
1950 List *result = NIL;
1951 double numsets = 1;
1952 ListCell *lc;
1953
1954 if (groupingSets == NIL)
1955 return NIL;
1956
1957 foreach(lc, groupingSets)
1958 {
1959 List *current_result = NIL;
1960 GroupingSet *gs = lfirst(lc);
1961
1962 current_result = expand_groupingset_node(gs);
1963
1964 Assert(current_result != NIL);
1965
1966 numsets *= list_length(current_result);
1967
1968 if (limit >= 0 && numsets > limit)
1969 return NIL;
1970
1971 expanded_groups = lappend(expanded_groups, current_result);
1972 }
1973
1974 /*
1975 * Do cartesian product between sublists of expanded_groups. While at it,
1976 * remove any duplicate elements from individual grouping sets (we must
1977 * NOT change the number of sets though)
1978 */
1979
1980 foreach(lc, (List *) linitial(expanded_groups))
1981 {
1982 result = lappend(result, list_union_int(NIL, (List *) lfirst(lc)));
1983 }
1984
1985 for_each_from(lc, expanded_groups, 1)
1986 {
1987 List *p = lfirst(lc);
1988 List *new_result = NIL;
1989 ListCell *lc2;
1990
1991 foreach(lc2, result)
1992 {
1993 List *q = lfirst(lc2);
1994 ListCell *lc3;
1995
1996 foreach(lc3, p)
1997 {
1998 new_result = lappend(new_result,
1999 list_union_int(q, (List *) lfirst(lc3)));
2000 }
2001 }
2002 result = new_result;
2003 }
2004
2005 /* Now sort the lists by length and deduplicate if necessary */
2006 if (!groupDistinct || list_length(result) < 2)
2007 list_sort(result, cmp_list_len_asc);
2008 else
2009 {
2010 ListCell *cell;
2011 List *prev;
2012
2013 /* Sort each groupset individually */
2014 foreach(cell, result)
2016
2017 /* Now sort the list of groupsets by length and contents */
2019
2020 /* Finally, remove duplicates */
2021 prev = linitial(result);
2022 for_each_from(cell, result, 1)
2023 {
2024 if (equal(lfirst(cell), prev))
2025 result = foreach_delete_current(result, cell);
2026 else
2027 prev = lfirst(cell);
2028 }
2029 }
2030
2031 return result;
2032}
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
Assert(PointerIsAligned(start, uint64))
void list_sort(List *list, list_sort_comparator cmp)
Definition: list.c:1674
int list_int_cmp(const ListCell *p1, const ListCell *p2)
Definition: list.c:1691
List * list_union_int(const List *list1, const List *list2)
Definition: list.c:1113
static int cmp_list_len_asc(const ListCell *a, const ListCell *b)
Definition: parse_agg.c:1903
static int cmp_list_len_contents_asc(const ListCell *a, const ListCell *b)
Definition: parse_agg.c:1913
static List * expand_groupingset_node(GroupingSet *gs)
Definition: parse_agg.c:1801
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define foreach_delete_current(lst, var_or_cell)
Definition: pg_list.h:391
#define for_each_from(cell, lst, N)
Definition: pg_list.h:414
#define linitial(l)
Definition: pg_list.h:178

References Assert(), cmp_list_len_asc(), cmp_list_len_contents_asc(), equal(), expand_groupingset_node(), for_each_from, foreach_delete_current, lappend(), lfirst, linitial, list_int_cmp(), list_length(), list_sort(), list_union_int(), and NIL.

Referenced by parseCheckAggregates(), and subquery_planner().

◆ get_aggregate_argtypes()

int get_aggregate_argtypes ( Aggref aggref,
Oid inputTypes 
)

Definition at line 2050 of file parse_agg.c.

2051{
2052 int numArguments = 0;
2053 ListCell *lc;
2054
2055 Assert(list_length(aggref->aggargtypes) <= FUNC_MAX_ARGS);
2056
2057 foreach(lc, aggref->aggargtypes)
2058 {
2059 inputTypes[numArguments++] = lfirst_oid(lc);
2060 }
2061
2062 return numArguments;
2063}
#define FUNC_MAX_ARGS
#define lfirst_oid(lc)
Definition: pg_list.h:174

References Assert(), FUNC_MAX_ARGS, lfirst_oid, and list_length().

Referenced by ExecInitAgg(), get_agg_expr_helper(), and preprocess_aggref().

◆ parseCheckAggregates()

void parseCheckAggregates ( ParseState pstate,
Query qry 
)

Definition at line 1138 of file parse_agg.c.

1139{
1140 List *gset_common = NIL;
1141 List *groupClauses = NIL;
1142 List *groupClauseCommonVars = NIL;
1143 bool have_non_var_grouping;
1144 List *func_grouped_rels = NIL;
1145 ListCell *l;
1146 bool hasJoinRTEs;
1147 bool hasSelfRefRTEs;
1148 Node *clause;
1149
1150 /* This should only be called if we found aggregates or grouping */
1151 Assert(pstate->p_hasAggs || qry->groupClause || qry->havingQual || qry->groupingSets);
1152
1153 /*
1154 * If we have grouping sets, expand them and find the intersection of all
1155 * sets.
1156 */
1157 if (qry->groupingSets)
1158 {
1159 /*
1160 * The limit of 4096 is arbitrary and exists simply to avoid resource
1161 * issues from pathological constructs.
1162 */
1163 List *gsets = expand_grouping_sets(qry->groupingSets, qry->groupDistinct, 4096);
1164
1165 if (!gsets)
1166 ereport(ERROR,
1167 (errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
1168 errmsg("too many grouping sets present (maximum 4096)"),
1169 parser_errposition(pstate,
1170 qry->groupClause
1171 ? exprLocation((Node *) qry->groupClause)
1172 : exprLocation((Node *) qry->groupingSets))));
1173
1174 /*
1175 * The intersection will often be empty, so help things along by
1176 * seeding the intersect with the smallest set.
1177 */
1178 gset_common = linitial(gsets);
1179
1180 if (gset_common)
1181 {
1182 for_each_from(l, gsets, 1)
1183 {
1184 gset_common = list_intersection_int(gset_common, lfirst(l));
1185 if (!gset_common)
1186 break;
1187 }
1188 }
1189
1190 /*
1191 * If there was only one grouping set in the expansion, AND if the
1192 * groupClause is non-empty (meaning that the grouping set is not
1193 * empty either), then we can ditch the grouping set and pretend we
1194 * just had a normal GROUP BY.
1195 */
1196 if (list_length(gsets) == 1 && qry->groupClause)
1197 qry->groupingSets = NIL;
1198 }
1199
1200 /*
1201 * Scan the range table to see if there are JOIN or self-reference CTE
1202 * entries. We'll need this info below.
1203 */
1204 hasJoinRTEs = hasSelfRefRTEs = false;
1205 foreach(l, pstate->p_rtable)
1206 {
1207 RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
1208
1209 if (rte->rtekind == RTE_JOIN)
1210 hasJoinRTEs = true;
1211 else if (rte->rtekind == RTE_CTE && rte->self_reference)
1212 hasSelfRefRTEs = true;
1213 }
1214
1215 /*
1216 * Build a list of the acceptable GROUP BY expressions for use by
1217 * substitute_grouped_columns().
1218 *
1219 * We get the TLE, not just the expr, because GROUPING wants to know the
1220 * sortgroupref.
1221 */
1222 foreach(l, qry->groupClause)
1223 {
1224 SortGroupClause *grpcl = (SortGroupClause *) lfirst(l);
1225 TargetEntry *expr;
1226
1227 expr = get_sortgroupclause_tle(grpcl, qry->targetList);
1228 if (expr == NULL)
1229 continue; /* probably cannot happen */
1230
1231 groupClauses = lappend(groupClauses, expr);
1232 }
1233
1234 /*
1235 * If there are join alias vars involved, we have to flatten them to the
1236 * underlying vars, so that aliased and unaliased vars will be correctly
1237 * taken as equal. We can skip the expense of doing this if no rangetable
1238 * entries are RTE_JOIN kind.
1239 */
1240 if (hasJoinRTEs)
1241 groupClauses = (List *) flatten_join_alias_vars(NULL, qry,
1242 (Node *) groupClauses);
1243
1244 /*
1245 * Detect whether any of the grouping expressions aren't simple Vars; if
1246 * they're all Vars then we don't have to work so hard in the recursive
1247 * scans. (Note we have to flatten aliases before this.)
1248 *
1249 * Track Vars that are included in all grouping sets separately in
1250 * groupClauseCommonVars, since these are the only ones we can use to
1251 * check for functional dependencies.
1252 */
1253 have_non_var_grouping = false;
1254 foreach(l, groupClauses)
1255 {
1256 TargetEntry *tle = lfirst(l);
1257
1258 if (!IsA(tle->expr, Var))
1259 {
1260 have_non_var_grouping = true;
1261 }
1262 else if (!qry->groupingSets ||
1263 list_member_int(gset_common, tle->ressortgroupref))
1264 {
1265 groupClauseCommonVars = lappend(groupClauseCommonVars, tle->expr);
1266 }
1267 }
1268
1269 /*
1270 * If there are any acceptable GROUP BY expressions, build an RTE and
1271 * nsitem for the result of the grouping step.
1272 */
1273 if (groupClauses)
1274 {
1275 pstate->p_grouping_nsitem =
1276 addRangeTableEntryForGroup(pstate, groupClauses);
1277
1278 /* Set qry->rtable again in case it was previously NIL */
1279 qry->rtable = pstate->p_rtable;
1280 /* Mark the Query as having RTE_GROUP RTE */
1281 qry->hasGroupRTE = true;
1282 }
1283
1284 /*
1285 * Replace grouped variables in the targetlist and HAVING clause with Vars
1286 * that reference the RTE_GROUP RTE. Emit an error message if we find any
1287 * ungrouped variables.
1288 *
1289 * Note: because we check resjunk tlist elements as well as regular ones,
1290 * this will also find ungrouped variables that came from ORDER BY and
1291 * WINDOW clauses. For that matter, it's also going to examine the
1292 * grouping expressions themselves --- but they'll all pass the test ...
1293 *
1294 * We also finalize GROUPING expressions, but for that we need to traverse
1295 * the original (unflattened) clause in order to modify nodes.
1296 */
1297 clause = (Node *) qry->targetList;
1298 finalize_grouping_exprs(clause, pstate, qry,
1299 groupClauses, hasJoinRTEs,
1300 have_non_var_grouping);
1301 if (hasJoinRTEs)
1302 clause = flatten_join_alias_vars(NULL, qry, clause);
1303 qry->targetList = (List *)
1304 substitute_grouped_columns(clause, pstate, qry,
1305 groupClauses, groupClauseCommonVars,
1306 gset_common,
1307 have_non_var_grouping,
1308 &func_grouped_rels);
1309
1310 clause = (Node *) qry->havingQual;
1311 finalize_grouping_exprs(clause, pstate, qry,
1312 groupClauses, hasJoinRTEs,
1313 have_non_var_grouping);
1314 if (hasJoinRTEs)
1315 clause = flatten_join_alias_vars(NULL, qry, clause);
1316 qry->havingQual =
1317 substitute_grouped_columns(clause, pstate, qry,
1318 groupClauses, groupClauseCommonVars,
1319 gset_common,
1320 have_non_var_grouping,
1321 &func_grouped_rels);
1322
1323 /*
1324 * Per spec, aggregates can't appear in a recursive term.
1325 */
1326 if (pstate->p_hasAggs && hasSelfRefRTEs)
1327 ereport(ERROR,
1328 (errcode(ERRCODE_INVALID_RECURSION),
1329 errmsg("aggregate functions are not allowed in a recursive query's recursive term"),
1330 parser_errposition(pstate,
1331 locate_agg_of_level((Node *) qry, 0))));
1332}
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ereport(elevel,...)
Definition: elog.h:150
List * list_intersection_int(const List *list1, const List *list2)
Definition: list.c:1200
bool list_member_int(const List *list, int datum)
Definition: list.c:702
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1384
#define IsA(nodeptr, _type_)
Definition: nodes.h:164
static void finalize_grouping_exprs(Node *node, ParseState *pstate, Query *qry, List *groupClauses, bool hasJoinRTEs, bool have_non_var_grouping)
Definition: parse_agg.c:1594
List * expand_grouping_sets(List *groupingSets, bool groupDistinct, int limit)
Definition: parse_agg.c:1947
static Node * substitute_grouped_columns(Node *node, ParseState *pstate, Query *qry, List *groupClauses, List *groupClauseCommonVars, List *gset_common, bool have_non_var_grouping, List **func_grouped_rels)
Definition: parse_agg.c:1358
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:106
ParseNamespaceItem * addRangeTableEntryForGroup(ParseState *pstate, List *groupClauses)
@ RTE_JOIN
Definition: parsenodes.h:1045
@ RTE_CTE
Definition: parsenodes.h:1049
int locate_agg_of_level(Node *node, int levelsup)
Definition: rewriteManip.c:149
ParseNamespaceItem * p_grouping_nsitem
Definition: parse_node.h:211
List * p_rtable
Definition: parse_node.h:196
bool p_hasAggs
Definition: parse_node.h:226
bool groupDistinct
Definition: parsenodes.h:217
List * groupClause
Definition: parsenodes.h:216
Node * havingQual
Definition: parsenodes.h:222
List * rtable
Definition: parsenodes.h:175
List * targetList
Definition: parsenodes.h:198
List * groupingSets
Definition: parsenodes.h:220
RTEKind rtekind
Definition: parsenodes.h:1078
Index ressortgroupref
Definition: primnodes.h:2245
Definition: primnodes.h:262
TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:367
Node * flatten_join_alias_vars(PlannerInfo *root, Query *query, Node *node)
Definition: var.c:789

References addRangeTableEntryForGroup(), Assert(), ereport, errcode(), errmsg(), ERROR, expand_grouping_sets(), TargetEntry::expr, exprLocation(), finalize_grouping_exprs(), flatten_join_alias_vars(), for_each_from, get_sortgroupclause_tle(), Query::groupClause, Query::groupDistinct, Query::groupingSets, Query::havingQual, IsA, lappend(), lfirst, linitial, list_intersection_int(), list_length(), list_member_int(), locate_agg_of_level(), NIL, ParseState::p_grouping_nsitem, ParseState::p_hasAggs, ParseState::p_rtable, parser_errposition(), TargetEntry::ressortgroupref, Query::rtable, RTE_CTE, RTE_JOIN, RangeTblEntry::rtekind, substitute_grouped_columns(), and Query::targetList.

Referenced by transformDeleteStmt(), transformSelectStmt(), and transformSetOperationStmt().

◆ resolve_aggregate_transtype()

Oid resolve_aggregate_transtype ( Oid  aggfuncid,
Oid  aggtranstype,
Oid inputTypes,
int  numArguments 
)

Definition at line 2076 of file parse_agg.c.

2080{
2081 /* resolve actual type of transition state, if polymorphic */
2082 if (IsPolymorphicType(aggtranstype))
2083 {
2084 /* have to fetch the agg's declared input types... */
2085 Oid *declaredArgTypes;
2086 int agg_nargs;
2087
2088 (void) get_func_signature(aggfuncid, &declaredArgTypes, &agg_nargs);
2089
2090 /*
2091 * VARIADIC ANY aggs could have more actual than declared args, but
2092 * such extra args can't affect polymorphic type resolution.
2093 */
2094 Assert(agg_nargs <= numArguments);
2095
2096 aggtranstype = enforce_generic_type_consistency(inputTypes,
2097 declaredArgTypes,
2098 agg_nargs,
2099 aggtranstype,
2100 false);
2101 pfree(declaredArgTypes);
2102 }
2103 return aggtranstype;
2104}
Oid get_func_signature(Oid funcid, Oid **argtypes, int *nargs)
Definition: lsyscache.c:1863
void pfree(void *pointer)
Definition: mcxt.c:1594
Oid enforce_generic_type_consistency(const Oid *actual_arg_types, Oid *declared_arg_types, int nargs, Oid rettype, bool allow_poly)

References Assert(), enforce_generic_type_consistency(), get_func_signature(), and pfree().

Referenced by initialize_peragg(), and preprocess_aggref().

◆ transformAggregateCall()

void transformAggregateCall ( ParseState pstate,
Aggref agg,
List args,
List aggorder,
bool  agg_distinct 
)

Definition at line 112 of file parse_agg.c.

114{
115 List *argtypes = NIL;
116 List *tlist = NIL;
117 List *torder = NIL;
118 List *tdistinct = NIL;
119 AttrNumber attno = 1;
120 int save_next_resno;
121 ListCell *lc;
122
123 if (AGGKIND_IS_ORDERED_SET(agg->aggkind))
124 {
125 /*
126 * For an ordered-set agg, the args list includes direct args and
127 * aggregated args; we must split them apart.
128 */
129 int numDirectArgs = list_length(args) - list_length(aggorder);
130 List *aargs;
131 ListCell *lc2;
132
133 Assert(numDirectArgs >= 0);
134
135 aargs = list_copy_tail(args, numDirectArgs);
136 agg->aggdirectargs = list_truncate(args, numDirectArgs);
137
138 /*
139 * Build a tlist from the aggregated args, and make a sortlist entry
140 * for each one. Note that the expressions in the SortBy nodes are
141 * ignored (they are the raw versions of the transformed args); we are
142 * just looking at the sort information in the SortBy nodes.
143 */
144 forboth(lc, aargs, lc2, aggorder)
145 {
146 Expr *arg = (Expr *) lfirst(lc);
147 SortBy *sortby = (SortBy *) lfirst(lc2);
148 TargetEntry *tle;
149
150 /* We don't bother to assign column names to the entries */
151 tle = makeTargetEntry(arg, attno++, NULL, false);
152 tlist = lappend(tlist, tle);
153
154 torder = addTargetToSortList(pstate, tle,
155 torder, tlist, sortby);
156 }
157
158 /* Never any DISTINCT in an ordered-set agg */
159 Assert(!agg_distinct);
160 }
161 else
162 {
163 /* Regular aggregate, so it has no direct args */
164 agg->aggdirectargs = NIL;
165
166 /*
167 * Transform the plain list of Exprs into a targetlist.
168 */
169 foreach(lc, args)
170 {
171 Expr *arg = (Expr *) lfirst(lc);
172 TargetEntry *tle;
173
174 /* We don't bother to assign column names to the entries */
175 tle = makeTargetEntry(arg, attno++, NULL, false);
176 tlist = lappend(tlist, tle);
177 }
178
179 /*
180 * If we have an ORDER BY, transform it. This will add columns to the
181 * tlist if they appear in ORDER BY but weren't already in the arg
182 * list. They will be marked resjunk = true so we can tell them apart
183 * from regular aggregate arguments later.
184 *
185 * We need to mess with p_next_resno since it will be used to number
186 * any new targetlist entries.
187 */
188 save_next_resno = pstate->p_next_resno;
189 pstate->p_next_resno = attno;
190
191 torder = transformSortClause(pstate,
192 aggorder,
193 &tlist,
195 true /* force SQL99 rules */ );
196
197 /*
198 * If we have DISTINCT, transform that to produce a distinctList.
199 */
200 if (agg_distinct)
201 {
202 tdistinct = transformDistinctClause(pstate, &tlist, torder, true);
203
204 /*
205 * Remove this check if executor support for hashed distinct for
206 * aggregates is ever added.
207 */
208 foreach(lc, tdistinct)
209 {
210 SortGroupClause *sortcl = (SortGroupClause *) lfirst(lc);
211
212 if (!OidIsValid(sortcl->sortop))
213 {
214 Node *expr = get_sortgroupclause_expr(sortcl, tlist);
215
217 (errcode(ERRCODE_UNDEFINED_FUNCTION),
218 errmsg("could not identify an ordering operator for type %s",
219 format_type_be(exprType(expr))),
220 errdetail("Aggregates with DISTINCT must be able to sort their inputs."),
221 parser_errposition(pstate, exprLocation(expr))));
222 }
223 }
224 }
225
226 pstate->p_next_resno = save_next_resno;
227 }
228
229 /* Update the Aggref with the transformation results */
230 agg->args = tlist;
231 agg->aggorder = torder;
232 agg->aggdistinct = tdistinct;
233
234 /*
235 * Now build the aggargtypes list with the type OIDs of the direct and
236 * aggregated args, ignoring any resjunk entries that might have been
237 * added by ORDER BY/DISTINCT processing. We can't do this earlier
238 * because said processing can modify some args' data types, in particular
239 * by resolving previously-unresolved "unknown" literals.
240 */
241 foreach(lc, agg->aggdirectargs)
242 {
243 Expr *arg = (Expr *) lfirst(lc);
244
245 argtypes = lappend_oid(argtypes, exprType((Node *) arg));
246 }
247 foreach(lc, tlist)
248 {
249 TargetEntry *tle = (TargetEntry *) lfirst(lc);
250
251 if (tle->resjunk)
252 continue; /* ignore junk */
253 argtypes = lappend_oid(argtypes, exprType((Node *) tle->expr));
254 }
255 agg->aggargtypes = argtypes;
256
257 check_agglevels_and_constraints(pstate, (Node *) agg);
258}
int16 AttrNumber
Definition: attnum.h:21
int errdetail(const char *fmt,...)
Definition: elog.c:1216
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1613
List * lappend_oid(List *list, Oid datum)
Definition: list.c:375
List * list_truncate(List *list, int new_size)
Definition: list.c:631
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:289
static void check_agglevels_and_constraints(ParseState *pstate, Node *expr)
Definition: parse_agg.c:307
List * transformSortClause(ParseState *pstate, List *orderlist, List **targetlist, ParseExprKind exprKind, bool useSQL99)
List * transformDistinctClause(ParseState *pstate, List **targetlist, List *sortClause, bool is_agg)
List * addTargetToSortList(ParseState *pstate, TargetEntry *tle, List *sortlist, List *targetlist, SortBy *sortby)
@ EXPR_KIND_ORDER_BY
Definition: parse_node.h:60
void * arg
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:518
List * aggdistinct
Definition: primnodes.h:493
List * aggdirectargs
Definition: primnodes.h:484
List * aggorder
Definition: primnodes.h:490
int p_next_resno
Definition: parse_node.h:215
Node * get_sortgroupclause_expr(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:379

References addTargetToSortList(), Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggorder, arg, generate_unaccent_rules::args, Aggref::args, Assert(), check_agglevels_and_constraints(), ereport, errcode(), errdetail(), errmsg(), ERROR, TargetEntry::expr, EXPR_KIND_ORDER_BY, exprLocation(), exprType(), forboth, format_type_be(), get_sortgroupclause_expr(), lappend(), lappend_oid(), lfirst, list_copy_tail(), list_length(), list_truncate(), makeTargetEntry(), NIL, OidIsValid, ParseState::p_next_resno, parser_errposition(), SortGroupClause::sortop, transformDistinctClause(), and transformSortClause().

Referenced by ParseFuncOrColumn(), and transformJsonAggConstructor().

◆ transformGroupingFunc()

Node * transformGroupingFunc ( ParseState pstate,
GroupingFunc p 
)

Definition at line 268 of file parse_agg.c.

269{
270 ListCell *lc;
271 List *args = p->args;
272 List *result_list = NIL;
274
275 if (list_length(args) > 31)
277 (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
278 errmsg("GROUPING must have fewer than 32 arguments"),
279 parser_errposition(pstate, p->location)));
280
281 foreach(lc, args)
282 {
283 Node *current_result;
284
285 current_result = transformExpr(pstate, (Node *) lfirst(lc), pstate->p_expr_kind);
286
287 /* acceptability of expressions is checked later */
288
289 result_list = lappend(result_list, current_result);
290 }
291
292 result->args = result_list;
293 result->location = p->location;
294
295 check_agglevels_and_constraints(pstate, (Node *) result);
296
297 return (Node *) result;
298}
#define makeNode(_type_)
Definition: nodes.h:161
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition: parse_expr.c:119
ParseLoc location
Definition: primnodes.h:573
ParseExprKind p_expr_kind
Definition: parse_node.h:214

References generate_unaccent_rules::args, check_agglevels_and_constraints(), ereport, errcode(), errmsg(), ERROR, lappend(), lfirst, list_length(), GroupingFunc::location, makeNode, NIL, ParseState::p_expr_kind, parser_errposition(), and transformExpr().

Referenced by transformExprRecurse().

◆ transformWindowFuncCall()

void transformWindowFuncCall ( ParseState pstate,
WindowFunc wfunc,
WindowDef windef 
)

Definition at line 878 of file parse_agg.c.

880{
881 const char *err;
882 bool errkind;
883
884 /*
885 * A window function call can't contain another one (but aggs are OK). XXX
886 * is this required by spec, or just an unimplemented feature?
887 *
888 * Note: we don't need to check the filter expression here, because the
889 * context checks done below and in transformAggregateCall would have
890 * already rejected any window funcs or aggs within the filter.
891 */
892 if (pstate->p_hasWindowFuncs &&
893 contain_windowfuncs((Node *) wfunc->args))
895 (errcode(ERRCODE_WINDOWING_ERROR),
896 errmsg("window function calls cannot be nested"),
897 parser_errposition(pstate,
898 locate_windowfunc((Node *) wfunc->args))));
899
900 /*
901 * Check to see if the window function is in an invalid place within the
902 * query.
903 *
904 * For brevity we support two schemes for reporting an error here: set
905 * "err" to a custom message, or set "errkind" true if the error context
906 * is sufficiently identified by what ParseExprKindName will return, *and*
907 * what it will return is just a SQL keyword. (Otherwise, use a custom
908 * message to avoid creating translation problems.)
909 */
910 err = NULL;
911 errkind = false;
912 switch (pstate->p_expr_kind)
913 {
914 case EXPR_KIND_NONE:
915 Assert(false); /* can't happen */
916 break;
917 case EXPR_KIND_OTHER:
918 /* Accept window func here; caller must throw error if wanted */
919 break;
922 err = _("window functions are not allowed in JOIN conditions");
923 break;
925 /* can't get here, but just in case, throw an error */
926 errkind = true;
927 break;
929 err = _("window functions are not allowed in functions in FROM");
930 break;
931 case EXPR_KIND_WHERE:
932 errkind = true;
933 break;
934 case EXPR_KIND_POLICY:
935 err = _("window functions are not allowed in policy expressions");
936 break;
937 case EXPR_KIND_HAVING:
938 errkind = true;
939 break;
940 case EXPR_KIND_FILTER:
941 errkind = true;
942 break;
948 err = _("window functions are not allowed in window definitions");
949 break;
951 /* okay */
952 break;
956 errkind = true;
957 break;
959 err = _("window functions are not allowed in MERGE WHEN conditions");
960 break;
962 errkind = true;
963 break;
965 /* okay */
966 break;
968 /* okay */
969 break;
970 case EXPR_KIND_LIMIT:
971 case EXPR_KIND_OFFSET:
972 errkind = true;
973 break;
976 errkind = true;
977 break;
978 case EXPR_KIND_VALUES:
980 errkind = true;
981 break;
984 err = _("window functions are not allowed in check constraints");
985 break;
988 err = _("window functions are not allowed in DEFAULT expressions");
989 break;
991 err = _("window functions are not allowed in index expressions");
992 break;
994 err = _("window functions are not allowed in statistics expressions");
995 break;
997 err = _("window functions are not allowed in index predicates");
998 break;
1000 err = _("window functions are not allowed in transform expressions");
1001 break;
1003 err = _("window functions are not allowed in EXECUTE parameters");
1004 break;
1006 err = _("window functions are not allowed in trigger WHEN conditions");
1007 break;
1009 err = _("window functions are not allowed in partition bound");
1010 break;
1012 err = _("window functions are not allowed in partition key expressions");
1013 break;
1015 err = _("window functions are not allowed in CALL arguments");
1016 break;
1018 err = _("window functions are not allowed in COPY FROM WHERE conditions");
1019 break;
1021 err = _("window functions are not allowed in column generation expressions");
1022 break;
1024 errkind = true;
1025 break;
1026
1027 /*
1028 * There is intentionally no default: case here, so that the
1029 * compiler will warn if we add a new ParseExprKind without
1030 * extending this switch. If we do see an unrecognized value at
1031 * runtime, the behavior will be the same as for EXPR_KIND_OTHER,
1032 * which is sane anyway.
1033 */
1034 }
1035 if (err)
1036 ereport(ERROR,
1037 (errcode(ERRCODE_WINDOWING_ERROR),
1038 errmsg_internal("%s", err),
1039 parser_errposition(pstate, wfunc->location)));
1040 if (errkind)
1041 ereport(ERROR,
1042 (errcode(ERRCODE_WINDOWING_ERROR),
1043 /* translator: %s is name of a SQL construct, eg GROUP BY */
1044 errmsg("window functions are not allowed in %s",
1046 parser_errposition(pstate, wfunc->location)));
1047
1048 /*
1049 * If the OVER clause just specifies a window name, find that WINDOW
1050 * clause (which had better be present). Otherwise, try to match all the
1051 * properties of the OVER clause, and make a new entry in the p_windowdefs
1052 * list if no luck.
1053 */
1054 if (windef->name)
1055 {
1056 Index winref = 0;
1057 ListCell *lc;
1058
1059 Assert(windef->refname == NULL &&
1060 windef->partitionClause == NIL &&
1061 windef->orderClause == NIL &&
1063
1064 foreach(lc, pstate->p_windowdefs)
1065 {
1066 WindowDef *refwin = (WindowDef *) lfirst(lc);
1067
1068 winref++;
1069 if (refwin->name && strcmp(refwin->name, windef->name) == 0)
1070 {
1071 wfunc->winref = winref;
1072 break;
1073 }
1074 }
1075 if (lc == NULL) /* didn't find it? */
1076 ereport(ERROR,
1077 (errcode(ERRCODE_UNDEFINED_OBJECT),
1078 errmsg("window \"%s\" does not exist", windef->name),
1079 parser_errposition(pstate, windef->location)));
1080 }
1081 else
1082 {
1083 Index winref = 0;
1084 ListCell *lc;
1085
1086 foreach(lc, pstate->p_windowdefs)
1087 {
1088 WindowDef *refwin = (WindowDef *) lfirst(lc);
1089
1090 winref++;
1091 if (refwin->refname && windef->refname &&
1092 strcmp(refwin->refname, windef->refname) == 0)
1093 /* matched on refname */ ;
1094 else if (!refwin->refname && !windef->refname)
1095 /* matched, no refname */ ;
1096 else
1097 continue;
1098
1099 /*
1100 * Also see similar de-duplication code in optimize_window_clauses
1101 */
1102 if (equal(refwin->partitionClause, windef->partitionClause) &&
1103 equal(refwin->orderClause, windef->orderClause) &&
1104 refwin->frameOptions == windef->frameOptions &&
1105 equal(refwin->startOffset, windef->startOffset) &&
1106 equal(refwin->endOffset, windef->endOffset))
1107 {
1108 /* found a duplicate window specification */
1109 wfunc->winref = winref;
1110 break;
1111 }
1112 }
1113 if (lc == NULL) /* didn't find it? */
1114 {
1115 pstate->p_windowdefs = lappend(pstate->p_windowdefs, windef);
1116 wfunc->winref = list_length(pstate->p_windowdefs);
1117 }
1118 }
1119
1120 pstate->p_hasWindowFuncs = true;
1121}
unsigned int Index
Definition: c.h:622
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1170
#define _(x)
Definition: elog.c:91
void err(int eval, const char *fmt,...)
Definition: err.c:43
const char * ParseExprKindName(ParseExprKind exprKind)
Definition: parse_expr.c:3134
@ EXPR_KIND_EXECUTE_PARAMETER
Definition: parse_node.h:76
@ EXPR_KIND_DOMAIN_CHECK
Definition: parse_node.h:69
@ EXPR_KIND_COPY_WHERE
Definition: parse_node.h:82
@ EXPR_KIND_COLUMN_DEFAULT
Definition: parse_node.h:70
@ EXPR_KIND_DISTINCT_ON
Definition: parse_node.h:61
@ EXPR_KIND_MERGE_WHEN
Definition: parse_node.h:58
@ EXPR_KIND_STATS_EXPRESSION
Definition: parse_node.h:74
@ EXPR_KIND_INDEX_EXPRESSION
Definition: parse_node.h:72
@ EXPR_KIND_MERGE_RETURNING
Definition: parse_node.h:65
@ EXPR_KIND_PARTITION_BOUND
Definition: parse_node.h:79
@ EXPR_KIND_FUNCTION_DEFAULT
Definition: parse_node.h:71
@ EXPR_KIND_WINDOW_FRAME_RANGE
Definition: parse_node.h:51
@ EXPR_KIND_VALUES
Definition: parse_node.h:66
@ EXPR_KIND_FROM_SUBSELECT
Definition: parse_node.h:44
@ EXPR_KIND_POLICY
Definition: parse_node.h:78
@ EXPR_KIND_WINDOW_FRAME_GROUPS
Definition: parse_node.h:53
@ EXPR_KIND_PARTITION_EXPRESSION
Definition: parse_node.h:80
@ EXPR_KIND_JOIN_USING
Definition: parse_node.h:43
@ EXPR_KIND_INDEX_PREDICATE
Definition: parse_node.h:73
@ EXPR_KIND_OFFSET
Definition: parse_node.h:63
@ EXPR_KIND_JOIN_ON
Definition: parse_node.h:42
@ EXPR_KIND_HAVING
Definition: parse_node.h:47
@ EXPR_KIND_INSERT_TARGET
Definition: parse_node.h:55
@ EXPR_KIND_ALTER_COL_TRANSFORM
Definition: parse_node.h:75
@ EXPR_KIND_LIMIT
Definition: parse_node.h:62
@ EXPR_KIND_WHERE
Definition: parse_node.h:46
@ EXPR_KIND_UPDATE_TARGET
Definition: parse_node.h:57
@ EXPR_KIND_SELECT_TARGET
Definition: parse_node.h:54
@ EXPR_KIND_RETURNING
Definition: parse_node.h:64
@ EXPR_KIND_GENERATED_COLUMN
Definition: parse_node.h:83
@ EXPR_KIND_NONE
Definition: parse_node.h:40
@ EXPR_KIND_CALL_ARGUMENT
Definition: parse_node.h:81
@ EXPR_KIND_GROUP_BY
Definition: parse_node.h:59
@ EXPR_KIND_OTHER
Definition: parse_node.h:41
@ EXPR_KIND_FROM_FUNCTION
Definition: parse_node.h:45
@ EXPR_KIND_TRIGGER_WHEN
Definition: parse_node.h:77
@ EXPR_KIND_FILTER
Definition: parse_node.h:48
@ EXPR_KIND_UPDATE_SOURCE
Definition: parse_node.h:56
@ EXPR_KIND_CHECK_CONSTRAINT
Definition: parse_node.h:68
@ EXPR_KIND_WINDOW_PARTITION
Definition: parse_node.h:49
@ EXPR_KIND_CYCLE_MARK
Definition: parse_node.h:84
@ EXPR_KIND_WINDOW_FRAME_ROWS
Definition: parse_node.h:52
@ EXPR_KIND_WINDOW_ORDER
Definition: parse_node.h:50
@ EXPR_KIND_VALUES_SINGLE
Definition: parse_node.h:67
#define FRAMEOPTION_DEFAULTS
Definition: parsenodes.h:636
bool contain_windowfuncs(Node *node)
Definition: rewriteManip.c:214
int locate_windowfunc(Node *node)
Definition: rewriteManip.c:251
bool p_hasWindowFuncs
Definition: parse_node.h:227
List * p_windowdefs
Definition: parse_node.h:213
List * orderClause
Definition: parsenodes.h:595
ParseLoc location
Definition: parsenodes.h:599
List * partitionClause
Definition: parsenodes.h:594
Node * startOffset
Definition: parsenodes.h:597
char * refname
Definition: parsenodes.h:593
Node * endOffset
Definition: parsenodes.h:598
int frameOptions
Definition: parsenodes.h:596
char * name
Definition: parsenodes.h:592
List * args
Definition: primnodes.h:605
Index winref
Definition: primnodes.h:611
ParseLoc location
Definition: primnodes.h:619

References _, WindowFunc::args, Assert(), contain_windowfuncs(), WindowDef::endOffset, equal(), ereport, err(), errcode(), errmsg(), errmsg_internal(), ERROR, EXPR_KIND_ALTER_COL_TRANSFORM, EXPR_KIND_CALL_ARGUMENT, EXPR_KIND_CHECK_CONSTRAINT, EXPR_KIND_COLUMN_DEFAULT, EXPR_KIND_COPY_WHERE, EXPR_KIND_CYCLE_MARK, EXPR_KIND_DISTINCT_ON, EXPR_KIND_DOMAIN_CHECK, EXPR_KIND_EXECUTE_PARAMETER, EXPR_KIND_FILTER, EXPR_KIND_FROM_FUNCTION, EXPR_KIND_FROM_SUBSELECT, EXPR_KIND_FUNCTION_DEFAULT, EXPR_KIND_GENERATED_COLUMN, EXPR_KIND_GROUP_BY, EXPR_KIND_HAVING, EXPR_KIND_INDEX_EXPRESSION, EXPR_KIND_INDEX_PREDICATE, EXPR_KIND_INSERT_TARGET, EXPR_KIND_JOIN_ON, EXPR_KIND_JOIN_USING, EXPR_KIND_LIMIT, EXPR_KIND_MERGE_RETURNING, EXPR_KIND_MERGE_WHEN, EXPR_KIND_NONE, EXPR_KIND_OFFSET, EXPR_KIND_ORDER_BY, EXPR_KIND_OTHER, EXPR_KIND_PARTITION_BOUND, EXPR_KIND_PARTITION_EXPRESSION, EXPR_KIND_POLICY, EXPR_KIND_RETURNING, EXPR_KIND_SELECT_TARGET, EXPR_KIND_STATS_EXPRESSION, EXPR_KIND_TRIGGER_WHEN, EXPR_KIND_UPDATE_SOURCE, EXPR_KIND_UPDATE_TARGET, EXPR_KIND_VALUES, EXPR_KIND_VALUES_SINGLE, EXPR_KIND_WHERE, EXPR_KIND_WINDOW_FRAME_GROUPS, EXPR_KIND_WINDOW_FRAME_RANGE, EXPR_KIND_WINDOW_FRAME_ROWS, EXPR_KIND_WINDOW_ORDER, EXPR_KIND_WINDOW_PARTITION, FRAMEOPTION_DEFAULTS, WindowDef::frameOptions, lappend(), lfirst, list_length(), locate_windowfunc(), WindowDef::location, WindowFunc::location, WindowDef::name, NIL, WindowDef::orderClause, ParseState::p_expr_kind, ParseState::p_hasWindowFuncs, ParseState::p_windowdefs, ParseExprKindName(), parser_errposition(), WindowDef::partitionClause, WindowDef::refname, WindowDef::startOffset, and WindowFunc::winref.

Referenced by ParseFuncOrColumn(), and transformJsonAggConstructor().