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 3388 of file parse_clause.c.

3390 {
3391  Oid restype = exprType((Node *) tle->expr);
3392  Oid sortop;
3393  Oid eqop;
3394  bool hashable;
3395  bool reverse;
3396  int location;
3397  ParseCallbackState pcbstate;
3398 
3399  /* if tlist item is an UNKNOWN literal, change it to TEXT */
3400  if (restype == UNKNOWNOID)
3401  {
3402  tle->expr = (Expr *) coerce_type(pstate, (Node *) tle->expr,
3403  restype, TEXTOID, -1,
3406  -1);
3407  restype = TEXTOID;
3408  }
3409 
3410  /*
3411  * Rather than clutter the API of get_sort_group_operators and the other
3412  * functions we're about to use, make use of error context callback to
3413  * mark any error reports with a parse position. We point to the operator
3414  * location if present, else to the expression being sorted. (NB: use the
3415  * original untransformed expression here; the TLE entry might well point
3416  * at a duplicate expression in the regular SELECT list.)
3417  */
3418  location = sortby->location;
3419  if (location < 0)
3420  location = exprLocation(sortby->node);
3421  setup_parser_errposition_callback(&pcbstate, pstate, location);
3422 
3423  /* determine the sortop, eqop, and directionality */
3424  switch (sortby->sortby_dir)
3425  {
3426  case SORTBY_DEFAULT:
3427  case SORTBY_ASC:
3428  get_sort_group_operators(restype,
3429  true, true, false,
3430  &sortop, &eqop, NULL,
3431  &hashable);
3432  reverse = false;
3433  break;
3434  case SORTBY_DESC:
3435  get_sort_group_operators(restype,
3436  false, true, true,
3437  NULL, &eqop, &sortop,
3438  &hashable);
3439  reverse = true;
3440  break;
3441  case SORTBY_USING:
3442  Assert(sortby->useOp != NIL);
3443  sortop = compatible_oper_opid(sortby->useOp,
3444  restype,
3445  restype,
3446  false);
3447 
3448  /*
3449  * Verify it's a valid ordering operator, fetch the corresponding
3450  * equality operator, and determine whether to consider it like
3451  * ASC or DESC.
3452  */
3453  eqop = get_equality_op_for_ordering_op(sortop, &reverse);
3454  if (!OidIsValid(eqop))
3455  ereport(ERROR,
3456  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
3457  errmsg("operator %s is not a valid ordering operator",
3458  strVal(llast(sortby->useOp))),
3459  errhint("Ordering operators must be \"<\" or \">\" members of btree operator families.")));
3460 
3461  /*
3462  * Also see if the equality operator is hashable.
3463  */
3464  hashable = op_hashjoinable(eqop, restype);
3465  break;
3466  default:
3467  elog(ERROR, "unrecognized sortby_dir: %d", sortby->sortby_dir);
3468  sortop = InvalidOid; /* keep compiler quiet */
3469  eqop = InvalidOid;
3470  hashable = false;
3471  reverse = false;
3472  break;
3473  }
3474 
3476 
3477  /* avoid making duplicate sortlist entries */
3478  if (!targetIsInSortList(tle, sortop, sortlist))
3479  {
3481 
3482  sortcl->tleSortGroupRef = assignSortGroupRef(tle, targetlist);
3483 
3484  sortcl->eqop = eqop;
3485  sortcl->sortop = sortop;
3486  sortcl->hashable = hashable;
3487 
3488  switch (sortby->sortby_nulls)
3489  {
3490  case SORTBY_NULLS_DEFAULT:
3491  /* NULLS FIRST is default for DESC; other way for ASC */
3492  sortcl->nulls_first = reverse;
3493  break;
3494  case SORTBY_NULLS_FIRST:
3495  sortcl->nulls_first = true;
3496  break;
3497  case SORTBY_NULLS_LAST:
3498  sortcl->nulls_first = false;
3499  break;
3500  default:
3501  elog(ERROR, "unrecognized sortby_nulls: %d",
3502  sortby->sortby_nulls);
3503  break;
3504  }
3505 
3506  sortlist = lappend(sortlist, sortcl);
3507  }
3508 
3509  return sortlist;
3510 }
#define OidIsValid(objectId)
Definition: c.h:764
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:1441
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1312
#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:180
Oid compatible_oper_opid(List *op, Oid arg1, Oid arg2, bool noError)
Definition: parse_oper.c:487
@ SORTBY_NULLS_DEFAULT
Definition: parsenodes.h:54
@ SORTBY_NULLS_LAST
Definition: parsenodes.h:56
@ SORTBY_NULLS_FIRST
Definition: parsenodes.h:55
@ SORTBY_USING
Definition: parsenodes.h:49
@ SORTBY_DESC
Definition: parsenodes.h:48
@ SORTBY_ASC
Definition: parsenodes.h:47
@ SORTBY_DEFAULT
Definition: parsenodes.h:46
#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:671
@ COERCION_IMPLICIT
Definition: primnodes.h:649
Definition: nodes.h:129
SortByNulls sortby_nulls
Definition: parsenodes.h:538
Node * node
Definition: parsenodes.h:536
List * useOp
Definition: parsenodes.h:539
SortByDir sortby_dir
Definition: parsenodes.h:537
int location
Definition: parsenodes.h:540
Index tleSortGroupRef
Definition: parsenodes.h:1385
Expr * expr
Definition: primnodes.h:1922
#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 3586 of file parse_clause.c.

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

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:1238
char * relname
Definition: primnodes.h:82
Alias * alias
Definition: primnodes.h:91
char * schemaname
Definition: primnodes.h:79
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 3627 of file parse_clause.c.

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

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 2980 of file parse_clause.c.

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

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

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

