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

Go to the source code of this file.

Functions

void transformFromClause (ParseState *pstate, List *frmList)
 
int setTargetTable (ParseState *pstate, RangeVar *relation, bool inh, bool alsoSource, AclMode requiredPerms)
 
NodetransformWhereClause (ParseState *pstate, Node *clause, ParseExprKind exprKind, const char *constructName)
 
NodetransformLimitClause (ParseState *pstate, Node *clause, ParseExprKind exprKind, const char *constructName, LimitOption limitOption)
 
ListtransformGroupClause (ParseState *pstate, List *grouplist, List **groupingSets, List **targetlist, List *sortClause, ParseExprKind exprKind, bool useSQL99)
 
ListtransformSortClause (ParseState *pstate, List *orderlist, List **targetlist, ParseExprKind exprKind, bool useSQL99)
 
ListtransformWindowDefinitions (ParseState *pstate, List *windowdefs, List **targetlist)
 
ListtransformDistinctClause (ParseState *pstate, List **targetlist, List *sortClause, bool is_agg)
 
ListtransformDistinctOnClause (ParseState *pstate, List *distinctlist, List **targetlist, List *sortClause)
 
void transformOnConflictArbiter (ParseState *pstate, OnConflictClause *onConflictClause, List **arbiterExpr, Node **arbiterWhere, Oid *constraint)
 
ListaddTargetToSortList (ParseState *pstate, TargetEntry *tle, List *sortlist, List *targetlist, SortBy *sortby)
 
Index assignSortGroupRef (TargetEntry *tle, List *tlist)
 
bool targetIsInSortList (TargetEntry *tle, Oid sortop, List *sortList)
 

Function Documentation

◆ addTargetToSortList()

List* addTargetToSortList ( ParseState pstate,
TargetEntry tle,
List sortlist,
List targetlist,
SortBy sortby 
)

Definition at line 3387 of file parse_clause.c.

3389 {
3390  Oid restype = exprType((Node *) tle->expr);
3391  Oid sortop;
3392  Oid eqop;
3393  bool hashable;
3394  bool reverse;
3395  int location;
3396  ParseCallbackState pcbstate;
3397 
3398  /* if tlist item is an UNKNOWN literal, change it to TEXT */
3399  if (restype == UNKNOWNOID)
3400  {
3401  tle->expr = (Expr *) coerce_type(pstate, (Node *) tle->expr,
3402  restype, TEXTOID, -1,
3405  -1);
3406  restype = TEXTOID;
3407  }
3408 
3409  /*
3410  * Rather than clutter the API of get_sort_group_operators and the other
3411  * functions we're about to use, make use of error context callback to
3412  * mark any error reports with a parse position. We point to the operator
3413  * location if present, else to the expression being sorted. (NB: use the
3414  * original untransformed expression here; the TLE entry might well point
3415  * at a duplicate expression in the regular SELECT list.)
3416  */
3417  location = sortby->location;
3418  if (location < 0)
3419  location = exprLocation(sortby->node);
3420  setup_parser_errposition_callback(&pcbstate, pstate, location);
3421 
3422  /* determine the sortop, eqop, and directionality */
3423  switch (sortby->sortby_dir)
3424  {
3425  case SORTBY_DEFAULT:
3426  case SORTBY_ASC:
3427  get_sort_group_operators(restype,
3428  true, true, false,
3429  &sortop, &eqop, NULL,
3430  &hashable);
3431  reverse = false;
3432  break;
3433  case SORTBY_DESC:
3434  get_sort_group_operators(restype,
3435  false, true, true,
3436  NULL, &eqop, &sortop,
3437  &hashable);
3438  reverse = true;
3439  break;
3440  case SORTBY_USING:
3441  Assert(sortby->useOp != NIL);
3442  sortop = compatible_oper_opid(sortby->useOp,
3443  restype,
3444  restype,
3445  false);
3446 
3447  /*
3448  * Verify it's a valid ordering operator, fetch the corresponding
3449  * equality operator, and determine whether to consider it like
3450  * ASC or DESC.
3451  */
3452  eqop = get_equality_op_for_ordering_op(sortop, &reverse);
3453  if (!OidIsValid(eqop))
3454  ereport(ERROR,
3455  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
3456  errmsg("operator %s is not a valid ordering operator",
3457  strVal(llast(sortby->useOp))),
3458  errhint("Ordering operators must be \"<\" or \">\" members of btree operator families.")));
3459 
3460  /*
3461  * Also see if the equality operator is hashable.
3462  */
3463  hashable = op_hashjoinable(eqop, restype);
3464  break;
3465  default:
3466  elog(ERROR, "unrecognized sortby_dir: %d", sortby->sortby_dir);
3467  sortop = InvalidOid; /* keep compiler quiet */
3468  eqop = InvalidOid;
3469  hashable = false;
3470  reverse = false;
3471  break;
3472  }
3473 
3475 
3476  /* avoid making duplicate sortlist entries */
3477  if (!targetIsInSortList(tle, sortop, sortlist))
3478  {
3480 
3481  sortcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist);
3482 
3483  sortcl->eqop = eqop;
3484  sortcl->sortop = sortop;
3485  sortcl->hashable = hashable;
3486 
3487  switch (sortby->sortby_nulls)
3488  {
3489  case SORTBY_NULLS_DEFAULT:
3490  /* NULLS FIRST is default for DESC; other way for ASC */
3491  sortcl->nulls_first = reverse;
3492  break;
3493  case SORTBY_NULLS_FIRST:
3494  sortcl->nulls_first = true;
3495  break;
3496  case SORTBY_NULLS_LAST:
3497  sortcl->nulls_first = false;
3498  break;
3499  default:
3500  elog(ERROR, "unrecognized sortby_nulls: %d",
3501  sortby->sortby_nulls);
3502  break;
3503  }
3504 
3505  sortlist = lappend(sortlist, sortcl);
3506  }
3507 
3508  return sortlist;
3509 }
#define OidIsValid(objectId)
Definition: c.h:759
int errhint(const char *fmt,...)
Definition: elog.c:1316
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
Definition: list.c:338
Oid get_equality_op_for_ordering_op(Oid opno, bool *reverse)
Definition: lsyscache.c:266
bool op_hashjoinable(Oid opno, Oid inputtype)
Definition: lsyscache.c:1419
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1314
#define makeNode(_type_)
Definition: nodes.h:176
Index assignSortGroupRef(TargetEntry *tle, List *tlist)
bool targetIsInSortList(TargetEntry *tle, Oid sortop, List *sortList)
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:157
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition: parse_node.c:161
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Definition: parse_node.c:145
void get_sort_group_operators(Oid argtype, bool needLT, bool needEQ, bool needGT, Oid *ltOpr, Oid *eqOpr, Oid *gtOpr, bool *isHashable)
Definition: parse_oper.c:192
Oid compatible_oper_opid(List *op, Oid arg1, Oid arg2, bool noError)
Definition: parse_oper.c:499
@ SORTBY_NULLS_DEFAULT
Definition: parsenodes.h:61
@ SORTBY_NULLS_LAST
Definition: parsenodes.h:63
@ SORTBY_NULLS_FIRST
Definition: parsenodes.h:62
@ SORTBY_USING
Definition: parsenodes.h:56
@ SORTBY_DESC
Definition: parsenodes.h:55
@ SORTBY_ASC
Definition: parsenodes.h:54
@ SORTBY_DEFAULT
Definition: parsenodes.h:53
#define llast(l)
Definition: pg_list.h:198
#define NIL
Definition: pg_list.h:68
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
@ COERCE_IMPLICIT_CAST
Definition: primnodes.h:663
@ COERCION_IMPLICIT
Definition: primnodes.h:641
Definition: nodes.h:129
SortByNulls sortby_nulls
Definition: parsenodes.h:546
Node * node
Definition: parsenodes.h:544
List * useOp
Definition: parsenodes.h:547
SortByDir sortby_dir
Definition: parsenodes.h:545
int location
Definition: parsenodes.h:548
Index tleSortGroupRef
Definition: parsenodes.h:1393
Expr * expr
Definition: primnodes.h:1886
#define strVal(v)
Definition: value.h:82

