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 1970 of file parse_agg.c.

1971 {
1972  ListCell *lc;
1973 
1974  foreach(lc, aggref->args)
1975  {
1976  HeapTuple typeTuple;
1977  Form_pg_type pt;
1978  TargetEntry *tle = (TargetEntry *) lfirst(lc);
1979  Oid type = exprType((Node *) tle->expr);
1980 
1981  typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type));
1982  if (!HeapTupleIsValid(typeTuple))
1983  elog(ERROR, "cache lookup failed for type %u", type);
1984 
1985  pt = (Form_pg_type) GETSTRUCT(typeTuple);
1986 
1987  if (!pt->typbyval &&
1988  (!OidIsValid(pt->typsend) || !OidIsValid(pt->typreceive)))
1989  {
1990  ReleaseSysCache(typeTuple);
1991  return false;
1992  }
1993  ReleaseSysCache(typeTuple);
1994  }
1995  return true;
1996 }
#define OidIsValid(objectId)
Definition: c.h:775
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
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:252
unsigned int Oid
Definition: postgres_ext.h:31
List * args
Definition: primnodes.h:468
Definition: nodes.h:129
Expr * expr
Definition: primnodes.h:2192
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:266
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:218
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 2112 of file parse_agg.c.

2114 {
2115  List *args;
2116  FuncExpr *fexpr;
2117 
2118  /* deserialfn always takes BYTEA, INTERNAL and returns INTERNAL */
2119  args = list_make2(make_agg_arg(BYTEAOID, InvalidOid),
2120  make_agg_arg(INTERNALOID, InvalidOid));
2121 
2122  fexpr = makeFuncExpr(deserialfn_oid,
2123  INTERNALOID,
2124  args,
2125  InvalidOid,
2126  InvalidOid,
2128  *deserialfnexpr = (Expr *) fexpr;
2129 }
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
Definition: makefuncs.c:521
static Node * make_agg_arg(Oid argtype, Oid argcollation)
Definition: parse_agg.c:2176
#define list_make2(x1, x2)
Definition: pg_list.h:214
#define InvalidOid
Definition: postgres_ext.h:36
@ COERCE_EXPLICIT_CALL
Definition: primnodes.h:734
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 2136 of file parse_agg.c.

2143 {
2144  List *args;
2145  int i;
2146 
2147  /*
2148  * Build expr tree for final function
2149  */
2150  args = list_make1(make_agg_arg(agg_state_type, agg_input_collation));
2151 
2152  /* finalfn may take additional args, which match agg's input types */
2153  for (i = 0; i < num_finalfn_inputs - 1; i++)
2154  {
2155  args = lappend(args,
2156  make_agg_arg(agg_input_types[i], agg_input_collation));
2157  }
2158 
2159  *finalfnexpr = (Expr *) makeFuncExpr(finalfn_oid,
2160  agg_result_type,
2161  args,
2162  InvalidOid,
2163  agg_input_collation,
2165  /* finalfn is currently never treated as variadic */
2166 }
int i
Definition: isn.c:73
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 2089 of file parse_agg.c.

2091 {
2092  List *args;
2093  FuncExpr *fexpr;
2094 
2095  /* serialfn always takes INTERNAL and returns BYTEA */
2096  args = list_make1(make_agg_arg(INTERNALOID, InvalidOid));
2097 
2098  fexpr = makeFuncExpr(serialfn_oid,
2099  BYTEAOID,
2100  args,
2101  InvalidOid,
2102  InvalidOid,
2104  *serialfnexpr = (Expr *) fexpr;
2105 }

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 2028 of file parse_agg.c.

2038 {
2039  List *args;
2040  FuncExpr *fexpr;
2041  int i;
2042 
2043  /*
2044  * Build arg list to use in the transfn FuncExpr node.
2045  */
2046  args = list_make1(make_agg_arg(agg_state_type, agg_input_collation));
2047 
2048  for (i = agg_num_direct_inputs; i < agg_num_inputs; i++)
2049  {
2050  args = lappend(args,
2051  make_agg_arg(agg_input_types[i], agg_input_collation));
2052  }
2053 
2054  fexpr = makeFuncExpr(transfn_oid,
2055  agg_state_type,
2056  args,
2057  InvalidOid,
2058  agg_input_collation,
2060  fexpr->funcvariadic = agg_variadic;
2061  *transfnexpr = (Expr *) fexpr;
2062 
2063  /*
2064  * Build invtransfn expression if requested, with same args as transfn
2065  */
2066  if (invtransfnexpr != NULL)
2067  {
2068  if (OidIsValid(invtransfn_oid))
2069  {
2070  fexpr = makeFuncExpr(invtransfn_oid,
2071  agg_state_type,
2072  args,
2073  InvalidOid,
2074  agg_input_collation,
2076  fexpr->funcvariadic = agg_variadic;
2077  *invtransfnexpr = (Expr *) fexpr;
2078  }
2079  else
2080  *invtransfnexpr = NULL;
2081  }
2082 }

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 1805 of file parse_agg.c.

1806 {
1807  List *expanded_groups = NIL;
1808  List *result = NIL;
1809  double numsets = 1;
1810  ListCell *lc;
1811 
1812  if (groupingSets == NIL)
1813  return NIL;
1814 
1815  foreach(lc, groupingSets)
1816  {
1817  List *current_result = NIL;
1818  GroupingSet *gs = lfirst(lc);
1819 
1820  current_result = expand_groupingset_node(gs);
1821 
1822  Assert(current_result != NIL);
1823 
1824  numsets *= list_length(current_result);
1825 
1826  if (limit >= 0 && numsets > limit)
1827  return NIL;
1828 
1829  expanded_groups = lappend(expanded_groups, current_result);
1830  }
1831 
1832  /*
1833  * Do cartesian product between sublists of expanded_groups. While at it,
1834  * remove any duplicate elements from individual grouping sets (we must
1835  * NOT change the number of sets though)
1836  */
1837 
1838  foreach(lc, (List *) linitial(expanded_groups))
1839  {
1840  result = lappend(result, list_union_int(NIL, (List *) lfirst(lc)));
1841  }
1842 
1843  for_each_from(lc, expanded_groups, 1)
1844  {
1845  List *p = lfirst(lc);
1846  List *new_result = NIL;
1847  ListCell *lc2;
1848 
1849  foreach(lc2, result)
1850  {
1851  List *q = lfirst(lc2);
1852  ListCell *lc3;
1853 
1854  foreach(lc3, p)
1855  {
1856  new_result = lappend(new_result,
1857  list_union_int(q, (List *) lfirst(lc3)));
1858  }
1859  }
1860  result = new_result;
1861  }
1862 
1863  /* Now sort the lists by length and deduplicate if necessary */
1864  if (!groupDistinct || list_length(result) < 2)
1865  list_sort(result, cmp_list_len_asc);
1866  else
1867  {
1868  ListCell *cell;
1869  List *prev;
1870 
1871  /* Sort each groupset individually */
1872  foreach(cell, result)
1873  list_sort(lfirst(cell), list_int_cmp);
1874 
1875  /* Now sort the list of groupsets by length and contents */
1877 
1878  /* Finally, remove duplicates */
1879  prev = linitial(result);
1880  for_each_from(cell, result, 1)
1881  {
1882  if (equal(lfirst(cell), prev))
1883  result = foreach_delete_current(result, cell);
1884  else
1885  prev = lfirst(cell);
1886  }
1887  }
1888 
1889  return result;
1890 }
#define Assert(condition)
Definition: c.h:858
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
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:1761
static int cmp_list_len_contents_asc(const ListCell *a, const ListCell *b)
Definition: parse_agg.c:1771
static List * expand_groupingset_node(GroupingSet *gs)
Definition: parse_agg.c:1659
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 preprocess_grouping_sets().

◆ get_aggregate_argtypes()

int get_aggregate_argtypes ( Aggref aggref,
Oid inputTypes 
)

Definition at line 1908 of file parse_agg.c.

1909 {
1910  int numArguments = 0;
1911  ListCell *lc;
1912 
1913  Assert(list_length(aggref->aggargtypes) <= FUNC_MAX_ARGS);
1914 
1915  foreach(lc, aggref->aggargtypes)
1916  {
1917  inputTypes[numArguments++] = lfirst_oid(lc);
1918  }
1919 
1920  return numArguments;
1921 }
#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 1080 of file parse_agg.c.

1081 {
1082  List *gset_common = NIL;
1083  List *groupClauses = NIL;
1084  List *groupClauseCommonVars = NIL;
1085  bool have_non_var_grouping;
1086  List *func_grouped_rels = NIL;
1087  ListCell *l;
1088  bool hasJoinRTEs;
1089  bool hasSelfRefRTEs;
1090  Node *clause;
1091 
1092  /* This should only be called if we found aggregates or grouping */
1093  Assert(pstate->p_hasAggs || qry->groupClause || qry->havingQual || qry->groupingSets);
1094 
1095  /*
1096  * If we have grouping sets, expand them and find the intersection of all
1097  * sets.
1098  */
1099  if (qry->groupingSets)
1100  {
1101  /*
1102  * The limit of 4096 is arbitrary and exists simply to avoid resource
1103  * issues from pathological constructs.
1104  */
1105  List *gsets = expand_grouping_sets(qry->groupingSets, qry->groupDistinct, 4096);
1106 
1107  if (!gsets)
1108  ereport(ERROR,
1109  (errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
1110  errmsg("too many grouping sets present (maximum 4096)"),
1111  parser_errposition(pstate,
1112  qry->groupClause
1113  ? exprLocation((Node *) qry->groupClause)
1114  : exprLocation((Node *) qry->groupingSets))));
1115 
1116  /*
1117  * The intersection will often be empty, so help things along by
1118  * seeding the intersect with the smallest set.
1119  */
1120  gset_common = linitial(gsets);
1121 
1122  if (gset_common)
1123  {
1124  for_each_from(l, gsets, 1)
1125  {
1126  gset_common = list_intersection_int(gset_common, lfirst(l));
1127  if (!gset_common)
1128  break;
1129  }
1130  }
1131 
1132  /*
1133  * If there was only one grouping set in the expansion, AND if the
1134  * groupClause is non-empty (meaning that the grouping set is not
1135  * empty either), then we can ditch the grouping set and pretend we
1136  * just had a normal GROUP BY.
1137  */
1138  if (list_length(gsets) == 1 && qry->groupClause)
1139  qry->groupingSets = NIL;
1140  }
1141 
1142  /*
1143  * Scan the range table to see if there are JOIN or self-reference CTE
1144  * entries. We'll need this info below.
1145  */
1146  hasJoinRTEs = hasSelfRefRTEs = false;
1147  foreach(l, pstate->p_rtable)
1148  {
1149  RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
1150 
1151  if (rte->rtekind == RTE_JOIN)
1152  hasJoinRTEs = true;
1153  else if (rte->rtekind == RTE_CTE && rte->self_reference)
1154  hasSelfRefRTEs = true;
1155  }
1156 
1157  /*
1158  * Build a list of the acceptable GROUP BY expressions for use by
1159  * check_ungrouped_columns().
1160  *
1161  * We get the TLE, not just the expr, because GROUPING wants to know the
1162  * sortgroupref.
1163  */
1164  foreach(l, qry->groupClause)
1165  {
1166  SortGroupClause *grpcl = (SortGroupClause *) lfirst(l);
1167  TargetEntry *expr;
1168 
1169  expr = get_sortgroupclause_tle(grpcl, qry->targetList);
1170  if (expr == NULL)
1171  continue; /* probably cannot happen */
1172 
1173  groupClauses = lappend(groupClauses, expr);
1174  }
1175 
1176  /*
1177  * If there are join alias vars involved, we have to flatten them to the
1178  * underlying vars, so that aliased and unaliased vars will be correctly
1179  * taken as equal. We can skip the expense of doing this if no rangetable
1180  * entries are RTE_JOIN kind.
1181  */
1182  if (hasJoinRTEs)
1183  groupClauses = (List *) flatten_join_alias_vars(NULL, qry,
1184  (Node *) groupClauses);
1185 
1186  /*
1187  * Detect whether any of the grouping expressions aren't simple Vars; if
1188  * they're all Vars then we don't have to work so hard in the recursive
1189  * scans. (Note we have to flatten aliases before this.)
1190  *
1191  * Track Vars that are included in all grouping sets separately in
1192  * groupClauseCommonVars, since these are the only ones we can use to
1193  * check for functional dependencies.
1194  */
1195  have_non_var_grouping = false;
1196  foreach(l, groupClauses)
1197  {
1198  TargetEntry *tle = lfirst(l);
1199 
1200  if (!IsA(tle->expr, Var))
1201  {
1202  have_non_var_grouping = true;
1203  }
1204  else if (!qry->groupingSets ||
1205  list_member_int(gset_common, tle->ressortgroupref))
1206  {
1207  groupClauseCommonVars = lappend(groupClauseCommonVars, tle->expr);
1208  }
1209  }
1210 
1211  /*
1212  * Check the targetlist and HAVING clause for ungrouped variables.
1213  *
1214  * Note: because we check resjunk tlist elements as well as regular ones,
1215  * this will also find ungrouped variables that came from ORDER BY and
1216  * WINDOW clauses. For that matter, it's also going to examine the
1217  * grouping expressions themselves --- but they'll all pass the test ...
1218  *
1219  * We also finalize GROUPING expressions, but for that we need to traverse
1220  * the original (unflattened) clause in order to modify nodes.
1221  */
1222  clause = (Node *) qry->targetList;
1223  finalize_grouping_exprs(clause, pstate, qry,
1224  groupClauses, hasJoinRTEs,
1225  have_non_var_grouping);
1226  if (hasJoinRTEs)
1227  clause = flatten_join_alias_vars(NULL, qry, clause);
1228  check_ungrouped_columns(clause, pstate, qry,
1229  groupClauses, groupClauseCommonVars,
1230  have_non_var_grouping,
1231  &func_grouped_rels);
1232 
1233  clause = (Node *) qry->havingQual;
1234  finalize_grouping_exprs(clause, pstate, qry,
1235  groupClauses, hasJoinRTEs,
1236  have_non_var_grouping);
1237  if (hasJoinRTEs)
1238  clause = flatten_join_alias_vars(NULL, qry, clause);
1239  check_ungrouped_columns(clause, pstate, qry,
1240  groupClauses, groupClauseCommonVars,
1241  have_non_var_grouping,
1242  &func_grouped_rels);
1243 
1244  /*
1245  * Per spec, aggregates can't appear in a recursive term.
1246  */
1247  if (pstate->p_hasAggs && hasSelfRefRTEs)
1248  ereport(ERROR,
1249  (errcode(ERRCODE_INVALID_RECURSION),
1250  errmsg("aggregate functions are not allowed in a recursive query's recursive term"),
1251  parser_errposition(pstate,
1252  locate_agg_of_level((Node *) qry, 0))));
1253 }
int errcode(int sqlerrcode)
Definition: elog.c:857
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ereport(elevel,...)
Definition: elog.h:149
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:1386
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
static void finalize_grouping_exprs(Node *node, ParseState *pstate, Query *qry, List *groupClauses, bool hasJoinRTEs, bool have_non_var_grouping)
Definition: parse_agg.c:1485
static void check_ungrouped_columns(Node *node, ParseState *pstate, Query *qry, List *groupClauses, List *groupClauseCommonVars, bool have_non_var_grouping, List **func_grouped_rels)
Definition: parse_agg.c:1277
List * expand_grouping_sets(List *groupingSets, bool groupDistinct, int limit)
Definition: parse_agg.c:1805
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:106
@ RTE_JOIN
Definition: parsenodes.h:1030
@ RTE_CTE
Definition: parsenodes.h:1034
int locate_agg_of_level(Node *node, int levelsup)
Definition: rewriteManip.c:149
List * p_rtable
Definition: parse_node.h:194
bool p_hasAggs
Definition: parse_node.h:223
bool groupDistinct
Definition: parsenodes.h:201
List * groupClause
Definition: parsenodes.h:200
Node * havingQual
Definition: parsenodes.h:205
List * targetList
Definition: parsenodes.h:191
List * groupingSets
Definition: parsenodes.h:203
RTEKind rtekind
Definition: parsenodes.h:1057
Index ressortgroupref
Definition: primnodes.h:2198
Definition: primnodes.h:248
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:744

References Assert, check_ungrouped_columns(), 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_hasAggs, ParseState::p_rtable, parser_errposition(), TargetEntry::ressortgroupref, RTE_CTE, RTE_JOIN, RangeTblEntry::rtekind, and Query::targetList.

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

◆ resolve_aggregate_transtype()

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

Definition at line 1934 of file parse_agg.c.

1938 {
1939  /* resolve actual type of transition state, if polymorphic */
1940  if (IsPolymorphicType(aggtranstype))
1941  {
1942  /* have to fetch the agg's declared input types... */
1943  Oid *declaredArgTypes;
1944  int agg_nargs;
1945 
1946  (void) get_func_signature(aggfuncid, &declaredArgTypes, &agg_nargs);
1947 
1948  /*
1949  * VARIADIC ANY aggs could have more actual than declared args, but
1950  * such extra args can't affect polymorphic type resolution.
1951  */
1952  Assert(agg_nargs <= numArguments);
1953 
1954  aggtranstype = enforce_generic_type_consistency(inputTypes,
1955  declaredArgTypes,
1956  agg_nargs,
1957  aggtranstype,
1958  false);
1959  pfree(declaredArgTypes);
1960  }
1961  return aggtranstype;
1962 }
Oid get_func_signature(Oid funcid, Oid **argtypes, int *nargs)
Definition: lsyscache.c:1696
void pfree(void *pointer)
Definition: mcxt.c:1520
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 104 of file parse_agg.c.

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

261 {
262  ListCell *lc;
263  List *args = p->args;
264  List *result_list = NIL;
266 
267  if (list_length(args) > 31)
268  ereport(ERROR,
269  (errcode(ERRCODE_TOO_MANY_ARGUMENTS),
270  errmsg("GROUPING must have fewer than 32 arguments"),
271  parser_errposition(pstate, p->location)));
272 
273  foreach(lc, args)
274  {
275  Node *current_result;
276 
277  current_result = transformExpr(pstate, (Node *) lfirst(lc), pstate->p_expr_kind);
278 
279  /* acceptability of expressions is checked later */
280 
281  result_list = lappend(result_list, current_result);
282  }
283 
284  result->args = result_list;
285  result->location = p->location;
286 
287  check_agglevels_and_constraints(pstate, (Node *) result);
288 
289  return (Node *) result;
290 }
#define makeNode(_type_)
Definition: nodes.h:155
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition: parse_expr.c:121
ParseLoc location
Definition: primnodes.h:554
ParseExprKind p_expr_kind
Definition: parse_node.h:211

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 822 of file parse_agg.c.

824 {
825  const char *err;
826  bool errkind;
827 
828  /*
829  * A window function call can't contain another one (but aggs are OK). XXX
830  * is this required by spec, or just an unimplemented feature?
831  *
832  * Note: we don't need to check the filter expression here, because the
833  * context checks done below and in transformAggregateCall would have
834  * already rejected any window funcs or aggs within the filter.
835  */
836  if (pstate->p_hasWindowFuncs &&
837  contain_windowfuncs((Node *) wfunc->args))
838  ereport(ERROR,
839  (errcode(ERRCODE_WINDOWING_ERROR),
840  errmsg("window function calls cannot be nested"),
841  parser_errposition(pstate,
842  locate_windowfunc((Node *) wfunc->args))));
843 
844  /*
845  * Check to see if the window function is in an invalid place within the
846  * query.
847  *
848  * For brevity we support two schemes for reporting an error here: set
849  * "err" to a custom message, or set "errkind" true if the error context
850  * is sufficiently identified by what ParseExprKindName will return, *and*
851  * what it will return is just a SQL keyword. (Otherwise, use a custom
852  * message to avoid creating translation problems.)
853  */
854  err = NULL;
855  errkind = false;
856  switch (pstate->p_expr_kind)
857  {
858  case EXPR_KIND_NONE:
859  Assert(false); /* can't happen */
860  break;
861  case EXPR_KIND_OTHER:
862  /* Accept window func here; caller must throw error if wanted */
863  break;
864  case EXPR_KIND_JOIN_ON:
866  err = _("window functions are not allowed in JOIN conditions");
867  break;
869  /* can't get here, but just in case, throw an error */
870  errkind = true;
871  break;
873  err = _("window functions are not allowed in functions in FROM");
874  break;
875  case EXPR_KIND_WHERE:
876  errkind = true;
877  break;
878  case EXPR_KIND_POLICY:
879  err = _("window functions are not allowed in policy expressions");
880  break;
881  case EXPR_KIND_HAVING:
882  errkind = true;
883  break;
884  case EXPR_KIND_FILTER:
885  errkind = true;
886  break;
892  err = _("window functions are not allowed in window definitions");
893  break;
895  /* okay */
896  break;
900  errkind = true;
901  break;
903  err = _("window functions are not allowed in MERGE WHEN conditions");
904  break;
905  case EXPR_KIND_GROUP_BY:
906  errkind = true;
907  break;
908  case EXPR_KIND_ORDER_BY:
909  /* okay */
910  break;
912  /* okay */
913  break;
914  case EXPR_KIND_LIMIT:
915  case EXPR_KIND_OFFSET:
916  errkind = true;
917  break;
918  case EXPR_KIND_RETURNING:
920  errkind = true;
921  break;
922  case EXPR_KIND_VALUES:
924  errkind = true;
925  break;
928  err = _("window functions are not allowed in check constraints");
929  break;
932  err = _("window functions are not allowed in DEFAULT expressions");
933  break;
935  err = _("window functions are not allowed in index expressions");
936  break;
938  err = _("window functions are not allowed in statistics expressions");
939  break;
941  err = _("window functions are not allowed in index predicates");
942  break;
944  err = _("window functions are not allowed in transform expressions");
945  break;
947  err = _("window functions are not allowed in EXECUTE parameters");
948  break;
950  err = _("window functions are not allowed in trigger WHEN conditions");
951  break;
953  err = _("window functions are not allowed in partition bound");
954  break;
956  err = _("window functions are not allowed in partition key expressions");
957  break;
959  err = _("window functions are not allowed in CALL arguments");
960  break;
962  err = _("window functions are not allowed in COPY FROM WHERE conditions");
963  break;
965  err = _("window functions are not allowed in column generation expressions");
966  break;
968  errkind = true;
969  break;
970 
971  /*
972  * There is intentionally no default: case here, so that the
973  * compiler will warn if we add a new ParseExprKind without
974  * extending this switch. If we do see an unrecognized value at
975  * runtime, the behavior will be the same as for EXPR_KIND_OTHER,
976  * which is sane anyway.
977  */
978  }
979  if (err)
980  ereport(ERROR,
981  (errcode(ERRCODE_WINDOWING_ERROR),
982  errmsg_internal("%s", err),
983  parser_errposition(pstate, wfunc->location)));
984  if (errkind)
985  ereport(ERROR,
986  (errcode(ERRCODE_WINDOWING_ERROR),
987  /* translator: %s is name of a SQL construct, eg GROUP BY */
988  errmsg("window functions are not allowed in %s",
989  ParseExprKindName(pstate->p_expr_kind)),
990  parser_errposition(pstate, wfunc->location)));
991 
992  /*
993  * If the OVER clause just specifies a window name, find that WINDOW
994  * clause (which had better be present). Otherwise, try to match all the
995  * properties of the OVER clause, and make a new entry in the p_windowdefs
996  * list if no luck.
997  */
998  if (windef->name)
999  {
1000  Index winref = 0;
1001  ListCell *lc;
1002 
1003  Assert(windef->refname == NULL &&
1004  windef->partitionClause == NIL &&
1005  windef->orderClause == NIL &&
1006  windef->frameOptions == FRAMEOPTION_DEFAULTS);
1007 
1008  foreach(lc, pstate->p_windowdefs)
1009  {
1010  WindowDef *refwin = (WindowDef *) lfirst(lc);
1011 
1012  winref++;
1013  if (refwin->name && strcmp(refwin->name, windef->name) == 0)
1014  {
1015  wfunc->winref = winref;
1016  break;
1017  }
1018  }
1019  if (lc == NULL) /* didn't find it? */
1020  ereport(ERROR,
1021  (errcode(ERRCODE_UNDEFINED_OBJECT),
1022  errmsg("window \"%s\" does not exist", windef->name),
1023  parser_errposition(pstate, windef->location)));
1024  }
1025  else
1026  {
1027  Index winref = 0;
1028  ListCell *lc;
1029 
1030  foreach(lc, pstate->p_windowdefs)
1031  {
1032  WindowDef *refwin = (WindowDef *) lfirst(lc);
1033 
1034  winref++;
1035  if (refwin->refname && windef->refname &&
1036  strcmp(refwin->refname, windef->refname) == 0)
1037  /* matched on refname */ ;
1038  else if (!refwin->refname && !windef->refname)
1039  /* matched, no refname */ ;
1040  else
1041  continue;
1042 
1043  /*
1044  * Also see similar de-duplication code in optimize_window_clauses
1045  */
1046  if (equal(refwin->partitionClause, windef->partitionClause) &&
1047  equal(refwin->orderClause, windef->orderClause) &&
1048  refwin->frameOptions == windef->frameOptions &&
1049  equal(refwin->startOffset, windef->startOffset) &&
1050  equal(refwin->endOffset, windef->endOffset))
1051  {
1052  /* found a duplicate window specification */
1053  wfunc->winref = winref;
1054  break;
1055  }
1056  }
1057  if (lc == NULL) /* didn't find it? */
1058  {
1059  pstate->p_windowdefs = lappend(pstate->p_windowdefs, windef);
1060  wfunc->winref = list_length(pstate->p_windowdefs);
1061  }
1062  }
1063 
1064  pstate->p_hasWindowFuncs = true;
1065 }
unsigned int Index
Definition: c.h:614
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1157
#define _(x)
Definition: elog.c:90
void err(int eval, const char *fmt,...)
Definition: err.c:43
const char * ParseExprKindName(ParseExprKind exprKind)
Definition: parse_expr.c:3111
@ 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:608
bool contain_windowfuncs(Node *node)
Definition: rewriteManip.c:215
int locate_windowfunc(Node *node)
Definition: rewriteManip.c:253
bool p_hasWindowFuncs
Definition: parse_node.h:224
List * p_windowdefs
Definition: parse_node.h:210
List * orderClause
Definition: parsenodes.h:567
ParseLoc location
Definition: parsenodes.h:571
List * partitionClause
Definition: parsenodes.h:566
Node * startOffset
Definition: parsenodes.h:569
char * refname
Definition: parsenodes.h:565
Node * endOffset
Definition: parsenodes.h:570
int frameOptions
Definition: parsenodes.h:568
char * name
Definition: parsenodes.h:564
List * args
Definition: primnodes.h:575
Index winref
Definition: primnodes.h:581
ParseLoc location
Definition: primnodes.h:587

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().