1878 {
1879  Node *qual;
1880 
1881  if (clause == NULL)
1882  return NULL;
1883 
1884  qual = transformExpr(pstate, clause, exprKind);
1885 
1886  qual = coerce_to_specific_type(pstate, qual, INT8OID, constructName);
1887 
1888  /* LIMIT can't refer to any variables of the current query */
1889  checkExprIsVarFree(pstate, qual, constructName);
1890 
1891  /*
1892  * Don't allow NULLs in FETCH FIRST .. WITH TIES. This test is ugly and
1893  * extremely simplistic, in that you can pass a NULL anyway by hiding it
1894  * inside an expression -- but this protects ruleutils against emitting an
1895  * unadorned NULL that's not accepted back by the grammar.
1896  */
1897  if (exprKind == EXPR_KIND_LIMIT && limitOption == LIMIT_OPTION_WITH_TIES &&
1898  IsA(clause, A_Const) && castNode(A_Const, clause)->isnull)
1899  ereport(ERROR,
1900  (errcode(ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE),
1901  errmsg("row count cannot be null in FETCH FIRST ... WITH TIES clause")));
1902 
1903  return qual;
1904 }
@ 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:110
@ 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 3292 of file parse_clause.c.

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

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 2726 of file parse_clause.c.

2731 {
2732  List *sortlist = NIL;
2733  ListCell *olitem;
2734 
2735  foreach(olitem, orderlist)
2736  {
2737  SortBy *sortby = (SortBy *) lfirst(olitem);
2738  TargetEntry *tle;
2739 
2740  if (useSQL99)
2741  tle = findTargetlistEntrySQL99(pstate, sortby->node,
2742  targetlist, exprKind);
2743  else
2744  tle = findTargetlistEntrySQL92(pstate, sortby->node,
2745  targetlist, exprKind);
2746 
2747  sortlist = addTargetToSortList(pstate, tle,
2748  sortlist, *targetlist, sortby);
2749  }
2750 
2751  return sortlist;
2752 }
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 1848 of file parse_clause.c.

1850 {
1851  Node *qual;
1852 
1853  if (clause == NULL)
1854  return NULL;
1855 
1856  qual = transformExpr(pstate, clause, exprKind);
1857 
1858  qual = coerce_to_boolean(pstate, qual, constructName);
1859 
1860  return qual;
1861 }
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 2759 of file parse_clause.c.

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