References Assert(), assignSortGroupRef(), cancel_parser_errposition_callback(), COERCE_IMPLICIT_CAST, coerce_type(), COERCION_IMPLICIT, compatible_oper_opid(), elog(), SortGroupClause::eqop, ereport, errcode(), errhint(), errmsg(), ERROR, TargetEntry::expr, exprLocation(), exprType(), get_equality_op_for_ordering_op(), get_sort_group_operators(), InvalidOid, lappend(), llast, SortBy::location, makeNode, NIL, SortBy::node, SortGroupClause::nulls_first, OidIsValid, op_hashjoinable(), setup_parser_errposition_callback(), SORTBY_ASC, SORTBY_DEFAULT, SORTBY_DESC, SortBy::sortby_dir, SortBy::sortby_nulls, SORTBY_NULLS_DEFAULT, SORTBY_NULLS_FIRST, SORTBY_NULLS_LAST, SORTBY_USING, SortGroupClause::sortop, strVal, targetIsInSortList(), SortGroupClause::tleSortGroupRef, and SortBy::useOp.

Referenced by transformAggregateCall(), and transformSortClause().

◆ assignSortGroupRef()

Index assignSortGroupRef ( TargetEntry tle,
List tlist 
)

Definition at line 3585 of file parse_clause.c.

3586 {
3587  Index maxRef;
3588  ListCell *l;
3589 
3590  if (tle->ressortgroupref) /* already has one? */
3591  return tle->ressortgroupref;
3592 
3593  /* easiest way to pick an unused refnumber: max used + 1 */
3594  maxRef = 0;
3595  foreach(l, tlist)
3596  {
3597  Index ref = ((TargetEntry *) lfirst(l))->ressortgroupref;
3598 
3599  if (ref > maxRef)
3600  maxRef = ref;
3601  }
3602  tle->ressortgroupref = maxRef + 1;
3603  return tle->ressortgroupref;
3604 }
unsigned int Index
Definition: c.h:598
#define lfirst(lc)
Definition: pg_list.h:172
Index ressortgroupref
Definition: primnodes.h:1892

References lfirst, and TargetEntry::ressortgroupref.

Referenced by addTargetToGroupList(), addTargetToSortList(), build_minmax_path(), create_unique_plan(), and transformDistinctOnClause().

◆ setTargetTable()

int setTargetTable ( ParseState pstate,
RangeVar relation,
bool  inh,
bool  alsoSource,
AclMode  requiredPerms 
)

Definition at line 182 of file parse_clause.c.

184 {
185  ParseNamespaceItem *nsitem;
186 
187  /*
188  * ENRs hide tables of the same name, so we need to check for them first.
189  * In contrast, CTEs don't hide tables (for this purpose).
190  */
191  if (relation->schemaname == NULL &&
192  scanNameSpaceForENR(pstate, relation->relname))
193  ereport(ERROR,
194  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
195  errmsg("relation \"%s\" cannot be the target of a modifying statement",
196  relation->relname)));
197 
198  /* Close old target; this could only happen for multi-action rules */
199  if (pstate->p_target_relation != NULL)
201 
202  /*
203  * Open target rel and grab suitable lock (which we will hold till end of
204  * transaction).
205  *
206  * free_parsestate() will eventually do the corresponding table_close(),
207  * but *not* release the lock.
208  */
209  pstate->p_target_relation = parserOpenTable(pstate, relation,
211 
212  /*
213  * Now build an RTE and a ParseNamespaceItem.
214  */
215  nsitem = addRangeTableEntryForRelation(pstate, pstate->p_target_relation,
217  relation->alias, inh, false);
218 
219  /* remember the RTE/nsitem as being the query target */
220  pstate->p_target_nsitem = nsitem;
221 
222  /*
223  * Override addRangeTableEntry's default ACL_SELECT permissions check, and
224  * instead mark target table as requiring exactly the specified
225  * permissions.
226  *
227  * If we find an explicit reference to the rel later during parse
228  * analysis, we will add the ACL_SELECT bit back again; see
229  * markVarForSelectPriv and its callers.
230  */
231  nsitem->p_perminfo->requiredPerms = requiredPerms;
232 
233  /*
234  * If UPDATE/DELETE, add table to joinlist and namespace.
235  */
236  if (alsoSource)
237  addNSItemToQuery(pstate, nsitem, true, true, true);
238 
239  return nsitem->p_rtindex;
240 }
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
Relation parserOpenTable(ParseState *pstate, const RangeVar *relation, int lockmode)
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
bool scanNameSpaceForENR(ParseState *pstate, const char *refname)
RTEPermissionInfo * p_perminfo
Definition: parse_node.h:288
ParseNamespaceItem * p_target_nsitem
Definition: parse_node.h:207
Relation p_target_relation
Definition: parse_node.h:206
AclMode requiredPerms
Definition: parsenodes.h:1246
char * relname
Definition: primnodes.h:74
Alias * alias
Definition: primnodes.h:83
char * schemaname
Definition: primnodes.h:71
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126

References addNSItemToQuery(), addRangeTableEntryForRelation(), RangeVar::alias, ereport, errcode(), errmsg(), ERROR, NoLock, ParseNamespaceItem::p_perminfo, ParseNamespaceItem::p_rtindex, ParseState::p_target_nsitem, ParseState::p_target_relation, parserOpenTable(), RangeVar::relname, RTEPermissionInfo::requiredPerms, RowExclusiveLock, scanNameSpaceForENR(), RangeVar::schemaname, and table_close().

Referenced by transformDeleteStmt(), transformInsertStmt(), transformMergeStmt(), and transformUpdateStmt().

◆ targetIsInSortList()

bool targetIsInSortList ( TargetEntry tle,
Oid  sortop,
List sortList 
)

Definition at line 3626 of file parse_clause.c.

3627 {
3628  Index ref = tle->ressortgroupref;
3629  ListCell *l;
3630 
3631  /* no need to scan list if tle has no marker */
3632  if (ref == 0)
3633  return false;
3634 
3635  foreach(l, sortList)
3636  {
3637  SortGroupClause *scl = (SortGroupClause *) lfirst(l);
3638 
3639  if (scl->tleSortGroupRef == ref &&
3640  (sortop == InvalidOid ||
3641  sortop == scl->sortop ||
3642  sortop == get_commutator(scl->sortop)))
3643  return true;
3644  }
3645  return false;
3646 }
Oid get_commutator(Oid opno)
Definition: lsyscache.c:1491

References get_commutator(), InvalidOid, lfirst, TargetEntry::ressortgroupref, SortGroupClause::sortop, and SortGroupClause::tleSortGroupRef.

Referenced by addTargetToGroupList(), addTargetToSortList(), check_output_expressions(), examine_simple_variable(), targetIsInAllPartitionLists(), transformDistinctOnClause(), and transformGroupClauseExpr().

◆ transformDistinctClause()

List* transformDistinctClause ( ParseState pstate,
List **  targetlist,
List sortClause,
bool  is_agg 
)

Definition at line 2979 of file parse_clause.c.

2981 {
2982  List *result = NIL;
2983  ListCell *slitem;
2984  ListCell *tlitem;
2985 
2986  /*
2987  * The distinctClause should consist of all ORDER BY items followed by all
2988  * other non-resjunk targetlist items. There must not be any resjunk
2989  * ORDER BY items --- that would imply that we are sorting by a value that
2990  * isn't necessarily unique within a DISTINCT group, so the results
2991  * wouldn't be well-defined. This construction ensures we follow the rule
2992  * that sortClause and distinctClause match; in fact the sortClause will
2993  * always be a prefix of distinctClause.
2994  *
2995  * Note a corner case: the same TLE could be in the ORDER BY list multiple
2996  * times with different sortops. We have to include it in the
2997  * distinctClause the same way to preserve the prefix property. The net
2998  * effect will be that the TLE value will be made unique according to both
2999  * sortops.
3000  */
3001  foreach(slitem, sortClause)
3002  {
3003  SortGroupClause *scl = (SortGroupClause *) lfirst(slitem);
3004  TargetEntry *tle = get_sortgroupclause_tle(scl, *targetlist);
3005 
3006  if (tle->resjunk)
3007  ereport(ERROR,
3008  (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3009  is_agg ?
3010  errmsg("in an aggregate with DISTINCT, ORDER BY expressions must appear in argument list") :
3011  errmsg("for SELECT DISTINCT, ORDER BY expressions must appear in select list"),
3012  parser_errposition(pstate,
3013  exprLocation((Node *) tle->expr))));
3014  result = lappend(result, copyObject(scl));
3015  }
3016 
3017  /*
3018  * Now add any remaining non-resjunk tlist items, using default sort/group
3019  * semantics for their data types.
3020  */
3021  foreach(tlitem, *targetlist)
3022  {
3023  TargetEntry *tle = (TargetEntry *) lfirst(tlitem);
3024 
3025  if (tle->resjunk)
3026  continue; /* ignore junk */
3027  result = addTargetToGroupList(pstate, tle,
3028  result, *targetlist,
3029  exprLocation((Node *) tle->expr));
3030  }
3031 
3032  /*
3033  * Complain if we found nothing to make DISTINCT. Returning an empty list
3034  * would cause the parsed Query to look like it didn't have DISTINCT, with
3035  * results that would probably surprise the user. Note: this case is
3036  * presently impossible for aggregates because of grammar restrictions,
3037  * but we check anyway.
3038  */
3039  if (result == NIL)
3040  ereport(ERROR,
3041  (errcode(ERRCODE_SYNTAX_ERROR),
3042  is_agg ?
3043  errmsg("an aggregate with DISTINCT must have at least one argument") :
3044  errmsg("SELECT DISTINCT must have at least one column")));
3045 
3046  return result;
3047 }
#define copyObject(obj)
Definition: nodes.h:244
static List * addTargetToGroupList(ParseState *pstate, TargetEntry *tle, List *grouplist, List *targetlist, int location)
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:111
Definition: pg_list.h:54
TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:367

References addTargetToGroupList(), copyObject, ereport, errcode(), errmsg(), ERROR, TargetEntry::expr, exprLocation(), get_sortgroupclause_tle(), lappend(), lfirst, NIL, and parser_errposition().

Referenced by transformAggregateCall(), transformPLAssignStmt(), and transformSelectStmt().

◆ transformDistinctOnClause()

List* transformDistinctOnClause ( ParseState pstate,
List distinctlist,
List **  targetlist,
List sortClause 
)

Definition at line 3063 of file parse_clause.c.

3065 {
3066  List *result = NIL;
3067  List *sortgrouprefs = NIL;
3068  bool skipped_sortitem;
3069  ListCell *lc;
3070  ListCell *lc2;
3071 
3072  /*
3073  * Add all the DISTINCT ON expressions to the tlist (if not already
3074  * present, they are added as resjunk items). Assign sortgroupref numbers
3075  * to them, and make a list of these numbers. (NB: we rely below on the
3076  * sortgrouprefs list being one-for-one with the original distinctlist.
3077  * Also notice that we could have duplicate DISTINCT ON expressions and
3078  * hence duplicate entries in sortgrouprefs.)
3079  */
3080  foreach(lc, distinctlist)
3081  {
3082  Node *dexpr = (Node *) lfirst(lc);
3083  int sortgroupref;
3084  TargetEntry *tle;
3085 
3086  tle = findTargetlistEntrySQL92(pstate, dexpr, targetlist,
3088  sortgroupref = assignSortGroupRef(tle, *targetlist);
3089  sortgrouprefs = lappend_int(sortgrouprefs, sortgroupref);
3090  }
3091 
3092  /*
3093  * If the user writes both DISTINCT ON and ORDER BY, adopt the sorting
3094  * semantics from ORDER BY items that match DISTINCT ON items, and also
3095  * adopt their column sort order. We insist that the distinctClause and
3096  * sortClause match, so throw error if we find the need to add any more
3097  * distinctClause items after we've skipped an ORDER BY item that wasn't
3098  * in DISTINCT ON.
3099  */
3100  skipped_sortitem = false;
3101  foreach(lc, sortClause)
3102  {
3103  SortGroupClause *scl = (SortGroupClause *) lfirst(lc);
3104 
3105  if (list_member_int(sortgrouprefs, scl->tleSortGroupRef))
3106  {
3107  if (skipped_sortitem)
3108  ereport(ERROR,
3109  (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3110  errmsg("SELECT DISTINCT ON expressions must match initial ORDER BY expressions"),
3111  parser_errposition(pstate,
3113  sortgrouprefs,
3114  distinctlist))));
3115  else
3116  result = lappend(result, copyObject(scl));
3117  }
3118  else
3119  skipped_sortitem = true;
3120  }
3121 
3122  /*
3123  * Now add any remaining DISTINCT ON items, using default sort/group
3124  * semantics for their data types. (Note: this is pretty questionable; if
3125  * the ORDER BY list doesn't include all the DISTINCT ON items and more
3126  * besides, you certainly aren't using DISTINCT ON in the intended way,
3127  * and you probably aren't going to get consistent results. It might be
3128  * better to throw an error or warning here. But historically we've
3129  * allowed it, so keep doing so.)
3130  */
3131  forboth(lc, distinctlist, lc2, sortgrouprefs)
3132  {
3133  Node *dexpr = (Node *) lfirst(lc);
3134  int sortgroupref = lfirst_int(lc2);
3135  TargetEntry *tle = get_sortgroupref_tle(sortgroupref, *targetlist);
3136 
3137  if (targetIsInSortList(tle, InvalidOid, result))
3138  continue; /* already in list (with some semantics) */
3139  if (skipped_sortitem)
3140  ereport(ERROR,
3141  (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3142  errmsg("SELECT DISTINCT ON expressions must match initial ORDER BY expressions"),
3143  parser_errposition(pstate, exprLocation(dexpr))));
3144  result = addTargetToGroupList(pstate, tle,
3145  result, *targetlist,
3146  exprLocation(dexpr));
3147  }
3148 
3149  /*
3150  * An empty result list is impossible here because of grammar
3151  * restrictions.
3152  */
3153  Assert(result != NIL);
3154 
3155  return result;
3156 }
List * lappend_int(List *list, int datum)
Definition: list.c:356
bool list_member_int(const List *list, int datum)
Definition: list.c:701
static int get_matching_location(int sortgroupref, List *sortgrouprefs, List *exprs)
static TargetEntry * findTargetlistEntrySQL92(ParseState *pstate, Node *node, List **tlist, ParseExprKind exprKind)
@ EXPR_KIND_DISTINCT_ON
Definition: parse_node.h:61
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:467
#define lfirst_int(lc)
Definition: pg_list.h:173
TargetEntry * get_sortgroupref_tle(Index sortref, List *targetList)
Definition: tlist.c:345

References addTargetToGroupList(), Assert(), assignSortGroupRef(), copyObject, ereport, errcode(), errmsg(), ERROR, EXPR_KIND_DISTINCT_ON, exprLocation(), findTargetlistEntrySQL92(), forboth, get_matching_location(), get_sortgroupref_tle(), InvalidOid, lappend(), lappend_int(), lfirst, lfirst_int, list_member_int(), NIL, parser_errposition(), targetIsInSortList(), and SortGroupClause::tleSortGroupRef.

Referenced by transformPLAssignStmt(), and transformSelectStmt().

◆ transformFromClause()

void transformFromClause ( ParseState pstate,
List frmList 
)

Definition at line 116 of file parse_clause.c.

117 {
118  ListCell *fl;
119 
120  /*
121  * The grammar will have produced a list of RangeVars, RangeSubselects,
122  * RangeFunctions, and/or JoinExprs. Transform each one (possibly adding
123  * entries to the rtable), check for duplicate refnames, and then add it
124  * to the joinlist and namespace.
125  *
126  * Note we must process the items left-to-right for proper handling of
127  * LATERAL references.
128  */
129  foreach(fl, frmList)
130  {
131  Node *n = lfirst(fl);
132  ParseNamespaceItem *nsitem;
133  List *namespace;
134 
135  n = transformFromClauseItem(pstate, n,
136  &nsitem,
137  &namespace);
138 
139  checkNameSpaceConflicts(pstate, pstate->p_namespace, namespace);
140 
141  /* Mark the new namespace items as visible only to LATERAL */
142  setNamespaceLateralState(namespace, true, true);
143 
144  pstate->p_joinlist = lappend(pstate->p_joinlist, n);
145  pstate->p_namespace = list_concat(pstate->p_namespace, namespace);
146  }
147 
148  /*
149  * We're done parsing the FROM list, so make all namespace items
150  * unconditionally visible. Note that this will also reset lateral_only
151  * for any namespace items that were already present when we were called;
152  * but those should have been that way already.
153  */
154  setNamespaceLateralState(pstate->p_namespace, false, true);
155 }
List * list_concat(List *list1, const List *list2)
Definition: list.c:560
static void setNamespaceLateralState(List *namespace, bool lateral_only, bool lateral_ok)
static Node * transformFromClauseItem(ParseState *pstate, Node *n, ParseNamespaceItem **top_nsitem, List **namespace)
void checkNameSpaceConflicts(ParseState *pstate, List *namespace1, List *namespace2)
List * p_namespace
Definition: parse_node.h:200
List * p_joinlist
Definition: parse_node.h:198

References checkNameSpaceConflicts(), lappend(), lfirst, list_concat(), ParseState::p_joinlist, ParseState::p_namespace, setNamespaceLateralState(), and transformFromClauseItem().

Referenced by transformDeleteStmt(), transformMergeStmt(), transformPLAssignStmt(), transformSelectStmt(), and transformUpdateStmt().

◆ transformGroupClause()

List* transformGroupClause ( ParseState pstate,
List grouplist,
List **  groupingSets,
List **  targetlist,
List sortClause,
ParseExprKind  exprKind,
bool  useSQL99 
)

Definition at line 2625 of file parse_clause.c.

2628 {
2629  List *result = NIL;
2630  List *flat_grouplist;
2631  List *gsets = NIL;
2632  ListCell *gl;
2633  bool hasGroupingSets = false;
2634  Bitmapset *seen_local = NULL;
2635 
2636  /*
2637  * Recursively flatten implicit RowExprs. (Technically this is only needed
2638  * for GROUP BY, per the syntax rules for grouping sets, but we do it
2639  * anyway.)
2640  */
2641  flat_grouplist = (List *) flatten_grouping_sets((Node *) grouplist,
2642  true,
2643  &hasGroupingSets);
2644 
2645  /*
2646  * If the list is now empty, but hasGroupingSets is true, it's because we
2647  * elided redundant empty grouping sets. Restore a single empty grouping
2648  * set to leave a canonical form: GROUP BY ()
2649  */
2650 
2651  if (flat_grouplist == NIL && hasGroupingSets)
2652  {
2654  NIL,
2655  exprLocation((Node *) grouplist)));
2656  }
2657 
2658  foreach(gl, flat_grouplist)
2659  {
2660  Node *gexpr = (Node *) lfirst(gl);
2661 
2662  if (IsA(gexpr, GroupingSet))
2663  {
2664  GroupingSet *gset = (GroupingSet *) gexpr;
2665 
2666  switch (gset->kind)
2667  {
2668  case GROUPING_SET_EMPTY:
2669  gsets = lappend(gsets, gset);
2670  break;
2671  case GROUPING_SET_SIMPLE:
2672  /* can't happen */
2673  Assert(false);
2674  break;
2675  case GROUPING_SET_SETS:
2676  case GROUPING_SET_CUBE:
2677  case GROUPING_SET_ROLLUP:
2678  gsets = lappend(gsets,
2679  transformGroupingSet(&result,
2680  pstate, gset,
2681  targetlist, sortClause,
2682  exprKind, useSQL99, true));
2683  break;
2684  }
2685  }
2686  else
2687  {
2688  Index ref = transformGroupClauseExpr(&result, seen_local,
2689  pstate, gexpr,
2690  targetlist, sortClause,
2691  exprKind, useSQL99, true);
2692 
2693  if (ref > 0)
2694  {
2695  seen_local = bms_add_member(seen_local, ref);
2696  if (hasGroupingSets)
2697  gsets = lappend(gsets,
2699  list_make1_int(ref),
2700  exprLocation(gexpr)));
2701  }
2702  }
2703  }
2704 
2705  /* parser should prevent this */
2706  Assert(gsets == NIL || groupingSets != NULL);
2707 
2708  if (groupingSets)
2709  *groupingSets = gsets;
2710 
2711  return result;
2712 }
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:755
GroupingSet * makeGroupingSet(GroupingSetKind kind, List *content, int location)
Definition: makefuncs.c:805
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
static Node * transformGroupingSet(List **flatresult, ParseState *pstate, GroupingSet *gset, List **targetlist, List *sortClause, ParseExprKind exprKind, bool useSQL99, bool toplevel)
static Node * flatten_grouping_sets(Node *expr, bool toplevel, bool *hasGroupingSets)
static Index transformGroupClauseExpr(List **flatresult, Bitmapset *seen_local, ParseState *pstate, Node *gexpr, List **targetlist, List *sortClause, ParseExprKind exprKind, bool useSQL99, bool toplevel)
@ GROUPING_SET_CUBE
Definition: parsenodes.h:1456
@ GROUPING_SET_SIMPLE
Definition: parsenodes.h:1454
@ GROUPING_SET_ROLLUP
Definition: parsenodes.h:1455
@ GROUPING_SET_SETS
Definition: parsenodes.h:1457
@ GROUPING_SET_EMPTY
Definition: parsenodes.h:1453
#define list_make1(x1)
Definition: pg_list.h:212
#define list_make1_int(x1)
Definition: pg_list.h:227

References Assert(), bms_add_member(), exprLocation(), flatten_grouping_sets(), GROUPING_SET_CUBE, GROUPING_SET_EMPTY, GROUPING_SET_ROLLUP, GROUPING_SET_SETS, GROUPING_SET_SIMPLE, IsA, lappend(), lfirst, list_make1, list_make1_int, makeGroupingSet(), NIL, transformGroupClauseExpr(), and transformGroupingSet().

Referenced by transformPLAssignStmt(), transformSelectStmt(), and transformWindowDefinitions().

◆ transformLimitClause()

Node* transformLimitClause ( ParseState pstate,
Node clause,
ParseExprKind  exprKind,
const char *  constructName,
LimitOption  limitOption 
)

Definition at line 1874 of file parse_clause.c.

1877 {
1878  Node *qual;
1879 
1880  if (clause == NULL)
1881  return NULL;
1882 
1883  qual = transformExpr(pstate, clause, exprKind);
1884 
1885  qual = coerce_to_specific_type(pstate, qual, INT8OID, constructName);
1886 
1887  /* LIMIT can't refer to any variables of the current query */
1888  checkExprIsVarFree(pstate, qual, constructName);
1889 
1890  /*
1891  * Don't allow NULLs in FETCH FIRST .. WITH TIES. This test is ugly and
1892  * extremely simplistic, in that you can pass a NULL anyway by hiding it
1893  * inside an expression -- but this protects ruleutils against emitting an
1894  * unadorned NULL that's not accepted back by the grammar.
1895  */
1896  if (exprKind == EXPR_KIND_LIMIT && limitOption == LIMIT_OPTION_WITH_TIES &&
1897  IsA(clause, A_Const) && castNode(A_Const, clause)->isnull)
1898  ereport(ERROR,
1899  (errcode(ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE),
1900  errmsg("row count cannot be null in FETCH FIRST ... WITH TIES clause")));
1901 
1902  return qual;
1903 }
@ LIMIT_OPTION_WITH_TIES
Definition: nodes.h:442
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
static void checkExprIsVarFree(ParseState *pstate, Node *n, const char *constructName)
Node * coerce_to_specific_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *constructName)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition: parse_expr.c:106
@ EXPR_KIND_LIMIT
Definition: parse_node.h:62

References castNode, checkExprIsVarFree(), coerce_to_specific_type(), ereport, errcode(), errmsg(), ERROR, EXPR_KIND_LIMIT, IsA, LIMIT_OPTION_WITH_TIES, and transformExpr().

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

◆ transformOnConflictArbiter()

void transformOnConflictArbiter ( ParseState pstate,
OnConflictClause onConflictClause,
List **  arbiterExpr,
Node **  arbiterWhere,
Oid constraint 
)

Definition at line 3291 of file parse_clause.c.

3295 {
3296  InferClause *infer = onConflictClause->infer;
3297 
3298  *arbiterExpr = NIL;
3299  *arbiterWhere = NULL;
3300  *constraint = InvalidOid;
3301 
3302  if (onConflictClause->action == ONCONFLICT_UPDATE && !infer)
3303  ereport(ERROR,
3304  (errcode(ERRCODE_SYNTAX_ERROR),
3305  errmsg("ON CONFLICT DO UPDATE requires inference specification or constraint name"),
3306  errhint("For example, ON CONFLICT (column_name)."),
3307  parser_errposition(pstate,
3308  exprLocation((Node *) onConflictClause))));
3309 
3310  /*
3311  * To simplify certain aspects of its design, speculative insertion into
3312  * system catalogs is disallowed
3313  */
3314  if (IsCatalogRelation(pstate->p_target_relation))
3315  ereport(ERROR,
3316  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3317  errmsg("ON CONFLICT is not supported with system catalog tables"),
3318  parser_errposition(pstate,
3319  exprLocation((Node *) onConflictClause))));
3320 
3321  /* Same applies to table used by logical decoding as catalog table */
3323  ereport(ERROR,
3324  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3325  errmsg("ON CONFLICT is not supported on table \"%s\" used as a catalog table",
3327  parser_errposition(pstate,
3328  exprLocation((Node *) onConflictClause))));
3329 
3330  /* ON CONFLICT DO NOTHING does not require an inference clause */
3331  if (infer)
3332  {
3333  if (infer->indexElems)
3334  *arbiterExpr = resolve_unique_index_expr(pstate, infer,
3335  pstate->p_target_relation);
3336 
3337  /*
3338  * Handling inference WHERE clause (for partial unique index
3339  * inference)
3340  */
3341  if (infer->whereClause)
3342  *arbiterWhere = transformExpr(pstate, infer->whereClause,
3344 
3345  /*
3346  * If the arbiter is specified by constraint name, get the constraint
3347  * OID and mark the constrained columns as requiring SELECT privilege,
3348  * in the same way as would have happened if the arbiter had been
3349  * specified by explicit reference to the constraint's index columns.
3350  */
3351  if (infer->conname)
3352  {
3353  Oid relid = RelationGetRelid(pstate->p_target_relation);
3354  RTEPermissionInfo *perminfo = pstate->p_target_nsitem->p_perminfo;
3355  Bitmapset *conattnos;
3356 
3357  conattnos = get_relation_constraint_attnos(relid, infer->conname,
3358  false, constraint);
3359 
3360  /* Make sure the rel as a whole is marked for SELECT access */
3361  perminfo->requiredPerms |= ACL_SELECT;
3362  /* Mark the constrained columns as requiring SELECT access */
3363  perminfo->selectedCols = bms_add_members(perminfo->selectedCols,
3364  conattnos);
3365  }
3366  }
3367 
3368  /*
3369  * It's convenient to form a list of expressions based on the
3370  * representation used by CREATE INDEX, since the same restrictions are
3371  * appropriate (e.g. on subqueries). However, from here on, a dedicated
3372  * primnode representation is used for inference elements, and so
3373  * assign_query_collations() can be trusted to do the right thing with the
3374  * post parse analysis query tree inference clause representation.
3375  */
3376 }
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:818
bool IsCatalogRelation(Relation relation)
Definition: catalog.c:105
@ ONCONFLICT_UPDATE
Definition: nodes.h:430
static List * resolve_unique_index_expr(ParseState *pstate, InferClause *infer, Relation heapRel)
@ EXPR_KIND_INDEX_PREDICATE
Definition: parse_node.h:72
#define ACL_SELECT
Definition: parsenodes.h:84
Bitmapset * get_relation_constraint_attnos(Oid relid, const char *conname, bool missing_ok, Oid *constraintOid)
#define RelationGetRelid(relation)
Definition: rel.h:504
#define RelationIsUsedAsCatalogTable(relation)
Definition: rel.h:385
#define RelationGetRelationName(relation)
Definition: rel.h:538
char * conname
Definition: parsenodes.h:1565
List * indexElems
Definition: parsenodes.h:1563
Node * whereClause
Definition: parsenodes.h:1564
InferClause * infer
Definition: parsenodes.h:1579
OnConflictAction action
Definition: parsenodes.h:1578
Bitmapset * selectedCols
Definition: parsenodes.h:1248

References ACL_SELECT, OnConflictClause::action, bms_add_members(), InferClause::conname, ereport, errcode(), errhint(), errmsg(), ERROR, EXPR_KIND_INDEX_PREDICATE, exprLocation(), get_relation_constraint_attnos(), InferClause::indexElems, OnConflictClause::infer, InvalidOid, IsCatalogRelation(), NIL, ONCONFLICT_UPDATE, ParseNamespaceItem::p_perminfo, ParseState::p_target_nsitem, ParseState::p_target_relation, parser_errposition(), RelationGetRelationName, RelationGetRelid, RelationIsUsedAsCatalogTable, RTEPermissionInfo::requiredPerms, resolve_unique_index_expr(), RTEPermissionInfo::selectedCols, transformExpr(), and InferClause::whereClause.

Referenced by transformOnConflictClause().

◆ transformSortClause()

List* transformSortClause ( ParseState pstate,
List orderlist,
List **  targetlist,
ParseExprKind  exprKind,
bool  useSQL99 
)

Definition at line 2725 of file parse_clause.c.

2730 {
2731  List *sortlist = NIL;
2732  ListCell *olitem;
2733 
2734  foreach(olitem, orderlist)
2735  {
2736  SortBy *sortby = (SortBy *) lfirst(olitem);
2737  TargetEntry *tle;
2738 
2739  if (useSQL99)
2740  tle = findTargetlistEntrySQL99(pstate, sortby->node,
2741  targetlist, exprKind);
2742  else
2743  tle = findTargetlistEntrySQL92(pstate, sortby->node,
2744  targetlist, exprKind);
2745 
2746  sortlist = addTargetToSortList(pstate, tle,
2747  sortlist, *targetlist, sortby);
2748  }
2749 
2750  return sortlist;
2751 }
List * addTargetToSortList(ParseState *pstate, TargetEntry *tle, List *sortlist, List *targetlist, SortBy *sortby)
static TargetEntry * findTargetlistEntrySQL99(ParseState *pstate, Node *node, List **tlist, ParseExprKind exprKind)

References addTargetToSortList(), findTargetlistEntrySQL92(), findTargetlistEntrySQL99(), lfirst, NIL, and SortBy::node.

Referenced by transformAggregateCall(), transformPLAssignStmt(), transformSelectStmt(), transformSetOperationStmt(), transformValuesClause(), and transformWindowDefinitions().

◆ transformWhereClause()

Node* transformWhereClause ( ParseState pstate,
Node clause,
ParseExprKind  exprKind,
const char *  constructName 
)

Definition at line 1847 of file parse_clause.c.

1849 {
1850  Node *qual;
1851 
1852  if (clause == NULL)
1853  return NULL;
1854 
1855  qual = transformExpr(pstate, clause, exprKind);
1856 
1857  qual = coerce_to_boolean(pstate, qual, constructName);
1858 
1859  return qual;
1860 }
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)

References coerce_to_boolean(), and transformExpr().

Referenced by AlterPolicy(), CreatePolicy(), CreateTriggerFiringOn(), ParseFuncOrColumn(), test_rls_hooks_permissive(), test_rls_hooks_restrictive(), transformDeleteStmt(), transformIndexStmt(), transformJoinOnClause(), transformJsonAggConstructor(), transformMergeStmt(), transformOnConflictClause(), transformPLAssignStmt(), TransformPubWhereClauses(), transformRuleStmt(), transformSelectStmt(), and transformUpdateStmt().

◆ transformWindowDefinitions()

List* transformWindowDefinitions ( ParseState pstate,
List windowdefs,
List **  targetlist 
)

Definition at line 2758 of file parse_clause.c.

2761 {
2762  List *result = NIL;
2763  Index winref = 0;
2764  ListCell *lc;
2765 
2766  foreach(lc, windowdefs)
2767  {
2768  WindowDef *windef = (WindowDef *) lfirst(lc);
2769  WindowClause *refwc = NULL;
2770  List *partitionClause;
2771  List *orderClause;
2772  Oid rangeopfamily = InvalidOid;
2773  Oid rangeopcintype = InvalidOid;
2774  WindowClause *wc;
2775 
2776  winref++;
2777 
2778  /*
2779  * Check for duplicate window names.
2780  */
2781  if (windef->name &&
2782  findWindowClause(result, windef->name) != NULL)
2783  ereport(ERROR,
2784  (errcode(ERRCODE_WINDOWING_ERROR),
2785  errmsg("window \"%s\" is already defined", windef->name),
2786  parser_errposition(pstate, windef->location)));
2787 
2788  /*
2789  * If it references a previous window, look that up.
2790  */
2791  if (windef->refname)
2792  {
2793  refwc = findWindowClause(result, windef->refname);
2794  if (refwc == NULL)
2795  ereport(ERROR,
2796  (errcode(ERRCODE_UNDEFINED_OBJECT),
2797  errmsg("window \"%s\" does not exist",
2798  windef->refname),
2799  parser_errposition(pstate, windef->location)));
2800  }
2801 
2802  /*
2803  * Transform PARTITION and ORDER specs, if any. These are treated
2804  * almost exactly like top-level GROUP BY and ORDER BY clauses,
2805  * including the special handling of nondefault operator semantics.
2806  */
2807  orderClause = transformSortClause(pstate,
2808  windef->orderClause,
2809  targetlist,
2811  true /* force SQL99 rules */ );
2812  partitionClause = transformGroupClause(pstate,
2813  windef->partitionClause,
2814  NULL,
2815  targetlist,
2816  orderClause,
2818  true /* force SQL99 rules */ );
2819 
2820  /*
2821  * And prepare the new WindowClause.
2822  */
2823  wc = makeNode(WindowClause);
2824  wc->name = windef->name;
2825  wc->refname = windef->refname;
2826 
2827  /*
2828  * Per spec, a windowdef that references a previous one copies the
2829  * previous partition clause (and mustn't specify its own). It can
2830  * specify its own ordering clause, but only if the previous one had
2831  * none. It always specifies its own frame clause, and the previous
2832  * one must not have a frame clause. Yeah, it's bizarre that each of
2833  * these cases works differently, but SQL:2008 says so; see 7.11
2834  * <window clause> syntax rule 10 and general rule 1. The frame
2835  * clause rule is especially bizarre because it makes "OVER foo"
2836  * different from "OVER (foo)", and requires the latter to throw an
2837  * error if foo has a nondefault frame clause. Well, ours not to
2838  * reason why, but we do go out of our way to throw a useful error
2839  * message for such cases.
2840  */
2841  if (refwc)
2842  {
2843  if (partitionClause)
2844  ereport(ERROR,
2845  (errcode(ERRCODE_WINDOWING_ERROR),
2846  errmsg("cannot override PARTITION BY clause of window \"%s\"",
2847  windef->refname),
2848  parser_errposition(pstate, windef->location)));
2850  }
2851  else
2852  wc->partitionClause = partitionClause;
2853  if (refwc)
2854  {
2855  if (orderClause && refwc->orderClause)
2856  ereport(ERROR,
2857  (errcode(ERRCODE_WINDOWING_ERROR),
2858  errmsg("cannot override ORDER BY clause of window \"%s\"",
2859  windef->refname),
2860  parser_errposition(pstate, windef->location)));
2861  if (orderClause)
2862  {
2863  wc->orderClause = orderClause;
2864  wc->copiedOrder = false;
2865  }
2866  else
2867  {
2868  wc->orderClause = copyObject(refwc->orderClause);
2869  wc->copiedOrder = true;
2870  }
2871  }
2872  else
2873  {
2874  wc->orderClause = orderClause;
2875  wc->copiedOrder = false;
2876  }
2877  if (refwc && refwc->frameOptions != FRAMEOPTION_DEFAULTS)
2878  {
2879  /*
2880  * Use this message if this is a WINDOW clause, or if it's an OVER
2881  * clause that includes ORDER BY or framing clauses. (We already
2882  * rejected PARTITION BY above, so no need to check that.)
2883  */
2884  if (windef->name ||
2885  orderClause || windef->frameOptions != FRAMEOPTION_DEFAULTS)
2886  ereport(ERROR,
2887  (errcode(ERRCODE_WINDOWING_ERROR),
2888  errmsg("cannot copy window \"%s\" because it has a frame clause",
2889  windef->refname),
2890  parser_errposition(pstate, windef->location)));
2891  /* Else this clause is just OVER (foo), so say this: */
2892  ereport(ERROR,
2893  (errcode(ERRCODE_WINDOWING_ERROR),
2894  errmsg("cannot copy window \"%s\" because it has a frame clause",
2895  windef->refname),
2896  errhint("Omit the parentheses in this OVER clause."),
2897  parser_errposition(pstate, windef->location)));
2898  }
2899  wc->frameOptions = windef->frameOptions;
2900 
2901  /*
2902  * RANGE offset PRECEDING/FOLLOWING requires exactly one ORDER BY
2903  * column; check that and get its sort opfamily info.
2904  */
2905  if ((wc->frameOptions & FRAMEOPTION_RANGE) &&
2908  {
2909  SortGroupClause *sortcl;
2910  Node *sortkey;
2911  int16 rangestrategy;
2912 
2913  if (list_length(wc->orderClause) != 1)
2914  ereport(ERROR,
2915  (errcode(ERRCODE_WINDOWING_ERROR),
2916  errmsg("RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column"),
2917  parser_errposition(pstate, windef->location)));
2918  sortcl = linitial_node(SortGroupClause, wc->orderClause);
2919  sortkey = get_sortgroupclause_expr(sortcl, *targetlist);
2920  /* Find the sort operator in pg_amop */
2921  if (!get_ordering_op_properties(sortcl->sortop,
2922  &rangeopfamily,
2923  &rangeopcintype,
2924  &rangestrategy))
2925  elog(ERROR, "operator %u is not a valid ordering operator",
2926  sortcl->sortop);
2927  /* Record properties of sort ordering */
2928  wc->inRangeColl = exprCollation(sortkey);
2929  wc->inRangeAsc = (rangestrategy == BTLessStrategyNumber);
2930  wc->inRangeNullsFirst = sortcl->nulls_first;
2931  }
2932 
2933  /* Per spec, GROUPS mode requires an ORDER BY clause */
2934  if (wc->frameOptions & FRAMEOPTION_GROUPS)
2935  {
2936  if (wc->orderClause == NIL)
2937  ereport(ERROR,
2938  (errcode(ERRCODE_WINDOWING_ERROR),
2939  errmsg("GROUPS mode requires an ORDER BY clause"),
2940  parser_errposition(pstate, windef->location)));
2941  }
2942 
2943  /* Process frame offset expressions */
2944  wc->startOffset = transformFrameOffset(pstate, wc->frameOptions,
2945  rangeopfamily, rangeopcintype,
2946  &wc->startInRangeFunc,
2947  windef->startOffset);
2948  wc->endOffset = transformFrameOffset(pstate, wc->frameOptions,
2949  rangeopfamily, rangeopcintype,
2950  &wc->endInRangeFunc,
2951  windef->endOffset);
2952  wc->runCondition = NIL;
2953  wc->winref = winref;
2954 
2955  result = lappend(result, wc);
2956  }
2957 
2958  return result;
2959 }
signed short int16
Definition: c.h:477
bool get_ordering_op_properties(Oid opno, Oid *opfamily, Oid *opcintype, int16 *strategy)
Definition: lsyscache.c:206
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:788
List * transformSortClause(ParseState *pstate, List *orderlist, List **targetlist, ParseExprKind exprKind, bool useSQL99)
List * transformGroupClause(ParseState *pstate, List *grouplist, List **groupingSets, List **targetlist, List *sortClause, ParseExprKind exprKind, bool useSQL99)
static Node * transformFrameOffset(ParseState *pstate, int frameOptions, Oid rangeopfamily, Oid rangeopcintype, Oid *inRangeFunc, Node *clause)
static WindowClause * findWindowClause(List *wclist, const char *name)
@ EXPR_KIND_WINDOW_PARTITION
Definition: parse_node.h:49
@ EXPR_KIND_WINDOW_ORDER
Definition: parse_node.h:50
#define FRAMEOPTION_END_OFFSET
Definition: parsenodes.h:600
#define FRAMEOPTION_START_OFFSET
Definition: parsenodes.h:598
#define FRAMEOPTION_RANGE
Definition: parsenodes.h:580
#define FRAMEOPTION_GROUPS
Definition: parsenodes.h:582
#define FRAMEOPTION_DEFAULTS
Definition: parsenodes.h:606
static int list_length(const List *l)
Definition: pg_list.h:152
#define linitial_node(type, l)
Definition: pg_list.h:181
#define BTLessStrategyNumber
Definition: stratnum.h:29
Node * startOffset
Definition: parsenodes.h:1499
List * partitionClause
Definition: parsenodes.h:1495
Node * endOffset
Definition: parsenodes.h:1500
List * orderClause
Definition: parsenodes.h:1497
List * orderClause
Definition: parsenodes.h:565
List * partitionClause
Definition: parsenodes.h:564
Node * startOffset
Definition: parsenodes.h:567
char * refname
Definition: parsenodes.h:563
Node * endOffset
Definition: parsenodes.h:568
int frameOptions
Definition: parsenodes.h:566
int location
Definition: parsenodes.h:569
char * name
Definition: parsenodes.h:562
Node * get_sortgroupclause_expr(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:379

References BTLessStrategyNumber, copyObject, elog(), WindowDef::endOffset, WindowClause::endOffset, ereport, errcode(), errhint(), errmsg(), ERROR, EXPR_KIND_WINDOW_ORDER, EXPR_KIND_WINDOW_PARTITION, exprCollation(), findWindowClause(), FRAMEOPTION_DEFAULTS, FRAMEOPTION_END_OFFSET, FRAMEOPTION_GROUPS, FRAMEOPTION_RANGE, FRAMEOPTION_START_OFFSET, WindowDef::frameOptions, WindowClause::frameOptions, get_ordering_op_properties(), get_sortgroupclause_expr(), InvalidOid, lappend(), lfirst, linitial_node, list_length(), WindowDef::location, makeNode, WindowDef::name, NIL, SortGroupClause::nulls_first, WindowDef::orderClause, WindowClause::orderClause, parser_errposition(), WindowDef::partitionClause, WindowClause::partitionClause, WindowDef::refname, SortGroupClause::sortop, WindowDef::startOffset, WindowClause::startOffset, transformFrameOffset(), transformGroupClause(), transformSortClause(), and WindowClause::winref.

Referenced by transformPLAssignStmt(), and transformSelectStmt().