PostgreSQL Source Code  git master
parsenodes.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * parsenodes.h
4  * definitions for parse tree nodes
5  *
6  * Many of the node types used in parsetrees include a "location" field.
7  * This is a byte (not character) offset in the original source text, to be
8  * used for positioning an error cursor when there is an error related to
9  * the node. Access to the original source text is needed to make use of
10  * the location. At the topmost (statement) level, we also provide a
11  * statement length, likewise measured in bytes, for convenience in
12  * identifying statement boundaries in multi-statement source strings.
13  *
14  *
15  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
16  * Portions Copyright (c) 1994, Regents of the University of California
17  *
18  * src/include/nodes/parsenodes.h
19  *
20  *-------------------------------------------------------------------------
21  */
22 #ifndef PARSENODES_H
23 #define PARSENODES_H
24 
25 #include "nodes/bitmapset.h"
26 #include "nodes/lockoptions.h"
27 #include "nodes/primnodes.h"
28 #include "nodes/value.h"
29 #include "partitioning/partdefs.h"
30 
31 
32 typedef enum OverridingKind
33 {
38 
39 /* Possible sources of a Query */
40 typedef enum QuerySource
41 {
42  QSRC_ORIGINAL, /* original parsetree (explicit query) */
43  QSRC_PARSER, /* added by parse analysis (now unused) */
44  QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */
45  QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */
46  QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */
47 } QuerySource;
48 
49 /* Sort ordering options for ORDER BY and CREATE INDEX */
50 typedef enum SortByDir
51 {
55  SORTBY_USING /* not allowed in CREATE INDEX ... */
56 } SortByDir;
57 
58 typedef enum SortByNulls
59 {
63 } SortByNulls;
64 
65 /* Options for [ ALL | DISTINCT ] */
66 typedef enum SetQuantifier
67 {
72 
73 /*
74  * Grantable rights are encoded so that we can OR them together in a bitmask.
75  * The present representation of AclItem limits us to 16 distinct rights,
76  * even though AclMode is defined as uint32. See utils/acl.h.
77  *
78  * Caution: changing these codes breaks stored ACLs, hence forces initdb.
79  */
80 typedef uint32 AclMode; /* a bitmask of privilege bits */
81 
82 #define ACL_INSERT (1<<0) /* for relations */
83 #define ACL_SELECT (1<<1)
84 #define ACL_UPDATE (1<<2)
85 #define ACL_DELETE (1<<3)
86 #define ACL_TRUNCATE (1<<4)
87 #define ACL_REFERENCES (1<<5)
88 #define ACL_TRIGGER (1<<6)
89 #define ACL_EXECUTE (1<<7) /* for functions */
90 #define ACL_USAGE (1<<8) /* for languages, namespaces, FDWs, and
91  * servers */
92 #define ACL_CREATE (1<<9) /* for namespaces and databases */
93 #define ACL_CREATE_TEMP (1<<10) /* for databases */
94 #define ACL_CONNECT (1<<11) /* for databases */
95 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */
96 #define ACL_NO_RIGHTS 0
97 /* Currently, SELECT ... FOR [KEY] UPDATE/SHARE requires UPDATE privileges */
98 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE
99 
100 
101 /*****************************************************************************
102  * Query Tree
103  *****************************************************************************/
104 
105 /*
106  * Query -
107  * Parse analysis turns all statements into a Query tree
108  * for further processing by the rewriter and planner.
109  *
110  * Utility statements (i.e. non-optimizable statements) have the
111  * utilityStmt field set, and the rest of the Query is mostly dummy.
112  *
113  * Planning converts a Query tree into a Plan tree headed by a PlannedStmt
114  * node --- the Query structure is not used by the executor.
115  */
116 typedef struct Query
117 {
119 
120  CmdType commandType; /* select|insert|update|delete|utility */
121 
122  QuerySource querySource; /* where did I come from? */
123 
124  uint64 queryId; /* query identifier (can be set by plugins) */
125 
126  bool canSetTag; /* do I set the command result tag? */
127 
128  Node *utilityStmt; /* non-null if commandType == CMD_UTILITY */
129 
130  int resultRelation; /* rtable index of target relation for
131  * INSERT/UPDATE/DELETE; 0 for SELECT */
132 
133  bool hasAggs; /* has aggregates in tlist or havingQual */
134  bool hasWindowFuncs; /* has window functions in tlist */
135  bool hasTargetSRFs; /* has set-returning functions in tlist */
136  bool hasSubLinks; /* has subquery SubLink */
137  bool hasDistinctOn; /* distinctClause is from DISTINCT ON */
138  bool hasRecursive; /* WITH RECURSIVE was specified */
139  bool hasModifyingCTE; /* has INSERT/UPDATE/DELETE in WITH */
140  bool hasForUpdate; /* FOR [KEY] UPDATE/SHARE was specified */
141  bool hasRowSecurity; /* rewriter has applied some RLS policy */
142 
143  bool isReturn; /* is a RETURN statement */
144 
145  List *cteList; /* WITH list (of CommonTableExpr's) */
146 
147  List *rtable; /* list of range table entries */
148  FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */
149 
150  List *targetList; /* target list (of TargetEntry) */
151 
152  OverridingKind override; /* OVERRIDING clause */
153 
154  OnConflictExpr *onConflict; /* ON CONFLICT DO [NOTHING | UPDATE] */
155 
156  List *returningList; /* return-values list (of TargetEntry) */
157 
158  List *groupClause; /* a list of SortGroupClause's */
159  bool groupDistinct; /* is the group by clause distinct? */
160 
161  List *groupingSets; /* a list of GroupingSet's if present */
162 
163  Node *havingQual; /* qualifications applied to groups */
164 
165  List *windowClause; /* a list of WindowClause's */
166 
167  List *distinctClause; /* a list of SortGroupClause's */
168 
169  List *sortClause; /* a list of SortGroupClause's */
170 
171  Node *limitOffset; /* # of result tuples to skip (int8 expr) */
172  Node *limitCount; /* # of result tuples to return (int8 expr) */
173  LimitOption limitOption; /* limit type */
174 
175  List *rowMarks; /* a list of RowMarkClause's */
176 
177  Node *setOperations; /* set-operation tree if this is top level of
178  * a UNION/INTERSECT/EXCEPT query */
179 
180  List *constraintDeps; /* a list of pg_constraint OIDs that the query
181  * depends on to be semantically valid */
182 
183  List *withCheckOptions; /* a list of WithCheckOption's (added
184  * during rewrite) */
185 
186  /*
187  * The following two fields identify the portion of the source text string
188  * containing this query. They are typically only populated in top-level
189  * Queries, not in sub-queries. When not set, they might both be zero, or
190  * both be -1 meaning "unknown".
191  */
192  int stmt_location; /* start location, or -1 if unknown */
193  int stmt_len; /* length in bytes; 0 means "rest of string" */
194 } Query;
195 
196 
197 /****************************************************************************
198  * Supporting data structures for Parse Trees
199  *
200  * Most of these node types appear in raw parsetrees output by the grammar,
201  * and get transformed to something else by the analyzer. A few of them
202  * are used as-is in transformed querytrees.
203  ****************************************************************************/
204 
205 /*
206  * TypeName - specifies a type in definitions
207  *
208  * For TypeName structures generated internally, it is often easier to
209  * specify the type by OID than by name. If "names" is NIL then the
210  * actual type OID is given by typeOid, otherwise typeOid is unused.
211  * Similarly, if "typmods" is NIL then the actual typmod is expected to
212  * be prespecified in typemod, otherwise typemod is unused.
213  *
214  * If pct_type is true, then names is actually a field name and we look up
215  * the type of that field. Otherwise (the normal case), names is a type
216  * name possibly qualified with schema and database name.
217  */
218 typedef struct TypeName
219 {
221  List *names; /* qualified name (list of Value strings) */
222  Oid typeOid; /* type identified by OID */
223  bool setof; /* is a set? */
224  bool pct_type; /* %TYPE specified? */
225  List *typmods; /* type modifier expression(s) */
226  int32 typemod; /* prespecified type modifier */
227  List *arrayBounds; /* array bounds */
228  int location; /* token location, or -1 if unknown */
229 } TypeName;
230 
231 /*
232  * ColumnRef - specifies a reference to a column, or possibly a whole tuple
233  *
234  * The "fields" list must be nonempty. It can contain string Value nodes
235  * (representing names) and A_Star nodes (representing occurrence of a '*').
236  * Currently, A_Star must appear only as the last list element --- the grammar
237  * is responsible for enforcing this!
238  *
239  * Note: any container subscripting or selection of fields from composite columns
240  * is represented by an A_Indirection node above the ColumnRef. However,
241  * for simplicity in the normal case, initial field selection from a table
242  * name is represented within ColumnRef and not by adding A_Indirection.
243  */
244 typedef struct ColumnRef
245 {
247  List *fields; /* field names (Value strings) or A_Star */
248  int location; /* token location, or -1 if unknown */
249 } ColumnRef;
250 
251 /*
252  * ParamRef - specifies a $n parameter reference
253  */
254 typedef struct ParamRef
255 {
257  int number; /* the number of the parameter */
258  int location; /* token location, or -1 if unknown */
259 } ParamRef;
260 
261 /*
262  * A_Expr - infix, prefix, and postfix expressions
263  */
264 typedef enum A_Expr_Kind
265 {
266  AEXPR_OP, /* normal operator */
267  AEXPR_OP_ANY, /* scalar op ANY (array) */
268  AEXPR_OP_ALL, /* scalar op ALL (array) */
269  AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */
270  AEXPR_NOT_DISTINCT, /* IS NOT DISTINCT FROM - name must be "=" */
271  AEXPR_NULLIF, /* NULLIF - name must be "=" */
272  AEXPR_IN, /* [NOT] IN - name must be "=" or "<>" */
273  AEXPR_LIKE, /* [NOT] LIKE - name must be "~~" or "!~~" */
274  AEXPR_ILIKE, /* [NOT] ILIKE - name must be "~~*" or "!~~*" */
275  AEXPR_SIMILAR, /* [NOT] SIMILAR - name must be "~" or "!~" */
276  AEXPR_BETWEEN, /* name must be "BETWEEN" */
277  AEXPR_NOT_BETWEEN, /* name must be "NOT BETWEEN" */
278  AEXPR_BETWEEN_SYM, /* name must be "BETWEEN SYMMETRIC" */
279  AEXPR_NOT_BETWEEN_SYM /* name must be "NOT BETWEEN SYMMETRIC" */
280 } A_Expr_Kind;
281 
282 typedef struct A_Expr
283 {
285  A_Expr_Kind kind; /* see above */
286  List *name; /* possibly-qualified name of operator */
287  Node *lexpr; /* left argument, or NULL if none */
288  Node *rexpr; /* right argument, or NULL if none */
289  int location; /* token location, or -1 if unknown */
290 } A_Expr;
291 
292 /*
293  * A_Const - a literal constant
294  */
295 typedef struct A_Const
296 {
298  Value val; /* value (includes type info, see value.h) */
299  int location; /* token location, or -1 if unknown */
300 } A_Const;
301 
302 /*
303  * TypeCast - a CAST expression
304  */
305 typedef struct TypeCast
306 {
308  Node *arg; /* the expression being casted */
309  TypeName *typeName; /* the target type */
310  int location; /* token location, or -1 if unknown */
311 } TypeCast;
312 
313 /*
314  * CollateClause - a COLLATE expression
315  */
316 typedef struct CollateClause
317 {
319  Node *arg; /* input expression */
320  List *collname; /* possibly-qualified collation name */
321  int location; /* token location, or -1 if unknown */
322 } CollateClause;
323 
324 /*
325  * RoleSpec - a role name or one of a few special values.
326  */
327 typedef enum RoleSpecType
328 {
329  ROLESPEC_CSTRING, /* role name is stored as a C string */
330  ROLESPEC_CURRENT_ROLE, /* role spec is CURRENT_ROLE */
331  ROLESPEC_CURRENT_USER, /* role spec is CURRENT_USER */
332  ROLESPEC_SESSION_USER, /* role spec is SESSION_USER */
333  ROLESPEC_PUBLIC /* role name is "public" */
334 } RoleSpecType;
335 
336 typedef struct RoleSpec
337 {
339  RoleSpecType roletype; /* Type of this rolespec */
340  char *rolename; /* filled only for ROLESPEC_CSTRING */
341  int location; /* token location, or -1 if unknown */
342 } RoleSpec;
343 
344 /*
345  * FuncCall - a function or aggregate invocation
346  *
347  * agg_order (if not NIL) indicates we saw 'foo(... ORDER BY ...)', or if
348  * agg_within_group is true, it was 'foo(...) WITHIN GROUP (ORDER BY ...)'.
349  * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
350  * indicates we saw 'foo(DISTINCT ...)'. In any of these cases, the
351  * construct *must* be an aggregate call. Otherwise, it might be either an
352  * aggregate or some other kind of function. However, if FILTER or OVER is
353  * present it had better be an aggregate or window function.
354  *
355  * Normally, you'd initialize this via makeFuncCall() and then only change the
356  * parts of the struct its defaults don't match afterwards, as needed.
357  */
358 typedef struct FuncCall
359 {
361  List *funcname; /* qualified name of function */
362  List *args; /* the arguments (list of exprs) */
363  List *agg_order; /* ORDER BY (list of SortBy) */
364  Node *agg_filter; /* FILTER clause, if any */
365  struct WindowDef *over; /* OVER clause, if any */
366  bool agg_within_group; /* ORDER BY appeared in WITHIN GROUP */
367  bool agg_star; /* argument was really '*' */
368  bool agg_distinct; /* arguments were labeled DISTINCT */
369  bool func_variadic; /* last argument was labeled VARIADIC */
370  CoercionForm funcformat; /* how to display this node */
371  int location; /* token location, or -1 if unknown */
372 } FuncCall;
373 
374 /*
375  * A_Star - '*' representing all columns of a table or compound field
376  *
377  * This can appear within ColumnRef.fields, A_Indirection.indirection, and
378  * ResTarget.indirection lists.
379  */
380 typedef struct A_Star
381 {
383 } A_Star;
384 
385 /*
386  * A_Indices - array subscript or slice bounds ([idx] or [lidx:uidx])
387  *
388  * In slice case, either or both of lidx and uidx can be NULL (omitted).
389  * In non-slice case, uidx holds the single subscript and lidx is always NULL.
390  */
391 typedef struct A_Indices
392 {
394  bool is_slice; /* true if slice (i.e., colon present) */
395  Node *lidx; /* slice lower bound, if any */
396  Node *uidx; /* subscript, or slice upper bound if any */
397 } A_Indices;
398 
399 /*
400  * A_Indirection - select a field and/or array element from an expression
401  *
402  * The indirection list can contain A_Indices nodes (representing
403  * subscripting), string Value nodes (representing field selection --- the
404  * string value is the name of the field to select), and A_Star nodes
405  * (representing selection of all fields of a composite type).
406  * For example, a complex selection operation like
407  * (foo).field1[42][7].field2
408  * would be represented with a single A_Indirection node having a 4-element
409  * indirection list.
410  *
411  * Currently, A_Star must appear only as the last list element --- the grammar
412  * is responsible for enforcing this!
413  */
414 typedef struct A_Indirection
415 {
417  Node *arg; /* the thing being selected from */
418  List *indirection; /* subscripts and/or field names and/or * */
419 } A_Indirection;
420 
421 /*
422  * A_ArrayExpr - an ARRAY[] construct
423  */
424 typedef struct A_ArrayExpr
425 {
427  List *elements; /* array element expressions */
428  int location; /* token location, or -1 if unknown */
429 } A_ArrayExpr;
430 
431 /*
432  * ResTarget -
433  * result target (used in target list of pre-transformed parse trees)
434  *
435  * In a SELECT target list, 'name' is the column label from an
436  * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
437  * value expression itself. The 'indirection' field is not used.
438  *
439  * INSERT uses ResTarget in its target-column-names list. Here, 'name' is
440  * the name of the destination column, 'indirection' stores any subscripts
441  * attached to the destination, and 'val' is not used.
442  *
443  * In an UPDATE target list, 'name' is the name of the destination column,
444  * 'indirection' stores any subscripts attached to the destination, and
445  * 'val' is the expression to assign.
446  *
447  * See A_Indirection for more info about what can appear in 'indirection'.
448  */
449 typedef struct ResTarget
450 {
452  char *name; /* column name or NULL */
453  List *indirection; /* subscripts, field names, and '*', or NIL */
454  Node *val; /* the value expression to compute or assign */
455  int location; /* token location, or -1 if unknown */
456 } ResTarget;
457 
458 /*
459  * MultiAssignRef - element of a row source expression for UPDATE
460  *
461  * In an UPDATE target list, when we have SET (a,b,c) = row-valued-expression,
462  * we generate separate ResTarget items for each of a,b,c. Their "val" trees
463  * are MultiAssignRef nodes numbered 1..n, linking to a common copy of the
464  * row-valued-expression (which parse analysis will process only once, when
465  * handling the MultiAssignRef with colno=1).
466  */
467 typedef struct MultiAssignRef
468 {
470  Node *source; /* the row-valued expression */
471  int colno; /* column number for this target (1..n) */
472  int ncolumns; /* number of targets in the construct */
474 
475 /*
476  * SortBy - for ORDER BY clause
477  */
478 typedef struct SortBy
479 {
481  Node *node; /* expression to sort on */
482  SortByDir sortby_dir; /* ASC/DESC/USING/default */
483  SortByNulls sortby_nulls; /* NULLS FIRST/LAST */
484  List *useOp; /* name of op to use, if SORTBY_USING */
485  int location; /* operator location, or -1 if none/unknown */
486 } SortBy;
487 
488 /*
489  * WindowDef - raw representation of WINDOW and OVER clauses
490  *
491  * For entries in a WINDOW list, "name" is the window name being defined.
492  * For OVER clauses, we use "name" for the "OVER window" syntax, or "refname"
493  * for the "OVER (window)" syntax, which is subtly different --- the latter
494  * implies overriding the window frame clause.
495  */
496 typedef struct WindowDef
497 {
499  char *name; /* window's own name */
500  char *refname; /* referenced window name, if any */
501  List *partitionClause; /* PARTITION BY expression list */
502  List *orderClause; /* ORDER BY (list of SortBy) */
503  int frameOptions; /* frame_clause options, see below */
504  Node *startOffset; /* expression for starting bound, if any */
505  Node *endOffset; /* expression for ending bound, if any */
506  int location; /* parse location, or -1 if none/unknown */
507 } WindowDef;
508 
509 /*
510  * frameOptions is an OR of these bits. The NONDEFAULT and BETWEEN bits are
511  * used so that ruleutils.c can tell which properties were specified and
512  * which were defaulted; the correct behavioral bits must be set either way.
513  * The START_foo and END_foo options must come in pairs of adjacent bits for
514  * the convenience of gram.y, even though some of them are useless/invalid.
515  */
516 #define FRAMEOPTION_NONDEFAULT 0x00001 /* any specified? */
517 #define FRAMEOPTION_RANGE 0x00002 /* RANGE behavior */
518 #define FRAMEOPTION_ROWS 0x00004 /* ROWS behavior */
519 #define FRAMEOPTION_GROUPS 0x00008 /* GROUPS behavior */
520 #define FRAMEOPTION_BETWEEN 0x00010 /* BETWEEN given? */
521 #define FRAMEOPTION_START_UNBOUNDED_PRECEDING 0x00020 /* start is U. P. */
522 #define FRAMEOPTION_END_UNBOUNDED_PRECEDING 0x00040 /* (disallowed) */
523 #define FRAMEOPTION_START_UNBOUNDED_FOLLOWING 0x00080 /* (disallowed) */
524 #define FRAMEOPTION_END_UNBOUNDED_FOLLOWING 0x00100 /* end is U. F. */
525 #define FRAMEOPTION_START_CURRENT_ROW 0x00200 /* start is C. R. */
526 #define FRAMEOPTION_END_CURRENT_ROW 0x00400 /* end is C. R. */
527 #define FRAMEOPTION_START_OFFSET_PRECEDING 0x00800 /* start is O. P. */
528 #define FRAMEOPTION_END_OFFSET_PRECEDING 0x01000 /* end is O. P. */
529 #define FRAMEOPTION_START_OFFSET_FOLLOWING 0x02000 /* start is O. F. */
530 #define FRAMEOPTION_END_OFFSET_FOLLOWING 0x04000 /* end is O. F. */
531 #define FRAMEOPTION_EXCLUDE_CURRENT_ROW 0x08000 /* omit C.R. */
532 #define FRAMEOPTION_EXCLUDE_GROUP 0x10000 /* omit C.R. & peers */
533 #define FRAMEOPTION_EXCLUDE_TIES 0x20000 /* omit C.R.'s peers */
534 
535 #define FRAMEOPTION_START_OFFSET \
536  (FRAMEOPTION_START_OFFSET_PRECEDING | FRAMEOPTION_START_OFFSET_FOLLOWING)
537 #define FRAMEOPTION_END_OFFSET \
538  (FRAMEOPTION_END_OFFSET_PRECEDING | FRAMEOPTION_END_OFFSET_FOLLOWING)
539 #define FRAMEOPTION_EXCLUSION \
540  (FRAMEOPTION_EXCLUDE_CURRENT_ROW | FRAMEOPTION_EXCLUDE_GROUP | \
541  FRAMEOPTION_EXCLUDE_TIES)
542 
543 #define FRAMEOPTION_DEFAULTS \
544  (FRAMEOPTION_RANGE | FRAMEOPTION_START_UNBOUNDED_PRECEDING | \
545  FRAMEOPTION_END_CURRENT_ROW)
546 
547 /*
548  * RangeSubselect - subquery appearing in a FROM clause
549  */
550 typedef struct RangeSubselect
551 {
553  bool lateral; /* does it have LATERAL prefix? */
554  Node *subquery; /* the untransformed sub-select clause */
555  Alias *alias; /* table alias & optional column aliases */
557 
558 /*
559  * RangeFunction - function call appearing in a FROM clause
560  *
561  * functions is a List because we use this to represent the construct
562  * ROWS FROM(func1(...), func2(...), ...). Each element of this list is a
563  * two-element sublist, the first element being the untransformed function
564  * call tree, and the second element being a possibly-empty list of ColumnDef
565  * nodes representing any columndef list attached to that function within the
566  * ROWS FROM() syntax.
567  *
568  * alias and coldeflist represent any alias and/or columndef list attached
569  * at the top level. (We disallow coldeflist appearing both here and
570  * per-function, but that's checked in parse analysis, not by the grammar.)
571  */
572 typedef struct RangeFunction
573 {
575  bool lateral; /* does it have LATERAL prefix? */
576  bool ordinality; /* does it have WITH ORDINALITY suffix? */
577  bool is_rowsfrom; /* is result of ROWS FROM() syntax? */
578  List *functions; /* per-function information, see above */
579  Alias *alias; /* table alias & optional column aliases */
580  List *coldeflist; /* list of ColumnDef nodes to describe result
581  * of function returning RECORD */
582 } RangeFunction;
583 
584 /*
585  * RangeTableFunc - raw form of "table functions" such as XMLTABLE
586  */
587 typedef struct RangeTableFunc
588 {
590  bool lateral; /* does it have LATERAL prefix? */
591  Node *docexpr; /* document expression */
592  Node *rowexpr; /* row generator expression */
593  List *namespaces; /* list of namespaces as ResTarget */
594  List *columns; /* list of RangeTableFuncCol */
595  Alias *alias; /* table alias & optional column aliases */
596  int location; /* token location, or -1 if unknown */
598 
599 /*
600  * RangeTableFuncCol - one column in a RangeTableFunc->columns
601  *
602  * If for_ordinality is true (FOR ORDINALITY), then the column is an int4
603  * column and the rest of the fields are ignored.
604  */
605 typedef struct RangeTableFuncCol
606 {
608  char *colname; /* name of generated column */
609  TypeName *typeName; /* type of generated column */
610  bool for_ordinality; /* does it have FOR ORDINALITY? */
611  bool is_not_null; /* does it have NOT NULL? */
612  Node *colexpr; /* column filter expression */
613  Node *coldefexpr; /* column default value expression */
614  int location; /* token location, or -1 if unknown */
616 
617 /*
618  * RangeTableSample - TABLESAMPLE appearing in a raw FROM clause
619  *
620  * This node, appearing only in raw parse trees, represents
621  * <relation> TABLESAMPLE <method> (<params>) REPEATABLE (<num>)
622  * Currently, the <relation> can only be a RangeVar, but we might in future
623  * allow RangeSubselect and other options. Note that the RangeTableSample
624  * is wrapped around the node representing the <relation>, rather than being
625  * a subfield of it.
626  */
627 typedef struct RangeTableSample
628 {
630  Node *relation; /* relation to be sampled */
631  List *method; /* sampling method name (possibly qualified) */
632  List *args; /* argument(s) for sampling method */
633  Node *repeatable; /* REPEATABLE expression, or NULL if none */
634  int location; /* method name location, or -1 if unknown */
636 
637 /*
638  * ColumnDef - column definition (used in various creates)
639  *
640  * If the column has a default value, we may have the value expression
641  * in either "raw" form (an untransformed parse tree) or "cooked" form
642  * (a post-parse-analysis, executable expression tree), depending on
643  * how this ColumnDef node was created (by parsing, or by inheritance
644  * from an existing relation). We should never have both in the same node!
645  *
646  * Similarly, we may have a COLLATE specification in either raw form
647  * (represented as a CollateClause with arg==NULL) or cooked form
648  * (the collation's OID).
649  *
650  * The constraints list may contain a CONSTR_DEFAULT item in a raw
651  * parsetree produced by gram.y, but transformCreateStmt will remove
652  * the item and set raw_default instead. CONSTR_DEFAULT items
653  * should not appear in any subsequent processing.
654  */
655 typedef struct ColumnDef
656 {
658  char *colname; /* name of column */
659  TypeName *typeName; /* type of column */
660  char *compression; /* compression method for column */
661  int inhcount; /* number of times column is inherited */
662  bool is_local; /* column has local (non-inherited) def'n */
663  bool is_not_null; /* NOT NULL constraint specified? */
664  bool is_from_type; /* column definition came from table type */
665  char storage; /* attstorage setting, or 0 for default */
666  Node *raw_default; /* default value (untransformed parse tree) */
667  Node *cooked_default; /* default value (transformed expr tree) */
668  char identity; /* attidentity setting */
669  RangeVar *identitySequence; /* to store identity sequence name for
670  * ALTER TABLE ... ADD COLUMN */
671  char generated; /* attgenerated setting */
672  CollateClause *collClause; /* untransformed COLLATE spec, if any */
673  Oid collOid; /* collation OID (InvalidOid if not set) */
674  List *constraints; /* other constraints on column */
675  List *fdwoptions; /* per-column FDW options */
676  int location; /* parse location, or -1 if none/unknown */
677 } ColumnDef;
678 
679 /*
680  * TableLikeClause - CREATE TABLE ( ... LIKE ... ) clause
681  */
682 typedef struct TableLikeClause
683 {
686  bits32 options; /* OR of TableLikeOption flags */
687  Oid relationOid; /* If table has been looked up, its OID */
689 
690 typedef enum TableLikeOption
691 {
703 
704 /*
705  * IndexElem - index parameters (used in CREATE INDEX, and in ON CONFLICT)
706  *
707  * For a plain index attribute, 'name' is the name of the table column to
708  * index, and 'expr' is NULL. For an index expression, 'name' is NULL and
709  * 'expr' is the expression tree.
710  */
711 typedef struct IndexElem
712 {
714  char *name; /* name of attribute to index, or NULL */
715  Node *expr; /* expression to index, or NULL */
716  char *indexcolname; /* name for index column; NULL = default */
717  List *collation; /* name of collation; NIL = default */
718  List *opclass; /* name of desired opclass; NIL = default */
719  List *opclassopts; /* opclass-specific options, or NIL */
720  SortByDir ordering; /* ASC/DESC/default */
721  SortByNulls nulls_ordering; /* FIRST/LAST/default */
722 } IndexElem;
723 
724 /*
725  * DefElem - a generic "name = value" option definition
726  *
727  * In some contexts the name can be qualified. Also, certain SQL commands
728  * allow a SET/ADD/DROP action to be attached to option settings, so it's
729  * convenient to carry a field for that too. (Note: currently, it is our
730  * practice that the grammar allows namespace and action only in statements
731  * where they are relevant; C code can just ignore those fields in other
732  * statements.)
733  */
734 typedef enum DefElemAction
735 {
736  DEFELEM_UNSPEC, /* no action given */
740 } DefElemAction;
741 
742 typedef struct DefElem
743 {
745  char *defnamespace; /* NULL if unqualified name */
746  char *defname;
747  Node *arg; /* a (Value *) or a (TypeName *) */
748  DefElemAction defaction; /* unspecified action, or SET/ADD/DROP */
749  int location; /* token location, or -1 if unknown */
750 } DefElem;
751 
752 /*
753  * LockingClause - raw representation of FOR [NO KEY] UPDATE/[KEY] SHARE
754  * options
755  *
756  * Note: lockedRels == NIL means "all relations in query". Otherwise it
757  * is a list of RangeVar nodes. (We use RangeVar mainly because it carries
758  * a location field --- currently, parse analysis insists on unqualified
759  * names in LockingClause.)
760  */
761 typedef struct LockingClause
762 {
764  List *lockedRels; /* FOR [KEY] UPDATE/SHARE relations */
766  LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */
767 } LockingClause;
768 
769 /*
770  * XMLSERIALIZE (in raw parse tree only)
771  */
772 typedef struct XmlSerialize
773 {
775  XmlOptionType xmloption; /* DOCUMENT or CONTENT */
778  int location; /* token location, or -1 if unknown */
779 } XmlSerialize;
780 
781 /* Partitioning related definitions */
782 
783 /*
784  * PartitionElem - parse-time representation of a single partition key
785  *
786  * expr can be either a raw expression tree or a parse-analyzed expression.
787  * We don't store these on-disk, though.
788  */
789 typedef struct PartitionElem
790 {
792  char *name; /* name of column to partition on, or NULL */
793  Node *expr; /* expression to partition on, or NULL */
794  List *collation; /* name of collation; NIL = default */
795  List *opclass; /* name of desired opclass; NIL = default */
796  int location; /* token location, or -1 if unknown */
797 } PartitionElem;
798 
799 /*
800  * PartitionSpec - parse-time representation of a partition key specification
801  *
802  * This represents the key space we will be partitioning on.
803  */
804 typedef struct PartitionSpec
805 {
807  char *strategy; /* partitioning strategy ('hash', 'list' or
808  * 'range') */
809  List *partParams; /* List of PartitionElems */
810  int location; /* token location, or -1 if unknown */
811 } PartitionSpec;
812 
813 /* Internal codes for partitioning strategies */
814 #define PARTITION_STRATEGY_HASH 'h'
815 #define PARTITION_STRATEGY_LIST 'l'
816 #define PARTITION_STRATEGY_RANGE 'r'
817 
818 /*
819  * PartitionBoundSpec - a partition bound specification
820  *
821  * This represents the portion of the partition key space assigned to a
822  * particular partition. These are stored on disk in pg_class.relpartbound.
823  */
825 {
827 
828  char strategy; /* see PARTITION_STRATEGY codes above */
829  bool is_default; /* is it a default partition bound? */
830 
831  /* Partitioning info for HASH strategy: */
832  int modulus;
834 
835  /* Partitioning info for LIST strategy: */
836  List *listdatums; /* List of Consts (or A_Consts in raw tree) */
837 
838  /* Partitioning info for RANGE strategy: */
839  List *lowerdatums; /* List of PartitionRangeDatums */
840  List *upperdatums; /* List of PartitionRangeDatums */
841 
842  int location; /* token location, or -1 if unknown */
843 };
844 
845 /*
846  * PartitionRangeDatum - one of the values in a range partition bound
847  *
848  * This can be MINVALUE, MAXVALUE or a specific bounded value.
849  */
851 {
852  PARTITION_RANGE_DATUM_MINVALUE = -1, /* less than any other value */
853  PARTITION_RANGE_DATUM_VALUE = 0, /* a specific (bounded) value */
854  PARTITION_RANGE_DATUM_MAXVALUE = 1 /* greater than any other value */
856 
857 typedef struct PartitionRangeDatum
858 {
860 
862  Node *value; /* Const (or A_Const in raw tree), if kind is
863  * PARTITION_RANGE_DATUM_VALUE, else NULL */
864 
865  int location; /* token location, or -1 if unknown */
867 
868 /*
869  * PartitionCmd - info for ALTER TABLE/INDEX ATTACH/DETACH PARTITION commands
870  */
871 typedef struct PartitionCmd
872 {
874  RangeVar *name; /* name of partition to attach/detach */
875  PartitionBoundSpec *bound; /* FOR VALUES, if attaching */
877 } PartitionCmd;
878 
879 /****************************************************************************
880  * Nodes for a Query tree
881  ****************************************************************************/
882 
883 /*--------------------
884  * RangeTblEntry -
885  * A range table is a List of RangeTblEntry nodes.
886  *
887  * A range table entry may represent a plain relation, a sub-select in
888  * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax
889  * produces an RTE, not the implicit join resulting from multiple FROM
890  * items. This is because we only need the RTE to deal with SQL features
891  * like outer joins and join-output-column aliasing.) Other special
892  * RTE types also exist, as indicated by RTEKind.
893  *
894  * Note that we consider RTE_RELATION to cover anything that has a pg_class
895  * entry. relkind distinguishes the sub-cases.
896  *
897  * alias is an Alias node representing the AS alias-clause attached to the
898  * FROM expression, or NULL if no clause.
899  *
900  * eref is the table reference name and column reference names (either
901  * real or aliases). Note that system columns (OID etc) are not included
902  * in the column list.
903  * eref->aliasname is required to be present, and should generally be used
904  * to identify the RTE for error messages etc.
905  *
906  * In RELATION RTEs, the colnames in both alias and eref are indexed by
907  * physical attribute number; this means there must be colname entries for
908  * dropped columns. When building an RTE we insert empty strings ("") for
909  * dropped columns. Note however that a stored rule may have nonempty
910  * colnames for columns dropped since the rule was created (and for that
911  * matter the colnames might be out of date due to column renamings).
912  * The same comments apply to FUNCTION RTEs when a function's return type
913  * is a named composite type.
914  *
915  * In JOIN RTEs, the colnames in both alias and eref are one-to-one with
916  * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when
917  * those columns are known to be dropped at parse time. Again, however,
918  * a stored rule might contain entries for columns dropped since the rule
919  * was created. (This is only possible for columns not actually referenced
920  * in the rule.) When loading a stored rule, we replace the joinaliasvars
921  * items for any such columns with null pointers. (We can't simply delete
922  * them from the joinaliasvars list, because that would affect the attnums
923  * of Vars referencing the rest of the list.)
924  *
925  * inh is true for relation references that should be expanded to include
926  * inheritance children, if the rel has any. This *must* be false for
927  * RTEs other than RTE_RELATION entries.
928  *
929  * inFromCl marks those range variables that are listed in the FROM clause.
930  * It's false for RTEs that are added to a query behind the scenes, such
931  * as the NEW and OLD variables for a rule, or the subqueries of a UNION.
932  * This flag is not used anymore during parsing, since the parser now uses
933  * a separate "namespace" data structure to control visibility, but it is
934  * needed by ruleutils.c to determine whether RTEs should be shown in
935  * decompiled queries.
936  *
937  * requiredPerms and checkAsUser specify run-time access permissions
938  * checks to be performed at query startup. The user must have *all*
939  * of the permissions that are OR'd together in requiredPerms (zero
940  * indicates no permissions checking). If checkAsUser is not zero,
941  * then do the permissions checks using the access rights of that user,
942  * not the current effective user ID. (This allows rules to act as
943  * setuid gateways.) Permissions checks only apply to RELATION RTEs.
944  *
945  * For SELECT/INSERT/UPDATE permissions, if the user doesn't have
946  * table-wide permissions then it is sufficient to have the permissions
947  * on all columns identified in selectedCols (for SELECT) and/or
948  * insertedCols and/or updatedCols (INSERT with ON CONFLICT DO UPDATE may
949  * have all 3). selectedCols, insertedCols and updatedCols are bitmapsets,
950  * which cannot have negative integer members, so we subtract
951  * FirstLowInvalidHeapAttributeNumber from column numbers before storing
952  * them in these fields. A whole-row Var reference is represented by
953  * setting the bit for InvalidAttrNumber.
954  *
955  * updatedCols is also used in some other places, for example, to determine
956  * which triggers to fire and in FDWs to know which changed columns they
957  * need to ship off.
958  *
959  * Generated columns that are caused to be updated by an update to a base
960  * column are listed in extraUpdatedCols. This is not considered for
961  * permission checking, but it is useful in those places that want to know
962  * the full set of columns being updated as opposed to only the ones the
963  * user explicitly mentioned in the query. (There is currently no need for
964  * an extraInsertedCols, but it could exist.) Note that extraUpdatedCols
965  * is populated during query rewrite, NOT in the parser, since generated
966  * columns could be added after a rule has been parsed and stored.
967  *
968  * securityQuals is a list of security barrier quals (boolean expressions),
969  * to be tested in the listed order before returning a row from the
970  * relation. It is always NIL in parser output. Entries are added by the
971  * rewriter to implement security-barrier views and/or row-level security.
972  * Note that the planner turns each boolean expression into an implicitly
973  * AND'ed sublist, as is its usual habit with qualification expressions.
974  *--------------------
975  */
976 typedef enum RTEKind
977 {
978  RTE_RELATION, /* ordinary relation reference */
979  RTE_SUBQUERY, /* subquery in FROM */
980  RTE_JOIN, /* join */
981  RTE_FUNCTION, /* function in FROM */
982  RTE_TABLEFUNC, /* TableFunc(.., column list) */
983  RTE_VALUES, /* VALUES (<exprlist>), (<exprlist>), ... */
984  RTE_CTE, /* common table expr (WITH list element) */
985  RTE_NAMEDTUPLESTORE, /* tuplestore, e.g. for AFTER triggers */
986  RTE_RESULT /* RTE represents an empty FROM clause; such
987  * RTEs are added by the planner, they're not
988  * present during parsing or rewriting */
989 } RTEKind;
990 
991 typedef struct RangeTblEntry
992 {
994 
995  RTEKind rtekind; /* see above */
996 
997  /*
998  * XXX the fields applicable to only some rte kinds should be merged into
999  * a union. I didn't do this yet because the diffs would impact a lot of
1000  * code that is being actively worked on. FIXME someday.
1001  */
1002 
1003  /*
1004  * Fields valid for a plain relation RTE (else zero):
1005  *
1006  * As a special case, RTE_NAMEDTUPLESTORE can also set relid to indicate
1007  * that the tuple format of the tuplestore is the same as the referenced
1008  * relation. This allows plans referencing AFTER trigger transition
1009  * tables to be invalidated if the underlying table is altered.
1010  *
1011  * rellockmode is really LOCKMODE, but it's declared int to avoid having
1012  * to include lock-related headers here. It must be RowExclusiveLock if
1013  * the RTE is an INSERT/UPDATE/DELETE target, else RowShareLock if the RTE
1014  * is a SELECT FOR UPDATE/FOR SHARE target, else AccessShareLock.
1015  *
1016  * Note: in some cases, rule expansion may result in RTEs that are marked
1017  * with RowExclusiveLock even though they are not the target of the
1018  * current query; this happens if a DO ALSO rule simply scans the original
1019  * target table. We leave such RTEs with their original lockmode so as to
1020  * avoid getting an additional, lesser lock.
1021  */
1022  Oid relid; /* OID of the relation */
1023  char relkind; /* relation kind (see pg_class.relkind) */
1024  int rellockmode; /* lock level that query requires on the rel */
1025  struct TableSampleClause *tablesample; /* sampling info, or NULL */
1026 
1027  /*
1028  * Fields valid for a subquery RTE (else NULL):
1029  */
1030  Query *subquery; /* the sub-query */
1031  bool security_barrier; /* is from security_barrier view? */
1032 
1033  /*
1034  * Fields valid for a join RTE (else NULL/zero):
1035  *
1036  * joinaliasvars is a list of (usually) Vars corresponding to the columns
1037  * of the join result. An alias Var referencing column K of the join
1038  * result can be replaced by the K'th element of joinaliasvars --- but to
1039  * simplify the task of reverse-listing aliases correctly, we do not do
1040  * that until planning time. In detail: an element of joinaliasvars can
1041  * be a Var of one of the join's input relations, or such a Var with an
1042  * implicit coercion to the join's output column type, or a COALESCE
1043  * expression containing the two input column Vars (possibly coerced).
1044  * Elements beyond the first joinmergedcols entries are always just Vars,
1045  * and are never referenced from elsewhere in the query (that is, join
1046  * alias Vars are generated only for merged columns). We keep these
1047  * entries only because they're needed in expandRTE() and similar code.
1048  *
1049  * Within a Query loaded from a stored rule, it is possible for non-merged
1050  * joinaliasvars items to be null pointers, which are placeholders for
1051  * (necessarily unreferenced) columns dropped since the rule was made.
1052  * Also, once planning begins, joinaliasvars items can be almost anything,
1053  * as a result of subquery-flattening substitutions.
1054  *
1055  * joinleftcols is an integer list of physical column numbers of the left
1056  * join input rel that are included in the join; likewise joinrighttcols
1057  * for the right join input rel. (Which rels those are can be determined
1058  * from the associated JoinExpr.) If the join is USING/NATURAL, then the
1059  * first joinmergedcols entries in each list identify the merged columns.
1060  * The merged columns come first in the join output, then remaining
1061  * columns of the left input, then remaining columns of the right.
1062  *
1063  * Note that input columns could have been dropped after creation of a
1064  * stored rule, if they are not referenced in the query (in particular,
1065  * merged columns could not be dropped); this is not accounted for in
1066  * joinleftcols/joinrighttcols.
1067  */
1068  JoinType jointype; /* type of join */
1069  int joinmergedcols; /* number of merged (JOIN USING) columns */
1070  List *joinaliasvars; /* list of alias-var expansions */
1071  List *joinleftcols; /* left-side input column numbers */
1072  List *joinrightcols; /* right-side input column numbers */
1073 
1074  /*
1075  * join_using_alias is an alias clause attached directly to JOIN/USING. It
1076  * is different from the alias field (below) in that it does not hide the
1077  * range variables of the tables being joined.
1078  */
1080 
1081  /*
1082  * Fields valid for a function RTE (else NIL/zero):
1083  *
1084  * When funcordinality is true, the eref->colnames list includes an alias
1085  * for the ordinality column. The ordinality column is otherwise
1086  * implicit, and must be accounted for "by hand" in places such as
1087  * expandRTE().
1088  */
1089  List *functions; /* list of RangeTblFunction nodes */
1090  bool funcordinality; /* is this called WITH ORDINALITY? */
1091 
1092  /*
1093  * Fields valid for a TableFunc RTE (else NULL):
1094  */
1096 
1097  /*
1098  * Fields valid for a values RTE (else NIL):
1099  */
1100  List *values_lists; /* list of expression lists */
1101 
1102  /*
1103  * Fields valid for a CTE RTE (else NULL/zero):
1104  */
1105  char *ctename; /* name of the WITH list item */
1106  Index ctelevelsup; /* number of query levels up */
1107  bool self_reference; /* is this a recursive self-reference? */
1108 
1109  /*
1110  * Fields valid for CTE, VALUES, ENR, and TableFunc RTEs (else NIL):
1111  *
1112  * We need these for CTE RTEs so that the types of self-referential
1113  * columns are well-defined. For VALUES RTEs, storing these explicitly
1114  * saves having to re-determine the info by scanning the values_lists. For
1115  * ENRs, we store the types explicitly here (we could get the information
1116  * from the catalogs if 'relid' was supplied, but we'd still need these
1117  * for TupleDesc-based ENRs, so we might as well always store the type
1118  * info here). For TableFuncs, these fields are redundant with data in
1119  * the TableFunc node, but keeping them here allows some code sharing with
1120  * the other cases.
1121  *
1122  * For ENRs only, we have to consider the possibility of dropped columns.
1123  * A dropped column is included in these lists, but it will have zeroes in
1124  * all three lists (as well as an empty-string entry in eref). Testing
1125  * for zero coltype is the standard way to detect a dropped column.
1126  */
1127  List *coltypes; /* OID list of column type OIDs */
1128  List *coltypmods; /* integer list of column typmods */
1129  List *colcollations; /* OID list of column collation OIDs */
1130 
1131  /*
1132  * Fields valid for ENR RTEs (else NULL/zero):
1133  */
1134  char *enrname; /* name of ephemeral named relation */
1135  double enrtuples; /* estimated or actual from caller */
1136 
1137  /*
1138  * Fields valid in all RTEs:
1139  */
1140  Alias *alias; /* user-written alias clause, if any */
1141  Alias *eref; /* expanded reference names */
1142  bool lateral; /* subquery, function, or values is LATERAL? */
1143  bool inh; /* inheritance requested? */
1144  bool inFromCl; /* present in FROM clause? */
1145  AclMode requiredPerms; /* bitmask of required access permissions */
1146  Oid checkAsUser; /* if valid, check access as this role */
1147  Bitmapset *selectedCols; /* columns needing SELECT permission */
1148  Bitmapset *insertedCols; /* columns needing INSERT permission */
1149  Bitmapset *updatedCols; /* columns needing UPDATE permission */
1150  Bitmapset *extraUpdatedCols; /* generated columns being updated */
1151  List *securityQuals; /* security barrier quals to apply, if any */
1152 } RangeTblEntry;
1153 
1154 /*
1155  * RangeTblFunction -
1156  * RangeTblEntry subsidiary data for one function in a FUNCTION RTE.
1157  *
1158  * If the function had a column definition list (required for an
1159  * otherwise-unspecified RECORD result), funccolnames lists the names given
1160  * in the definition list, funccoltypes lists their declared column types,
1161  * funccoltypmods lists their typmods, funccolcollations their collations.
1162  * Otherwise, those fields are NIL.
1163  *
1164  * Notice we don't attempt to store info about the results of functions
1165  * returning named composite types, because those can change from time to
1166  * time. We do however remember how many columns we thought the type had
1167  * (including dropped columns!), so that we can successfully ignore any
1168  * columns added after the query was parsed.
1169  */
1170 typedef struct RangeTblFunction
1171 {
1173 
1174  Node *funcexpr; /* expression tree for func call */
1175  int funccolcount; /* number of columns it contributes to RTE */
1176  /* These fields record the contents of a column definition list, if any: */
1177  List *funccolnames; /* column names (list of String) */
1178  List *funccoltypes; /* OID list of column type OIDs */
1179  List *funccoltypmods; /* integer list of column typmods */
1180  List *funccolcollations; /* OID list of column collation OIDs */
1181  /* This is set during planning for use by the executor: */
1182  Bitmapset *funcparams; /* PARAM_EXEC Param IDs affecting this func */
1184 
1185 /*
1186  * TableSampleClause - TABLESAMPLE appearing in a transformed FROM clause
1187  *
1188  * Unlike RangeTableSample, this is a subnode of the relevant RangeTblEntry.
1189  */
1190 typedef struct TableSampleClause
1191 {
1193  Oid tsmhandler; /* OID of the tablesample handler function */
1194  List *args; /* tablesample argument expression(s) */
1195  Expr *repeatable; /* REPEATABLE expression, or NULL if none */
1197 
1198 /*
1199  * WithCheckOption -
1200  * representation of WITH CHECK OPTION checks to be applied to new tuples
1201  * when inserting/updating an auto-updatable view, or RLS WITH CHECK
1202  * policies to be applied when inserting/updating a relation with RLS.
1203  */
1204 typedef enum WCOKind
1205 {
1206  WCO_VIEW_CHECK, /* WCO on an auto-updatable view */
1207  WCO_RLS_INSERT_CHECK, /* RLS INSERT WITH CHECK policy */
1208  WCO_RLS_UPDATE_CHECK, /* RLS UPDATE WITH CHECK policy */
1209  WCO_RLS_CONFLICT_CHECK /* RLS ON CONFLICT DO UPDATE USING policy */
1210 } WCOKind;
1211 
1212 typedef struct WithCheckOption
1213 {
1215  WCOKind kind; /* kind of WCO */
1216  char *relname; /* name of relation that specified the WCO */
1217  char *polname; /* name of RLS policy being checked */
1218  Node *qual; /* constraint qual to check */
1219  bool cascaded; /* true for a cascaded WCO on a view */
1220 } WithCheckOption;
1221 
1222 /*
1223  * SortGroupClause -
1224  * representation of ORDER BY, GROUP BY, PARTITION BY,
1225  * DISTINCT, DISTINCT ON items
1226  *
1227  * You might think that ORDER BY is only interested in defining ordering,
1228  * and GROUP/DISTINCT are only interested in defining equality. However,
1229  * one way to implement grouping is to sort and then apply a "uniq"-like
1230  * filter. So it's also interesting to keep track of possible sort operators
1231  * for GROUP/DISTINCT, and in particular to try to sort for the grouping
1232  * in a way that will also yield a requested ORDER BY ordering. So we need
1233  * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates
1234  * the decision to give them the same representation.
1235  *
1236  * tleSortGroupRef must match ressortgroupref of exactly one entry of the
1237  * query's targetlist; that is the expression to be sorted or grouped by.
1238  * eqop is the OID of the equality operator.
1239  * sortop is the OID of the ordering operator (a "<" or ">" operator),
1240  * or InvalidOid if not available.
1241  * nulls_first means about what you'd expect. If sortop is InvalidOid
1242  * then nulls_first is meaningless and should be set to false.
1243  * hashable is true if eqop is hashable (note this condition also depends
1244  * on the datatype of the input expression).
1245  *
1246  * In an ORDER BY item, all fields must be valid. (The eqop isn't essential
1247  * here, but it's cheap to get it along with the sortop, and requiring it
1248  * to be valid eases comparisons to grouping items.) Note that this isn't
1249  * actually enough information to determine an ordering: if the sortop is
1250  * collation-sensitive, a collation OID is needed too. We don't store the
1251  * collation in SortGroupClause because it's not available at the time the
1252  * parser builds the SortGroupClause; instead, consult the exposed collation
1253  * of the referenced targetlist expression to find out what it is.
1254  *
1255  * In a grouping item, eqop must be valid. If the eqop is a btree equality
1256  * operator, then sortop should be set to a compatible ordering operator.
1257  * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that
1258  * the query presents for the same tlist item. If there is none, we just
1259  * use the default ordering op for the datatype.
1260  *
1261  * If the tlist item's type has a hash opclass but no btree opclass, then
1262  * we will set eqop to the hash equality operator, sortop to InvalidOid,
1263  * and nulls_first to false. A grouping item of this kind can only be
1264  * implemented by hashing, and of course it'll never match an ORDER BY item.
1265  *
1266  * The hashable flag is provided since we generally have the requisite
1267  * information readily available when the SortGroupClause is constructed,
1268  * and it's relatively expensive to get it again later. Note there is no
1269  * need for a "sortable" flag since OidIsValid(sortop) serves the purpose.
1270  *
1271  * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses.
1272  * In SELECT DISTINCT, the distinctClause list is as long or longer than the
1273  * sortClause list, while in SELECT DISTINCT ON it's typically shorter.
1274  * The two lists must match up to the end of the shorter one --- the parser
1275  * rearranges the distinctClause if necessary to make this true. (This
1276  * restriction ensures that only one sort step is needed to both satisfy the
1277  * ORDER BY and set up for the Unique step. This is semantically necessary
1278  * for DISTINCT ON, and presents no real drawback for DISTINCT.)
1279  */
1280 typedef struct SortGroupClause
1281 {
1283  Index tleSortGroupRef; /* reference into targetlist */
1284  Oid eqop; /* the equality operator ('=' op) */
1285  Oid sortop; /* the ordering operator ('<' op), or 0 */
1286  bool nulls_first; /* do NULLs come before normal values? */
1287  bool hashable; /* can eqop be implemented by hashing? */
1288 } SortGroupClause;
1289 
1290 /*
1291  * GroupingSet -
1292  * representation of CUBE, ROLLUP and GROUPING SETS clauses
1293  *
1294  * In a Query with grouping sets, the groupClause contains a flat list of
1295  * SortGroupClause nodes for each distinct expression used. The actual
1296  * structure of the GROUP BY clause is given by the groupingSets tree.
1297  *
1298  * In the raw parser output, GroupingSet nodes (of all types except SIMPLE
1299  * which is not used) are potentially mixed in with the expressions in the
1300  * groupClause of the SelectStmt. (An expression can't contain a GroupingSet,
1301  * but a list may mix GroupingSet and expression nodes.) At this stage, the
1302  * content of each node is a list of expressions, some of which may be RowExprs
1303  * which represent sublists rather than actual row constructors, and nested
1304  * GroupingSet nodes where legal in the grammar. The structure directly
1305  * reflects the query syntax.
1306  *
1307  * In parse analysis, the transformed expressions are used to build the tlist
1308  * and groupClause list (of SortGroupClause nodes), and the groupingSets tree
1309  * is eventually reduced to a fixed format:
1310  *
1311  * EMPTY nodes represent (), and obviously have no content
1312  *
1313  * SIMPLE nodes represent a list of one or more expressions to be treated as an
1314  * atom by the enclosing structure; the content is an integer list of
1315  * ressortgroupref values (see SortGroupClause)
1316  *
1317  * CUBE and ROLLUP nodes contain a list of one or more SIMPLE nodes.
1318  *
1319  * SETS nodes contain a list of EMPTY, SIMPLE, CUBE or ROLLUP nodes, but after
1320  * parse analysis they cannot contain more SETS nodes; enough of the syntactic
1321  * transforms of the spec have been applied that we no longer have arbitrarily
1322  * deep nesting (though we still preserve the use of cube/rollup).
1323  *
1324  * Note that if the groupingSets tree contains no SIMPLE nodes (only EMPTY
1325  * nodes at the leaves), then the groupClause will be empty, but this is still
1326  * an aggregation query (similar to using aggs or HAVING without GROUP BY).
1327  *
1328  * As an example, the following clause:
1329  *
1330  * GROUP BY GROUPING SETS ((a,b), CUBE(c,(d,e)))
1331  *
1332  * looks like this after raw parsing:
1333  *
1334  * SETS( RowExpr(a,b) , CUBE( c, RowExpr(d,e) ) )
1335  *
1336  * and parse analysis converts it to:
1337  *
1338  * SETS( SIMPLE(1,2), CUBE( SIMPLE(3), SIMPLE(4,5) ) )
1339  */
1340 typedef enum GroupingSetKind
1341 {
1347 } GroupingSetKind;
1348 
1349 typedef struct GroupingSet
1350 {
1355 } GroupingSet;
1356 
1357 /*
1358  * WindowClause -
1359  * transformed representation of WINDOW and OVER clauses
1360  *
1361  * A parsed Query's windowClause list contains these structs. "name" is set
1362  * if the clause originally came from WINDOW, and is NULL if it originally
1363  * was an OVER clause (but note that we collapse out duplicate OVERs).
1364  * partitionClause and orderClause are lists of SortGroupClause structs.
1365  * If we have RANGE with offset PRECEDING/FOLLOWING, the semantics of that are
1366  * specified by startInRangeFunc/inRangeColl/inRangeAsc/inRangeNullsFirst
1367  * for the start offset, or endInRangeFunc/inRange* for the end offset.
1368  * winref is an ID number referenced by WindowFunc nodes; it must be unique
1369  * among the members of a Query's windowClause list.
1370  * When refname isn't null, the partitionClause is always copied from there;
1371  * the orderClause might or might not be copied (see copiedOrder); the framing
1372  * options are never copied, per spec.
1373  */
1374 typedef struct WindowClause
1375 {
1377  char *name; /* window name (NULL in an OVER clause) */
1378  char *refname; /* referenced window name, if any */
1379  List *partitionClause; /* PARTITION BY list */
1380  List *orderClause; /* ORDER BY list */
1381  int frameOptions; /* frame_clause options, see WindowDef */
1382  Node *startOffset; /* expression for starting bound, if any */
1383  Node *endOffset; /* expression for ending bound, if any */
1384  Oid startInRangeFunc; /* in_range function for startOffset */
1385  Oid endInRangeFunc; /* in_range function for endOffset */
1386  Oid inRangeColl; /* collation for in_range tests */
1387  bool inRangeAsc; /* use ASC sort order for in_range tests? */
1388  bool inRangeNullsFirst; /* nulls sort first for in_range tests? */
1389  Index winref; /* ID referenced by window functions */
1390  bool copiedOrder; /* did we copy orderClause from refname? */
1391 } WindowClause;
1392 
1393 /*
1394  * RowMarkClause -
1395  * parser output representation of FOR [KEY] UPDATE/SHARE clauses
1396  *
1397  * Query.rowMarks contains a separate RowMarkClause node for each relation
1398  * identified as a FOR [KEY] UPDATE/SHARE target. If one of these clauses
1399  * is applied to a subquery, we generate RowMarkClauses for all normal and
1400  * subquery rels in the subquery, but they are marked pushedDown = true to
1401  * distinguish them from clauses that were explicitly written at this query
1402  * level. Also, Query.hasForUpdate tells whether there were explicit FOR
1403  * UPDATE/SHARE/KEY SHARE clauses in the current query level.
1404  */
1405 typedef struct RowMarkClause
1406 {
1408  Index rti; /* range table index of target relation */
1410  LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */
1411  bool pushedDown; /* pushed down from higher query level? */
1412 } RowMarkClause;
1413 
1414 /*
1415  * WithClause -
1416  * representation of WITH clause
1417  *
1418  * Note: WithClause does not propagate into the Query representation;
1419  * but CommonTableExpr does.
1420  */
1421 typedef struct WithClause
1422 {
1424  List *ctes; /* list of CommonTableExprs */
1425  bool recursive; /* true = WITH RECURSIVE */
1426  int location; /* token location, or -1 if unknown */
1427 } WithClause;
1428 
1429 /*
1430  * InferClause -
1431  * ON CONFLICT unique index inference clause
1432  *
1433  * Note: InferClause does not propagate into the Query representation.
1434  */
1435 typedef struct InferClause
1436 {
1438  List *indexElems; /* IndexElems to infer unique index */
1439  Node *whereClause; /* qualification (partial-index predicate) */
1440  char *conname; /* Constraint name, or NULL if unnamed */
1441  int location; /* token location, or -1 if unknown */
1442 } InferClause;
1443 
1444 /*
1445  * OnConflictClause -
1446  * representation of ON CONFLICT clause
1447  *
1448  * Note: OnConflictClause does not propagate into the Query representation.
1449  */
1450 typedef struct OnConflictClause
1451 {
1453  OnConflictAction action; /* DO NOTHING or UPDATE? */
1454  InferClause *infer; /* Optional index inference clause */
1455  List *targetList; /* the target list (of ResTarget) */
1456  Node *whereClause; /* qualifications */
1457  int location; /* token location, or -1 if unknown */
1459 
1460 /*
1461  * CommonTableExpr -
1462  * representation of WITH list element
1463  */
1464 
1465 typedef enum CTEMaterialize
1466 {
1467  CTEMaterializeDefault, /* no option specified */
1468  CTEMaterializeAlways, /* MATERIALIZED */
1469  CTEMaterializeNever /* NOT MATERIALIZED */
1470 } CTEMaterialize;
1471 
1472 typedef struct CTESearchClause
1473 {
1479 } CTESearchClause;
1480 
1481 typedef struct CTECycleClause
1482 {
1490  /* These fields are set during parse analysis: */
1491  Oid cycle_mark_type; /* common type of _value and _default */
1494  Oid cycle_mark_neop; /* <> operator for type */
1495 } CTECycleClause;
1496 
1497 typedef struct CommonTableExpr
1498 {
1500  char *ctename; /* query name (never qualified) */
1501  List *aliascolnames; /* optional list of column names */
1502  CTEMaterialize ctematerialized; /* is this an optimization fence? */
1503  /* SelectStmt/InsertStmt/etc before parse analysis, Query afterwards: */
1504  Node *ctequery; /* the CTE's subquery */
1507  int location; /* token location, or -1 if unknown */
1508  /* These fields are set during parse analysis: */
1509  bool cterecursive; /* is this CTE actually recursive? */
1510  int cterefcount; /* number of RTEs referencing this CTE
1511  * (excluding internal self-references) */
1512  List *ctecolnames; /* list of output column names */
1513  List *ctecoltypes; /* OID list of output column type OIDs */
1514  List *ctecoltypmods; /* integer list of output column typmods */
1515  List *ctecolcollations; /* OID list of column collation OIDs */
1516 } CommonTableExpr;
1517 
1518 /* Convenience macro to get the output tlist of a CTE's query */
1519 #define GetCTETargetList(cte) \
1520  (AssertMacro(IsA((cte)->ctequery, Query)), \
1521  ((Query *) (cte)->ctequery)->commandType == CMD_SELECT ? \
1522  ((Query *) (cte)->ctequery)->targetList : \
1523  ((Query *) (cte)->ctequery)->returningList)
1524 
1525 /*
1526  * TriggerTransition -
1527  * representation of transition row or table naming clause
1528  *
1529  * Only transition tables are initially supported in the syntax, and only for
1530  * AFTER triggers, but other permutations are accepted by the parser so we can
1531  * give a meaningful message from C code.
1532  */
1533 typedef struct TriggerTransition
1534 {
1536  char *name;
1537  bool isNew;
1538  bool isTable;
1540 
1541 /*****************************************************************************
1542  * Raw Grammar Output Statements
1543  *****************************************************************************/
1544 
1545 /*
1546  * RawStmt --- container for any one statement's raw parse tree
1547  *
1548  * Parse analysis converts a raw parse tree headed by a RawStmt node into
1549  * an analyzed statement headed by a Query node. For optimizable statements,
1550  * the conversion is complex. For utility statements, the parser usually just
1551  * transfers the raw parse tree (sans RawStmt) into the utilityStmt field of
1552  * the Query node, and all the useful work happens at execution time.
1553  *
1554  * stmt_location/stmt_len identify the portion of the source text string
1555  * containing this raw statement (useful for multi-statement strings).
1556  */
1557 typedef struct RawStmt
1558 {
1560  Node *stmt; /* raw parse tree */
1561  int stmt_location; /* start location, or -1 if unknown */
1562  int stmt_len; /* length in bytes; 0 means "rest of string" */
1563 } RawStmt;
1564 
1565 /*****************************************************************************
1566  * Optimizable Statements
1567  *****************************************************************************/
1568 
1569 /* ----------------------
1570  * Insert Statement
1571  *
1572  * The source expression is represented by SelectStmt for both the
1573  * SELECT and VALUES cases. If selectStmt is NULL, then the query
1574  * is INSERT ... DEFAULT VALUES.
1575  * ----------------------
1576  */
1577 typedef struct InsertStmt
1578 {
1580  RangeVar *relation; /* relation to insert into */
1581  List *cols; /* optional: names of the target columns */
1582  Node *selectStmt; /* the source SELECT/VALUES, or NULL */
1583  OnConflictClause *onConflictClause; /* ON CONFLICT clause */
1584  List *returningList; /* list of expressions to return */
1585  WithClause *withClause; /* WITH clause */
1586  OverridingKind override; /* OVERRIDING clause */
1587 } InsertStmt;
1588 
1589 /* ----------------------
1590  * Delete Statement
1591  * ----------------------
1592  */
1593 typedef struct DeleteStmt
1594 {
1596  RangeVar *relation; /* relation to delete from */
1597  List *usingClause; /* optional using clause for more tables */
1598  Node *whereClause; /* qualifications */
1599  List *returningList; /* list of expressions to return */
1600  WithClause *withClause; /* WITH clause */
1601 } DeleteStmt;
1602 
1603 /* ----------------------
1604  * Update Statement
1605  * ----------------------
1606  */
1607 typedef struct UpdateStmt
1608 {
1610  RangeVar *relation; /* relation to update */
1611  List *targetList; /* the target list (of ResTarget) */
1612  Node *whereClause; /* qualifications */
1613  List *fromClause; /* optional from clause for more tables */
1614  List *returningList; /* list of expressions to return */
1615  WithClause *withClause; /* WITH clause */
1616 } UpdateStmt;
1617 
1618 /* ----------------------
1619  * Select Statement
1620  *
1621  * A "simple" SELECT is represented in the output of gram.y by a single
1622  * SelectStmt node; so is a VALUES construct. A query containing set
1623  * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
1624  * nodes, in which the leaf nodes are component SELECTs and the internal nodes
1625  * represent UNION, INTERSECT, or EXCEPT operators. Using the same node
1626  * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
1627  * LIMIT, etc, clause values into a SELECT statement without worrying
1628  * whether it is a simple or compound SELECT.
1629  * ----------------------
1630  */
1631 typedef enum SetOperation
1632 {
1637 } SetOperation;
1638 
1639 typedef struct SelectStmt
1640 {
1642 
1643  /*
1644  * These fields are used only in "leaf" SelectStmts.
1645  */
1646  List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
1647  * lcons(NIL,NIL) for all (SELECT DISTINCT) */
1648  IntoClause *intoClause; /* target for SELECT INTO */
1649  List *targetList; /* the target list (of ResTarget) */
1650  List *fromClause; /* the FROM clause */
1651  Node *whereClause; /* WHERE qualification */
1652  List *groupClause; /* GROUP BY clauses */
1653  bool groupDistinct; /* Is this GROUP BY DISTINCT? */
1654  Node *havingClause; /* HAVING conditional-expression */
1655  List *windowClause; /* WINDOW window_name AS (...), ... */
1656 
1657  /*
1658  * In a "leaf" node representing a VALUES list, the above fields are all
1659  * null, and instead this field is set. Note that the elements of the
1660  * sublists are just expressions, without ResTarget decoration. Also note
1661  * that a list element can be DEFAULT (represented as a SetToDefault
1662  * node), regardless of the context of the VALUES list. It's up to parse
1663  * analysis to reject that where not valid.
1664  */
1665  List *valuesLists; /* untransformed list of expression lists */
1666 
1667  /*
1668  * These fields are used in both "leaf" SelectStmts and upper-level
1669  * SelectStmts.
1670  */
1671  List *sortClause; /* sort clause (a list of SortBy's) */
1672  Node *limitOffset; /* # of result tuples to skip */
1673  Node *limitCount; /* # of result tuples to return */
1674  LimitOption limitOption; /* limit type */
1675  List *lockingClause; /* FOR UPDATE (list of LockingClause's) */
1676  WithClause *withClause; /* WITH clause */
1677 
1678  /*
1679  * These fields are used only in upper-level SelectStmts.
1680  */
1681  SetOperation op; /* type of set op */
1682  bool all; /* ALL specified? */
1683  struct SelectStmt *larg; /* left child */
1684  struct SelectStmt *rarg; /* right child */
1685  /* Eventually add fields for CORRESPONDING spec here */
1686 } SelectStmt;
1687 
1688 
1689 /* ----------------------
1690  * Set Operation node for post-analysis query trees
1691  *
1692  * After parse analysis, a SELECT with set operations is represented by a
1693  * top-level Query node containing the leaf SELECTs as subqueries in its
1694  * range table. Its setOperations field shows the tree of set operations,
1695  * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
1696  * nodes replaced by SetOperationStmt nodes. Information about the output
1697  * column types is added, too. (Note that the child nodes do not necessarily
1698  * produce these types directly, but we've checked that their output types
1699  * can be coerced to the output column type.) Also, if it's not UNION ALL,
1700  * information about the types' sort/group semantics is provided in the form
1701  * of a SortGroupClause list (same representation as, eg, DISTINCT).
1702  * The resolved common column collations are provided too; but note that if
1703  * it's not UNION ALL, it's okay for a column to not have a common collation,
1704  * so a member of the colCollations list could be InvalidOid even though the
1705  * column has a collatable type.
1706  * ----------------------
1707  */
1708 typedef struct SetOperationStmt
1709 {
1711  SetOperation op; /* type of set op */
1712  bool all; /* ALL specified? */
1713  Node *larg; /* left child */
1714  Node *rarg; /* right child */
1715  /* Eventually add fields for CORRESPONDING spec here */
1716 
1717  /* Fields derived during parse analysis: */
1718  List *colTypes; /* OID list of output column type OIDs */
1719  List *colTypmods; /* integer list of output column typmods */
1720  List *colCollations; /* OID list of output column collation OIDs */
1721  List *groupClauses; /* a list of SortGroupClause's */
1722  /* groupClauses is NIL if UNION ALL, but must be set otherwise */
1724 
1725 
1726 /*
1727  * RETURN statement (inside SQL function body)
1728  */
1729 typedef struct ReturnStmt
1730 {
1733 } ReturnStmt;
1734 
1735 
1736 /* ----------------------
1737  * PL/pgSQL Assignment Statement
1738  *
1739  * Like SelectStmt, this is transformed into a SELECT Query.
1740  * However, the targetlist of the result looks more like an UPDATE.
1741  * ----------------------
1742  */
1743 typedef struct PLAssignStmt
1744 {
1746 
1747  char *name; /* initial column name */
1748  List *indirection; /* subscripts and field names, if any */
1749  int nnames; /* number of names to use in ColumnRef */
1750  SelectStmt *val; /* the PL/pgSQL expression to assign */
1751  int location; /* name's token location, or -1 if unknown */
1752 } PLAssignStmt;
1753 
1754 
1755 /*****************************************************************************
1756  * Other Statements (no optimizations required)
1757  *
1758  * These are not touched by parser/analyze.c except to put them into
1759  * the utilityStmt field of a Query. This is eventually passed to
1760  * ProcessUtility (by-passing rewriting and planning). Some of the
1761  * statements do need attention from parse analysis, and this is
1762  * done by routines in parser/parse_utilcmd.c after ProcessUtility
1763  * receives the command for execution.
1764  * DECLARE CURSOR, EXPLAIN, and CREATE TABLE AS are special cases:
1765  * they contain optimizable statements, which get processed normally
1766  * by parser/analyze.c.
1767  *****************************************************************************/
1768 
1769 /*
1770  * When a command can act on several kinds of objects with only one
1771  * parse structure required, use these constants to designate the
1772  * object type. Note that commands typically don't support all the types.
1773  */
1774 
1775 typedef enum ObjectType
1776 {
1781  OBJECT_ATTRIBUTE, /* type's attribute, when distinct from column */
1827 } ObjectType;
1828 
1829 /* ----------------------
1830  * Create Schema Statement
1831  *
1832  * NOTE: the schemaElts list contains raw parsetrees for component statements
1833  * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
1834  * executed after the schema itself is created.
1835  * ----------------------
1836  */
1837 typedef struct CreateSchemaStmt
1838 {
1840  char *schemaname; /* the name of the schema to create */
1841  RoleSpec *authrole; /* the owner of the created schema */
1842  List *schemaElts; /* schema components (list of parsenodes) */
1843  bool if_not_exists; /* just do nothing if schema already exists? */
1845 
1846 typedef enum DropBehavior
1847 {
1848  DROP_RESTRICT, /* drop fails if any dependent objects */
1849  DROP_CASCADE /* remove dependent objects too */
1850 } DropBehavior;
1851 
1852 /* ----------------------
1853  * Alter Table
1854  * ----------------------
1855  */
1856 typedef struct AlterTableStmt
1857 {
1859  RangeVar *relation; /* table to work on */
1860  List *cmds; /* list of subcommands */
1861  ObjectType objtype; /* type of object */
1862  bool missing_ok; /* skip error if table missing */
1863 } AlterTableStmt;
1864 
1865 typedef enum AlterTableType
1866 {
1867  AT_AddColumn, /* add column */
1868  AT_AddColumnRecurse, /* internal to commands/tablecmds.c */
1869  AT_AddColumnToView, /* implicitly via CREATE OR REPLACE VIEW */
1870  AT_ColumnDefault, /* alter column default */
1871  AT_CookedColumnDefault, /* add a pre-cooked column default */
1872  AT_DropNotNull, /* alter column drop not null */
1873  AT_SetNotNull, /* alter column set not null */
1874  AT_DropExpression, /* alter column drop expression */
1875  AT_CheckNotNull, /* check column is already marked not null */
1876  AT_SetStatistics, /* alter column set statistics */
1877  AT_SetOptions, /* alter column set ( options ) */
1878  AT_ResetOptions, /* alter column reset ( options ) */
1879  AT_SetStorage, /* alter column set storage */
1880  AT_SetCompression, /* alter column set compression */
1881  AT_DropColumn, /* drop column */
1882  AT_DropColumnRecurse, /* internal to commands/tablecmds.c */
1883  AT_AddIndex, /* add index */
1884  AT_ReAddIndex, /* internal to commands/tablecmds.c */
1885  AT_AddConstraint, /* add constraint */
1886  AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */
1887  AT_ReAddConstraint, /* internal to commands/tablecmds.c */
1888  AT_ReAddDomainConstraint, /* internal to commands/tablecmds.c */
1889  AT_AlterConstraint, /* alter constraint */
1890  AT_ValidateConstraint, /* validate constraint */
1891  AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */
1892  AT_AddIndexConstraint, /* add constraint using existing index */
1893  AT_DropConstraint, /* drop constraint */
1894  AT_DropConstraintRecurse, /* internal to commands/tablecmds.c */
1895  AT_ReAddComment, /* internal to commands/tablecmds.c */
1896  AT_AlterColumnType, /* alter column type */
1897  AT_AlterColumnGenericOptions, /* alter column OPTIONS (...) */
1898  AT_ChangeOwner, /* change owner */
1899  AT_ClusterOn, /* CLUSTER ON */
1900  AT_DropCluster, /* SET WITHOUT CLUSTER */
1901  AT_SetLogged, /* SET LOGGED */
1902  AT_SetUnLogged, /* SET UNLOGGED */
1903  AT_DropOids, /* SET WITHOUT OIDS */
1904  AT_SetAccessMethod, /* SET ACCESS METHOD */
1905  AT_SetTableSpace, /* SET TABLESPACE */
1906  AT_SetRelOptions, /* SET (...) -- AM specific parameters */
1907  AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */
1908  AT_ReplaceRelOptions, /* replace reloption list in its entirety */
1909  AT_EnableTrig, /* ENABLE TRIGGER name */
1910  AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */
1911  AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */
1912  AT_DisableTrig, /* DISABLE TRIGGER name */
1913  AT_EnableTrigAll, /* ENABLE TRIGGER ALL */
1914  AT_DisableTrigAll, /* DISABLE TRIGGER ALL */
1915  AT_EnableTrigUser, /* ENABLE TRIGGER USER */
1916  AT_DisableTrigUser, /* DISABLE TRIGGER USER */
1917  AT_EnableRule, /* ENABLE RULE name */
1918  AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */
1919  AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */
1920  AT_DisableRule, /* DISABLE RULE name */
1921  AT_AddInherit, /* INHERIT parent */
1922  AT_DropInherit, /* NO INHERIT parent */
1923  AT_AddOf, /* OF <type_name> */
1924  AT_DropOf, /* NOT OF */
1925  AT_ReplicaIdentity, /* REPLICA IDENTITY */
1926  AT_EnableRowSecurity, /* ENABLE ROW SECURITY */
1927  AT_DisableRowSecurity, /* DISABLE ROW SECURITY */
1928  AT_ForceRowSecurity, /* FORCE ROW SECURITY */
1929  AT_NoForceRowSecurity, /* NO FORCE ROW SECURITY */
1930  AT_GenericOptions, /* OPTIONS (...) */
1931  AT_AttachPartition, /* ATTACH PARTITION */
1932  AT_DetachPartition, /* DETACH PARTITION */
1933  AT_DetachPartitionFinalize, /* DETACH PARTITION FINALIZE */
1934  AT_AddIdentity, /* ADD IDENTITY */
1935  AT_SetIdentity, /* SET identity column options */
1936  AT_DropIdentity, /* DROP IDENTITY */
1937  AT_ReAddStatistics /* internal to commands/tablecmds.c */
1938 } AlterTableType;
1939 
1940 typedef struct ReplicaIdentityStmt
1941 {
1944  char *name;
1946 
1947 typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */
1948 {
1950  AlterTableType subtype; /* Type of table alteration to apply */
1951  char *name; /* column, constraint, or trigger to act on,
1952  * or tablespace */
1953  int16 num; /* attribute number for columns referenced by
1954  * number */
1956  Node *def; /* definition of new column, index,
1957  * constraint, or parent table */
1958  DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
1959  bool missing_ok; /* skip error if missing? */
1960 } AlterTableCmd;
1961 
1962 
1963 /* ----------------------
1964  * Alter Collation
1965  * ----------------------
1966  */
1967 typedef struct AlterCollationStmt
1968 {
1972 
1973 
1974 /* ----------------------
1975  * Alter Domain
1976  *
1977  * The fields are used in different ways by the different variants of
1978  * this command.
1979  * ----------------------
1980  */
1981 typedef struct AlterDomainStmt
1982 {
1984  char subtype; /*------------
1985  * T = alter column default
1986  * N = alter column drop not null
1987  * O = alter column set not null
1988  * C = add constraint
1989  * X = drop constraint
1990  *------------
1991  */
1992  List *typeName; /* domain to work on */
1993  char *name; /* column or constraint name to act on */
1994  Node *def; /* definition of default or constraint */
1995  DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
1996  bool missing_ok; /* skip error if missing? */
1997 } AlterDomainStmt;
1998 
1999 
2000 /* ----------------------
2001  * Grant|Revoke Statement
2002  * ----------------------
2003  */
2004 typedef enum GrantTargetType
2005 {
2006  ACL_TARGET_OBJECT, /* grant on specific named object(s) */
2007  ACL_TARGET_ALL_IN_SCHEMA, /* grant on all objects in given schema(s) */
2008  ACL_TARGET_DEFAULTS /* ALTER DEFAULT PRIVILEGES */
2009 } GrantTargetType;
2010 
2011 typedef struct GrantStmt
2012 {
2014  bool is_grant; /* true = GRANT, false = REVOKE */
2015  GrantTargetType targtype; /* type of the grant target */
2016  ObjectType objtype; /* kind of object being operated on */
2017  List *objects; /* list of RangeVar nodes, ObjectWithArgs
2018  * nodes, or plain names (as Value strings) */
2019  List *privileges; /* list of AccessPriv nodes */
2020  /* privileges == NIL denotes ALL PRIVILEGES */
2021  List *grantees; /* list of RoleSpec nodes */
2022  bool grant_option; /* grant or revoke grant option */
2024  DropBehavior behavior; /* drop behavior (for REVOKE) */
2025 } GrantStmt;
2026 
2027 /*
2028  * ObjectWithArgs represents a function/procedure/operator name plus parameter
2029  * identification.
2030  *
2031  * objargs includes only the types of the input parameters of the object.
2032  * In some contexts, that will be all we have, and it's enough to look up
2033  * objects according to the traditional Postgres rules (i.e., when only input
2034  * arguments matter).
2035  *
2036  * objfuncargs, if not NIL, carries the full specification of the parameter
2037  * list, including parameter mode annotations.
2038  *
2039  * Some grammar productions can set args_unspecified = true instead of
2040  * providing parameter info. In this case, lookup will succeed only if
2041  * the object name is unique. Note that otherwise, NIL parameter lists
2042  * mean zero arguments.
2043  */
2044 typedef struct ObjectWithArgs
2045 {
2047  List *objname; /* qualified name of function/operator */
2048  List *objargs; /* list of Typename nodes (input args only) */
2049  List *objfuncargs; /* list of FunctionParameter nodes */
2050  bool args_unspecified; /* argument list was omitted? */
2051 } ObjectWithArgs;
2052 
2053 /*
2054  * An access privilege, with optional list of column names
2055  * priv_name == NULL denotes ALL PRIVILEGES (only used with a column list)
2056  * cols == NIL denotes "all columns"
2057  * Note that simple "ALL PRIVILEGES" is represented as a NIL list, not
2058  * an AccessPriv with both fields null.
2059  */
2060 typedef struct AccessPriv
2061 {
2063  char *priv_name; /* string name of privilege */
2064  List *cols; /* list of Value strings */
2065 } AccessPriv;
2066 
2067 /* ----------------------
2068  * Grant/Revoke Role Statement
2069  *
2070  * Note: because of the parsing ambiguity with the GRANT <privileges>
2071  * statement, granted_roles is a list of AccessPriv; the execution code
2072  * should complain if any column lists appear. grantee_roles is a list
2073  * of role names, as Value strings.
2074  * ----------------------
2075  */
2076 typedef struct GrantRoleStmt
2077 {
2079  List *granted_roles; /* list of roles to be granted/revoked */
2080  List *grantee_roles; /* list of member roles to add/delete */
2081  bool is_grant; /* true = GRANT, false = REVOKE */
2082  bool admin_opt; /* with admin option */
2083  RoleSpec *grantor; /* set grantor to other than current role */
2084  DropBehavior behavior; /* drop behavior (for REVOKE) */
2085 } GrantRoleStmt;
2086 
2087 /* ----------------------
2088  * Alter Default Privileges Statement
2089  * ----------------------
2090  */
2092 {
2094  List *options; /* list of DefElem */
2095  GrantStmt *action; /* GRANT/REVOKE action (with objects=NIL) */
2097 
2098 /* ----------------------
2099  * Copy Statement
2100  *
2101  * We support "COPY relation FROM file", "COPY relation TO file", and
2102  * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation"
2103  * and "query" must be non-NULL.
2104  * ----------------------
2105  */
2106 typedef struct CopyStmt
2107 {
2109  RangeVar *relation; /* the relation to copy */
2110  Node *query; /* the query (SELECT or DML statement with
2111  * RETURNING) to copy, as a raw parse tree */
2112  List *attlist; /* List of column names (as Strings), or NIL
2113  * for all columns */
2114  bool is_from; /* TO or FROM */
2115  bool is_program; /* is 'filename' a program to popen? */
2116  char *filename; /* filename, or NULL for STDIN/STDOUT */
2117  List *options; /* List of DefElem nodes */
2118  Node *whereClause; /* WHERE condition (or NULL) */
2119 } CopyStmt;
2120 
2121 /* ----------------------
2122  * SET Statement (includes RESET)
2123  *
2124  * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
2125  * preserve the distinction in VariableSetKind for CreateCommandTag().
2126  * ----------------------
2127  */
2128 typedef enum VariableSetKind
2129 {
2130  VAR_SET_VALUE, /* SET var = value */
2131  VAR_SET_DEFAULT, /* SET var TO DEFAULT */
2132  VAR_SET_CURRENT, /* SET var FROM CURRENT */
2133  VAR_SET_MULTI, /* special case for SET TRANSACTION ... */
2134  VAR_RESET, /* RESET var */
2135  VAR_RESET_ALL /* RESET ALL */
2136 } VariableSetKind;
2137 
2138 typedef struct VariableSetStmt
2139 {
2142  char *name; /* variable to be set */
2143  List *args; /* List of A_Const nodes */
2144  bool is_local; /* SET LOCAL? */
2145 } VariableSetStmt;
2146 
2147 /* ----------------------
2148  * Show Statement
2149  * ----------------------
2150  */
2151 typedef struct VariableShowStmt
2152 {
2154  char *name;
2156 
2157 /* ----------------------
2158  * Create Table Statement
2159  *
2160  * NOTE: in the raw gram.y output, ColumnDef and Constraint nodes are
2161  * intermixed in tableElts, and constraints is NIL. After parse analysis,
2162  * tableElts contains just ColumnDefs, and constraints contains just
2163  * Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
2164  * implementation).
2165  * ----------------------
2166  */
2167 
2168 typedef struct CreateStmt
2169 {
2171  RangeVar *relation; /* relation to create */
2172  List *tableElts; /* column definitions (list of ColumnDef) */
2173  List *inhRelations; /* relations to inherit from (list of
2174  * RangeVar) */
2175  PartitionBoundSpec *partbound; /* FOR VALUES clause */
2176  PartitionSpec *partspec; /* PARTITION BY clause */
2177  TypeName *ofTypename; /* OF typename */
2178  List *constraints; /* constraints (list of Constraint nodes) */
2179  List *options; /* options from WITH clause */
2180  OnCommitAction oncommit; /* what do we do at COMMIT? */
2181  char *tablespacename; /* table space to use, or NULL */
2182  char *accessMethod; /* table access method */
2183  bool if_not_exists; /* just do nothing if it already exists? */
2184 } CreateStmt;
2185 
2186 /* ----------
2187  * Definitions for constraints in CreateStmt
2188  *
2189  * Note that column defaults are treated as a type of constraint,
2190  * even though that's a bit odd semantically.
2191  *
2192  * For constraints that use expressions (CONSTR_CHECK, CONSTR_DEFAULT)
2193  * we may have the expression in either "raw" form (an untransformed
2194  * parse tree) or "cooked" form (the nodeToString representation of
2195  * an executable expression tree), depending on how this Constraint
2196  * node was created (by parsing, or by inheritance from an existing
2197  * relation). We should never have both in the same node!
2198  *
2199  * FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
2200  * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
2201  * stored into pg_constraint.confmatchtype. Changing the code values may
2202  * require an initdb!
2203  *
2204  * If skip_validation is true then we skip checking that the existing rows
2205  * in the table satisfy the constraint, and just install the catalog entries
2206  * for the constraint. A new FK constraint is marked as valid iff
2207  * initially_valid is true. (Usually skip_validation and initially_valid
2208  * are inverses, but we can set both true if the table is known empty.)
2209  *
2210  * Constraint attributes (DEFERRABLE etc) are initially represented as
2211  * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes
2212  * a pass through the constraints list to insert the info into the appropriate
2213  * Constraint node.
2214  * ----------
2215  */
2216 
2217 typedef enum ConstrType /* types of constraints */
2218 {
2219  CONSTR_NULL, /* not standard SQL, but a lot of people
2220  * expect it */
2230  CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
2234 } ConstrType;
2235 
2236 /* Foreign key action codes */
2237 #define FKCONSTR_ACTION_NOACTION 'a'
2238 #define FKCONSTR_ACTION_RESTRICT 'r'
2239 #define FKCONSTR_ACTION_CASCADE 'c'
2240 #define FKCONSTR_ACTION_SETNULL 'n'
2241 #define FKCONSTR_ACTION_SETDEFAULT 'd'
2242 
2243 /* Foreign key matchtype codes */
2244 #define FKCONSTR_MATCH_FULL 'f'
2245 #define FKCONSTR_MATCH_PARTIAL 'p'
2246 #define FKCONSTR_MATCH_SIMPLE 's'
2247 
2248 typedef struct Constraint
2249 {
2251  ConstrType contype; /* see above */
2252 
2253  /* Fields used for most/all constraint types: */
2254  char *conname; /* Constraint name, or NULL if unnamed */
2255  bool deferrable; /* DEFERRABLE? */
2256  bool initdeferred; /* INITIALLY DEFERRED? */
2257  int location; /* token location, or -1 if unknown */
2258 
2259  /* Fields used for constraints with expressions (CHECK and DEFAULT): */
2260  bool is_no_inherit; /* is constraint non-inheritable? */
2261  Node *raw_expr; /* expr, as untransformed parse tree */
2262  char *cooked_expr; /* expr, as nodeToString representation */
2263  char generated_when; /* ALWAYS or BY DEFAULT */
2264 
2265  /* Fields used for unique constraints (UNIQUE and PRIMARY KEY): */
2266  List *keys; /* String nodes naming referenced key
2267  * column(s) */
2268  List *including; /* String nodes naming referenced nonkey
2269  * column(s) */
2270 
2271  /* Fields used for EXCLUSION constraints: */
2272  List *exclusions; /* list of (IndexElem, operator name) pairs */
2273 
2274  /* Fields used for index constraints (UNIQUE, PRIMARY KEY, EXCLUSION): */
2275  List *options; /* options from WITH clause */
2276  char *indexname; /* existing index to use; otherwise NULL */
2277  char *indexspace; /* index tablespace; NULL for default */
2278  bool reset_default_tblspc; /* reset default_tablespace prior to
2279  * creating the index */
2280  /* These could be, but currently are not, used for UNIQUE/PKEY: */
2281  char *access_method; /* index access method; NULL for default */
2282  Node *where_clause; /* partial index predicate */
2283 
2284  /* Fields used for FOREIGN KEY constraints: */
2285  RangeVar *pktable; /* Primary key table */
2286  List *fk_attrs; /* Attributes of foreign key */
2287  List *pk_attrs; /* Corresponding attrs in PK table */
2288  char fk_matchtype; /* FULL, PARTIAL, SIMPLE */
2289  char fk_upd_action; /* ON UPDATE action */
2290  char fk_del_action; /* ON DELETE action */
2291  List *old_conpfeqop; /* pg_constraint.conpfeqop of my former self */
2292  Oid old_pktable_oid; /* pg_constraint.confrelid of my former
2293  * self */
2294 
2295  /* Fields used for constraints that allow a NOT VALID specification */
2296  bool skip_validation; /* skip validation of existing rows? */
2297  bool initially_valid; /* mark the new constraint as valid? */
2298 } Constraint;
2299 
2300 /* ----------------------
2301  * Create/Drop Table Space Statements
2302  * ----------------------
2303  */
2304 
2305 typedef struct CreateTableSpaceStmt
2306 {
2310  char *location;
2313 
2314 typedef struct DropTableSpaceStmt
2315 {
2318  bool missing_ok; /* skip error if missing? */
2320 
2322 {
2326  bool isReset;
2328 
2330 {
2333  ObjectType objtype; /* Object type to move */
2334  List *roles; /* List of roles to move objects of */
2336  bool nowait;
2338 
2339 /* ----------------------
2340  * Create/Alter Extension Statements
2341  * ----------------------
2342  */
2343 
2344 typedef struct CreateExtensionStmt
2345 {
2347  char *extname;
2348  bool if_not_exists; /* just do nothing if it already exists? */
2349  List *options; /* List of DefElem nodes */
2351 
2352 /* Only used for ALTER EXTENSION UPDATE; later might need an action field */
2353 typedef struct AlterExtensionStmt
2354 {
2356  char *extname;
2357  List *options; /* List of DefElem nodes */
2359 
2361 {
2363  char *extname; /* Extension's name */
2364  int action; /* +1 = add object, -1 = drop object */
2365  ObjectType objtype; /* Object's type */
2366  Node *object; /* Qualified name of the object */
2368 
2369 /* ----------------------
2370  * Create/Alter FOREIGN DATA WRAPPER Statements
2371  * ----------------------
2372  */
2373 
2374 typedef struct CreateFdwStmt
2375 {
2377  char *fdwname; /* foreign-data wrapper name */
2378  List *func_options; /* HANDLER/VALIDATOR options */
2379  List *options; /* generic options to FDW */
2380 } CreateFdwStmt;
2381 
2382 typedef struct AlterFdwStmt
2383 {
2385  char *fdwname; /* foreign-data wrapper name */
2386  List *func_options; /* HANDLER/VALIDATOR options */
2387  List *options; /* generic options to FDW */
2388 } AlterFdwStmt;
2389 
2390 /* ----------------------
2391  * Create/Alter FOREIGN SERVER Statements
2392  * ----------------------
2393  */
2394 
2396 {
2398  char *servername; /* server name */
2399  char *servertype; /* optional server type */
2400  char *version; /* optional server version */
2401  char *fdwname; /* FDW name */
2402  bool if_not_exists; /* just do nothing if it already exists? */
2403  List *options; /* generic options to server */
2405 
2407 {
2409  char *servername; /* server name */
2410  char *version; /* optional server version */
2411  List *options; /* generic options to server */
2412  bool has_version; /* version specified */
2414 
2415 /* ----------------------
2416  * Create FOREIGN TABLE Statement
2417  * ----------------------
2418  */
2419 
2421 {
2423  char *servername;
2426 
2427 /* ----------------------
2428  * Create/Drop USER MAPPING Statements
2429  * ----------------------
2430  */
2431 
2433 {
2435  RoleSpec *user; /* user role */
2436  char *servername; /* server name */
2437  bool if_not_exists; /* just do nothing if it already exists? */
2438  List *options; /* generic options to server */
2440 
2441 typedef struct AlterUserMappingStmt
2442 {
2444  RoleSpec *user; /* user role */
2445  char *servername; /* server name */
2446  List *options; /* generic options to server */
2448 
2449 typedef struct DropUserMappingStmt
2450 {
2452  RoleSpec *user; /* user role */
2453  char *servername; /* server name */
2454  bool missing_ok; /* ignore missing mappings */
2456 
2457 /* ----------------------
2458  * Import Foreign Schema Statement
2459  * ----------------------
2460  */
2461 
2463 {
2464  FDW_IMPORT_SCHEMA_ALL, /* all relations wanted */
2465  FDW_IMPORT_SCHEMA_LIMIT_TO, /* include only listed tables in import */
2466  FDW_IMPORT_SCHEMA_EXCEPT /* exclude listed tables from import */
2468 
2470 {
2472  char *server_name; /* FDW server name */
2473  char *remote_schema; /* remote schema name to query */
2474  char *local_schema; /* local schema to create objects in */
2475  ImportForeignSchemaType list_type; /* type of table list */
2476  List *table_list; /* List of RangeVar */
2477  List *options; /* list of options to pass to FDW */
2479 
2480 /*----------------------
2481  * Create POLICY Statement
2482  *----------------------
2483  */
2484 typedef struct CreatePolicyStmt
2485 {
2487  char *policy_name; /* Policy's name */
2488  RangeVar *table; /* the table name the policy applies to */
2489  char *cmd_name; /* the command name the policy applies to */
2490  bool permissive; /* restrictive or permissive policy */
2491  List *roles; /* the roles associated with the policy */
2492  Node *qual; /* the policy's condition */
2493  Node *with_check; /* the policy's WITH CHECK condition. */
2495 
2496 /*----------------------
2497  * Alter POLICY Statement
2498  *----------------------
2499  */
2500 typedef struct AlterPolicyStmt
2501 {
2503  char *policy_name; /* Policy's name */
2504  RangeVar *table; /* the table name the policy applies to */
2505  List *roles; /* the roles associated with the policy */
2506  Node *qual; /* the policy's condition */
2507  Node *with_check; /* the policy's WITH CHECK condition. */
2508 } AlterPolicyStmt;
2509 
2510 /*----------------------
2511  * Create ACCESS METHOD Statement
2512  *----------------------
2513  */
2514 typedef struct CreateAmStmt
2515 {
2517  char *amname; /* access method name */
2518  List *handler_name; /* handler function name */
2519  char amtype; /* type of access method */
2520 } CreateAmStmt;
2521 
2522 /* ----------------------
2523  * Create TRIGGER Statement
2524  * ----------------------
2525  */
2526 typedef struct CreateTrigStmt
2527 {
2529  bool replace; /* replace trigger if already exists */
2530  bool isconstraint; /* This is a constraint trigger */
2531  char *trigname; /* TRIGGER's name */
2532  RangeVar *relation; /* relation trigger is on */
2533  List *funcname; /* qual. name of function to call */
2534  List *args; /* list of (T_String) Values or NIL */
2535  bool row; /* ROW/STATEMENT */
2536  /* timing uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */
2537  int16 timing; /* BEFORE, AFTER, or INSTEAD */
2538  /* events uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */
2539  int16 events; /* "OR" of INSERT/UPDATE/DELETE/TRUNCATE */
2540  List *columns; /* column names, or NIL for all columns */
2541  Node *whenClause; /* qual expression, or NULL if none */
2542  /* explicitly named transition data */
2543  List *transitionRels; /* TriggerTransition nodes, or NIL if none */
2544  /* The remaining fields are only used for constraint triggers */
2545  bool deferrable; /* [NOT] DEFERRABLE */
2546  bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
2547  RangeVar *constrrel; /* opposite relation, if RI trigger */
2548 } CreateTrigStmt;
2549 
2550 /* ----------------------
2551  * Create EVENT TRIGGER Statement
2552  * ----------------------
2553  */
2554 typedef struct CreateEventTrigStmt
2555 {
2557  char *trigname; /* TRIGGER's name */
2558  char *eventname; /* event's identifier */
2559  List *whenclause; /* list of DefElems indicating filtering */
2560  List *funcname; /* qual. name of function to call */
2562 
2563 /* ----------------------
2564  * Alter EVENT TRIGGER Statement
2565  * ----------------------
2566  */
2567 typedef struct AlterEventTrigStmt
2568 {
2570  char *trigname; /* TRIGGER's name */
2571  char tgenabled; /* trigger's firing configuration WRT
2572  * session_replication_role */
2574 
2575 /* ----------------------
2576  * Create LANGUAGE Statements
2577  * ----------------------
2578  */
2579 typedef struct CreatePLangStmt
2580 {
2582  bool replace; /* T => replace if already exists */
2583  char *plname; /* PL name */
2584  List *plhandler; /* PL call handler function (qual. name) */
2585  List *plinline; /* optional inline function (qual. name) */
2586  List *plvalidator; /* optional validator function (qual. name) */
2587  bool pltrusted; /* PL is trusted */
2588 } CreatePLangStmt;
2589 
2590 /* ----------------------
2591  * Create/Alter/Drop Role Statements
2592  *
2593  * Note: these node types are also used for the backwards-compatible
2594  * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases
2595  * there's really no need to distinguish what the original spelling was,
2596  * but for CREATE we mark the type because the defaults vary.
2597  * ----------------------
2598  */
2599 typedef enum RoleStmtType
2600 {
2604 } RoleStmtType;
2605 
2606 typedef struct CreateRoleStmt
2607 {
2609  RoleStmtType stmt_type; /* ROLE/USER/GROUP */
2610  char *role; /* role name */
2611  List *options; /* List of DefElem nodes */
2612 } CreateRoleStmt;
2613 
2614 typedef struct AlterRoleStmt
2615 {
2617  RoleSpec *role; /* role */
2618  List *options; /* List of DefElem nodes */
2619  int action; /* +1 = add members, -1 = drop members */
2620 } AlterRoleStmt;
2621 
2622 typedef struct AlterRoleSetStmt
2623 {
2625  RoleSpec *role; /* role */
2626  char *database; /* database name, or NULL */
2627  VariableSetStmt *setstmt; /* SET or RESET subcommand */
2629 
2630 typedef struct DropRoleStmt
2631 {
2633  List *roles; /* List of roles to remove */
2634  bool missing_ok; /* skip error if a role is missing? */
2635 } DropRoleStmt;
2636 
2637 /* ----------------------
2638  * {Create|Alter} SEQUENCE Statement
2639  * ----------------------
2640  */
2641 
2642 typedef struct CreateSeqStmt
2643 {
2645  RangeVar *sequence; /* the sequence to create */
2647  Oid ownerId; /* ID of owner, or InvalidOid for default */
2649  bool if_not_exists; /* just do nothing if it already exists? */
2650 } CreateSeqStmt;
2651 
2652 typedef struct AlterSeqStmt
2653 {
2655  RangeVar *sequence; /* the sequence to alter */
2658  bool missing_ok; /* skip error if a role is missing? */
2659 } AlterSeqStmt;
2660 
2661 /* ----------------------
2662  * Create {Aggregate|Operator|Type} Statement
2663  * ----------------------
2664  */
2665 typedef struct DefineStmt
2666 {
2668  ObjectType kind; /* aggregate, operator, type */
2669  bool oldstyle; /* hack to signal old CREATE AGG syntax */
2670  List *defnames; /* qualified name (list of Value strings) */
2671  List *args; /* a list of TypeName (if needed) */
2672  List *definition; /* a list of DefElem */
2673  bool if_not_exists; /* just do nothing if it already exists? */
2674  bool replace; /* replace if already exists? */
2675 } DefineStmt;
2676 
2677 /* ----------------------
2678  * Create Domain Statement
2679  * ----------------------
2680  */
2681 typedef struct CreateDomainStmt
2682 {
2684  List *domainname; /* qualified name (list of Value strings) */
2685  TypeName *typeName; /* the base type */
2686  CollateClause *collClause; /* untransformed COLLATE spec, if any */
2687  List *constraints; /* constraints (list of Constraint nodes) */
2689 
2690 /* ----------------------
2691  * Create Operator Class Statement
2692  * ----------------------
2693  */
2694 typedef struct CreateOpClassStmt
2695 {
2697  List *opclassname; /* qualified name (list of Value strings) */
2698  List *opfamilyname; /* qualified name (ditto); NIL if omitted */
2699  char *amname; /* name of index AM opclass is for */
2700  TypeName *datatype; /* datatype of indexed column */
2701  List *items; /* List of CreateOpClassItem nodes */
2702  bool isDefault; /* Should be marked as default for type? */
2704 
2705 #define OPCLASS_ITEM_OPERATOR 1
2706 #define OPCLASS_ITEM_FUNCTION 2
2707 #define OPCLASS_ITEM_STORAGETYPE 3
2708 
2709 typedef struct CreateOpClassItem
2710 {
2712  int itemtype; /* see codes above */
2713  ObjectWithArgs *name; /* operator or function name and args */
2714  int number; /* strategy num or support proc num */
2715  List *order_family; /* only used for ordering operators */
2716  List *class_args; /* amproclefttype/amprocrighttype or
2717  * amoplefttype/amoprighttype */
2718  /* fields used for a storagetype item: */
2719  TypeName *storedtype; /* datatype stored in index */
2721 
2722 /* ----------------------
2723  * Create Operator Family Statement
2724  * ----------------------
2725  */
2726 typedef struct CreateOpFamilyStmt
2727 {
2729  List *opfamilyname; /* qualified name (list of Value strings) */
2730  char *amname; /* name of index AM opfamily is for */
2732 
2733 /* ----------------------
2734  * Alter Operator Family Statement
2735  * ----------------------
2736  */
2737 typedef struct AlterOpFamilyStmt
2738 {
2740  List *opfamilyname; /* qualified name (list of Value strings) */
2741  char *amname; /* name of index AM opfamily is for */
2742  bool isDrop; /* ADD or DROP the items? */
2743  List *items; /* List of CreateOpClassItem nodes */
2745 
2746 /* ----------------------
2747  * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
2748  * ----------------------
2749  */
2750 
2751 typedef struct DropStmt
2752 {
2754  List *objects; /* list of names */
2755  ObjectType removeType; /* object type */
2756  DropBehavior behavior; /* RESTRICT or CASCADE behavior */
2757  bool missing_ok; /* skip error if object is missing? */
2758  bool concurrent; /* drop index concurrently? */
2759 } DropStmt;
2760 
2761 /* ----------------------
2762  * Truncate Table Statement
2763  * ----------------------
2764  */
2765 typedef struct TruncateStmt
2766 {
2768  List *relations; /* relations (RangeVars) to be truncated */
2769  bool restart_seqs; /* restart owned sequences? */
2770  DropBehavior behavior; /* RESTRICT or CASCADE behavior */
2771 } TruncateStmt;
2772 
2773 /* ----------------------
2774  * Comment On Statement
2775  * ----------------------
2776  */
2777 typedef struct CommentStmt
2778 {
2780  ObjectType objtype; /* Object's type */
2781  Node *object; /* Qualified name of the object */
2782  char *comment; /* Comment to insert, or NULL to remove */
2783 } CommentStmt;
2784 
2785 /* ----------------------
2786  * SECURITY LABEL Statement
2787  * ----------------------
2788  */
2789 typedef struct SecLabelStmt
2790 {
2792  ObjectType objtype; /* Object's type */
2793  Node *object; /* Qualified name of the object */
2794  char *provider; /* Label provider (or NULL) */
2795  char *label; /* New security label to be assigned */
2796 } SecLabelStmt;
2797 
2798 /* ----------------------
2799  * Declare Cursor Statement
2800  *
2801  * The "query" field is initially a raw parse tree, and is converted to a
2802  * Query node during parse analysis. Note that rewriting and planning
2803  * of the query are always postponed until execution.
2804  * ----------------------
2805  */
2806 #define CURSOR_OPT_BINARY 0x0001 /* BINARY */
2807 #define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */
2808 #define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */
2809 #define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */
2810 #define CURSOR_OPT_ASENSITIVE 0x0010 /* ASENSITIVE */
2811 #define CURSOR_OPT_HOLD 0x0020 /* WITH HOLD */
2812 /* these planner-control flags do not correspond to any SQL grammar: */
2813 #define CURSOR_OPT_FAST_PLAN 0x0100 /* prefer fast-start plan */
2814 #define CURSOR_OPT_GENERIC_PLAN 0x0200 /* force use of generic plan */
2815 #define CURSOR_OPT_CUSTOM_PLAN 0x0400 /* force use of custom plan */
2816 #define CURSOR_OPT_PARALLEL_OK 0x0800 /* parallel mode OK */
2817 
2818 typedef struct DeclareCursorStmt
2819 {
2821  char *portalname; /* name of the portal (cursor) */
2822  int options; /* bitmask of options (see above) */
2823  Node *query; /* the query (see comments above) */
2825 
2826 /* ----------------------
2827  * Close Portal Statement
2828  * ----------------------
2829  */
2830 typedef struct ClosePortalStmt
2831 {
2833  char *portalname; /* name of the portal (cursor) */
2834  /* NULL means CLOSE ALL */
2835 } ClosePortalStmt;
2836 
2837 /* ----------------------
2838  * Fetch Statement (also Move)
2839  * ----------------------
2840  */
2841 typedef enum FetchDirection
2842 {
2843  /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
2846  /* for these, howMany indicates a position; only one row is fetched */
2849 } FetchDirection;
2850 
2851 #define FETCH_ALL LONG_MAX
2852 
2853 typedef struct FetchStmt
2854 {
2856  FetchDirection direction; /* see above */
2857  long howMany; /* number of rows, or position argument */
2858  char *portalname; /* name of portal (cursor) */
2859  bool ismove; /* true if MOVE */
2860 } FetchStmt;
2861 
2862 /* ----------------------
2863  * Create Index Statement
2864  *
2865  * This represents creation of an index and/or an associated constraint.
2866  * If isconstraint is true, we should create a pg_constraint entry along
2867  * with the index. But if indexOid isn't InvalidOid, we are not creating an
2868  * index, just a UNIQUE/PKEY constraint using an existing index. isconstraint
2869  * must always be true in this case, and the fields describing the index
2870  * properties are empty.
2871  * ----------------------
2872  */
2873 typedef struct IndexStmt
2874 {
2876  char *idxname; /* name of new index, or NULL for default */
2877  RangeVar *relation; /* relation to build index on */
2878  char *accessMethod; /* name of access method (eg. btree) */
2879  char *tableSpace; /* tablespace, or NULL for default */
2880  List *indexParams; /* columns to index: a list of IndexElem */
2881  List *indexIncludingParams; /* additional columns to index: a list
2882  * of IndexElem */
2883  List *options; /* WITH clause options: a list of DefElem */
2884  Node *whereClause; /* qualification (partial-index predicate) */
2885  List *excludeOpNames; /* exclusion operator names, or NIL if none */
2886  char *idxcomment; /* comment to apply to index, or NULL */
2887  Oid indexOid; /* OID of an existing index, if any */
2888  Oid oldNode; /* relfilenode of existing storage, if any */
2889  SubTransactionId oldCreateSubid; /* rd_createSubid of oldNode */
2890  SubTransactionId oldFirstRelfilenodeSubid; /* rd_firstRelfilenodeSubid of
2891  * oldNode */
2892  bool unique; /* is index unique? */
2893  bool primary; /* is index a primary key? */
2894  bool isconstraint; /* is it for a pkey/unique constraint? */
2895  bool deferrable; /* is the constraint DEFERRABLE? */
2896  bool initdeferred; /* is the constraint INITIALLY DEFERRED? */
2897  bool transformed; /* true when transformIndexStmt is finished */
2898  bool concurrent; /* should this be a concurrent index build? */
2899  bool if_not_exists; /* just do nothing if index already exists? */
2900  bool reset_default_tblspc; /* reset default_tablespace prior to
2901  * executing */
2902 } IndexStmt;
2903 
2904 /* ----------------------
2905  * Create Statistics Statement
2906  * ----------------------
2907  */
2908 typedef struct CreateStatsStmt
2909 {
2911  List *defnames; /* qualified name (list of Value strings) */
2912  List *stat_types; /* stat types (list of Value strings) */
2913  List *exprs; /* expressions to build statistics on */
2914  List *relations; /* rels to build stats on (list of RangeVar) */
2915  char *stxcomment; /* comment to apply to stats, or NULL */
2916  bool transformed; /* true when transformStatsStmt is finished */
2917  bool if_not_exists; /* do nothing if stats name already exists */
2918 } CreateStatsStmt;
2919 
2920 /*
2921  * StatsElem - statistics parameters (used in CREATE STATISTICS)
2922  *
2923  * For a plain attribute, 'name' is the name of the referenced table column
2924  * and 'expr' is NULL. For an expression, 'name' is NULL and 'expr' is the
2925  * expression tree.
2926  */
2927 typedef struct StatsElem
2928 {
2930  char *name; /* name of attribute to index, or NULL */
2931  Node *expr; /* expression to index, or NULL */
2932 } StatsElem;
2933 
2934 
2935 /* ----------------------
2936  * Alter Statistics Statement
2937  * ----------------------
2938  */
2939 typedef struct AlterStatsStmt
2940 {
2942  List *defnames; /* qualified name (list of Value strings) */
2943  int stxstattarget; /* statistics target */
2944  bool missing_ok; /* skip error if statistics object is missing */
2945 } AlterStatsStmt;
2946 
2947 /* ----------------------
2948  * Create Function Statement
2949  * ----------------------
2950  */
2951 typedef struct CreateFunctionStmt
2952 {
2954  bool is_procedure; /* it's really CREATE PROCEDURE */
2955  bool replace; /* T => replace if already exists */
2956  List *funcname; /* qualified name of function to create */
2957  List *parameters; /* a list of FunctionParameter */
2958  TypeName *returnType; /* the return type */
2959  List *options; /* a list of DefElem */
2962 
2964 {
2965  /* the assigned enum values appear in pg_proc, don't change 'em! */
2966  FUNC_PARAM_IN = 'i', /* input only */
2967  FUNC_PARAM_OUT = 'o', /* output only */
2968  FUNC_PARAM_INOUT = 'b', /* both */
2969  FUNC_PARAM_VARIADIC = 'v', /* variadic (always input) */
2970  FUNC_PARAM_TABLE = 't', /* table function output column */
2971  /* this is not used in pg_proc: */
2972  FUNC_PARAM_DEFAULT = 'd' /* default; effectively same as IN */
2974 
2975 typedef struct FunctionParameter
2976 {
2978  char *name; /* parameter name, or NULL if not given */
2979  TypeName *argType; /* TypeName for parameter type */
2980  FunctionParameterMode mode; /* IN/OUT/etc */
2981  Node *defexpr; /* raw default expr, or NULL if not given */
2983 
2984 typedef struct AlterFunctionStmt
2985 {
2988  ObjectWithArgs *func; /* name and args of function */
2989  List *actions; /* list of DefElem */
2991 
2992 /* ----------------------
2993  * DO Statement
2994  *
2995  * DoStmt is the raw parser output, InlineCodeBlock is the execution-time API
2996  * ----------------------
2997  */
2998 typedef struct DoStmt
2999 {
3001  List *args; /* List of DefElem nodes */
3002 } DoStmt;
3003 
3004 typedef struct InlineCodeBlock
3005 {
3007  char *source_text; /* source text of anonymous code block */
3008  Oid langOid; /* OID of selected language */
3009  bool langIsTrusted; /* trusted property of the language */
3010  bool atomic; /* atomic execution context */
3011 } InlineCodeBlock;
3012 
3013 /* ----------------------
3014  * CALL statement
3015  *
3016  * OUT-mode arguments are removed from the transformed funcexpr. The outargs
3017  * list contains copies of the expressions for all output arguments, in the
3018  * order of the procedure's declared arguments. (outargs is never evaluated,
3019  * but is useful to the caller as a reference for what to assign to.)
3020  * ----------------------
3021  */
3022 typedef struct CallStmt
3023 {
3025  FuncCall *funccall; /* from the parser */
3026  FuncExpr *funcexpr; /* transformed call, with only input args */
3027  List *outargs; /* transformed output-argument expressions */
3028 } CallStmt;
3029 
3030 typedef struct CallContext
3031 {
3033  bool atomic;
3034 } CallContext;
3035 
3036 /* ----------------------
3037  * Alter Object Rename Statement
3038  * ----------------------
3039  */
3040 typedef struct RenameStmt
3041 {
3043  ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
3044  ObjectType relationType; /* if column name, associated relation type */
3045  RangeVar *relation; /* in case it's a table */
3046  Node *object; /* in case it's some other object */
3047  char *subname; /* name of contained object (column, rule,
3048  * trigger, etc) */
3049  char *newname; /* the new name */
3050  DropBehavior behavior; /* RESTRICT or CASCADE behavior */
3051  bool missing_ok; /* skip error if missing? */
3052 } RenameStmt;
3053 
3054 /* ----------------------
3055  * ALTER object DEPENDS ON EXTENSION extname
3056  * ----------------------
3057  */
3059 {
3061  ObjectType objectType; /* OBJECT_FUNCTION, OBJECT_TRIGGER, etc */
3062  RangeVar *relation; /* in case a table is involved */
3063  Node *object; /* name of the object */
3064  Value *extname; /* extension name */
3065  bool remove; /* set true to remove dep rather than add */
3067 
3068 /* ----------------------
3069  * ALTER object SET SCHEMA Statement
3070  * ----------------------
3071  */
3073 {
3075  ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
3076  RangeVar *relation; /* in case it's a table */
3077  Node *object; /* in case it's some other object */
3078  char *newschema; /* the new schema */
3079  bool missing_ok; /* skip error if missing? */
3081 
3082 /* ----------------------
3083  * Alter Object Owner Statement
3084  * ----------------------
3085  */
3086 typedef struct AlterOwnerStmt
3087 {
3089  ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
3090  RangeVar *relation; /* in case it's a table */
3091  Node *object; /* in case it's some other object */
3092  RoleSpec *newowner; /* the new owner */
3093 } AlterOwnerStmt;
3094 
3095 /* ----------------------
3096  * Alter Operator Set ( this-n-that )
3097  * ----------------------
3098  */
3099 typedef struct AlterOperatorStmt
3100 {
3102  ObjectWithArgs *opername; /* operator name and argument types */
3103  List *options; /* List of DefElem nodes */
3105 
3106 /* ------------------------
3107  * Alter Type Set ( this-n-that )
3108  * ------------------------
3109  */
3110 typedef struct AlterTypeStmt
3111 {
3113  List *typeName; /* type name (possibly qualified) */
3114  List *options; /* List of DefElem nodes */
3115 } AlterTypeStmt;
3116 
3117 /* ----------------------
3118  * Create Rule Statement
3119  * ----------------------
3120  */
3121 typedef struct RuleStmt
3122 {
3124  RangeVar *relation; /* relation the rule is for */
3125  char *rulename; /* name of the rule */
3126  Node *whereClause; /* qualifications */
3127  CmdType event; /* SELECT, INSERT, etc */
3128  bool instead; /* is a 'do instead'? */
3129  List *actions; /* the action statements */
3130  bool replace; /* OR REPLACE */
3131 } RuleStmt;
3132 
3133 /* ----------------------
3134  * Notify Statement
3135  * ----------------------
3136  */
3137 typedef struct NotifyStmt
3138 {
3140  char *conditionname; /* condition name to notify */
3141  char *payload; /* the payload string, or NULL if none */
3142 } NotifyStmt;
3143 
3144 /* ----------------------
3145  * Listen Statement
3146  * ----------------------
3147  */
3148 typedef struct ListenStmt
3149 {
3151  char *conditionname; /* condition name to listen on */
3152 } ListenStmt;
3153 
3154 /* ----------------------
3155  * Unlisten Statement
3156  * ----------------------
3157  */
3158 typedef struct UnlistenStmt
3159 {
3161  char *conditionname; /* name to unlisten on, or NULL for all */
3162 } UnlistenStmt;
3163 
3164 /* ----------------------
3165  * {Begin|Commit|Rollback} Transaction Statement
3166  * ----------------------
3167  */
3169 {
3171  TRANS_STMT_START, /* semantically identical to BEGIN */
3181 
3182 typedef struct TransactionStmt
3183 {
3185  TransactionStmtKind kind; /* see above */
3186  List *options; /* for BEGIN/START commands */
3187  char *savepoint_name; /* for savepoint commands */
3188  char *gid; /* for two-phase-commit related commands */
3189  bool chain; /* AND CHAIN option */
3190 } TransactionStmt;
3191 
3192 /* ----------------------
3193  * Create Type Statement, composite types
3194  * ----------------------
3195  */
3196 typedef struct CompositeTypeStmt
3197 {
3199  RangeVar *typevar; /* the composite type to be created */
3200  List *coldeflist; /* list of ColumnDef nodes */
3202 
3203 /* ----------------------
3204  * Create Type Statement, enum types
3205  * ----------------------
3206  */
3207 typedef struct CreateEnumStmt
3208 {
3210  List *typeName; /* qualified name (list of Value strings) */
3211  List *vals; /* enum values (list of Value strings) */
3212 } CreateEnumStmt;
3213 
3214 /* ----------------------
3215  * Create Type Statement, range types
3216  * ----------------------
3217  */
3218 typedef struct CreateRangeStmt
3219 {
3221  List *typeName; /* qualified name (list of Value strings) */
3222  List *params; /* range parameters (list of DefElem) */
3223 } CreateRangeStmt;
3224 
3225 /* ----------------------
3226  * Alter Type Statement, enum types
3227  * ----------------------
3228  */
3229 typedef struct AlterEnumStmt
3230 {
3232  List *typeName; /* qualified name (list of Value strings) */
3233  char *oldVal; /* old enum value's name, if renaming */
3234  char *newVal; /* new enum value's name */
3235  char *newValNeighbor; /* neighboring enum value, if specified */
3236  bool newValIsAfter; /* place new enum value after neighbor? */
3237  bool skipIfNewValExists; /* no error if new already exists? */
3238 } AlterEnumStmt;
3239 
3240 /* ----------------------
3241  * Create View Statement
3242  * ----------------------
3243  */
3244 typedef enum ViewCheckOption
3245 {
3249 } ViewCheckOption;
3250 
3251 typedef struct ViewStmt
3252 {
3254  RangeVar *view; /* the view to be created */
3255  List *aliases; /* target column names */
3256  Node *query; /* the SELECT query (as a raw parse tree) */
3257  bool replace; /* replace an existing view? */
3258  List *options; /* options from WITH clause */
3259  ViewCheckOption withCheckOption; /* WITH CHECK OPTION */
3260 } ViewStmt;
3261 
3262 /* ----------------------
3263  * Load Statement
3264  * ----------------------
3265  */
3266 typedef struct LoadStmt
3267 {
3269  char *filename; /* file to load */
3270 } LoadStmt;
3271 
3272 /* ----------------------
3273  * Createdb Statement
3274  * ----------------------
3275  */
3276 typedef struct CreatedbStmt
3277 {
3279  char *dbname; /* name of database to create */
3280  List *options; /* List of DefElem nodes */
3281 } CreatedbStmt;
3282 
3283 /* ----------------------
3284  * Alter Database
3285  * ----------------------
3286  */
3287 typedef struct AlterDatabaseStmt
3288 {
3290  char *dbname; /* name of database to alter */
3291  List *options; /* List of DefElem nodes */
3293 
3294 typedef struct AlterDatabaseSetStmt
3295 {
3297  char *dbname; /* database name */
3298  VariableSetStmt *setstmt; /* SET or RESET subcommand */
3300 
3301 /* ----------------------
3302  * Dropdb Statement
3303  * ----------------------
3304  */
3305 typedef struct DropdbStmt
3306 {
3308  char *dbname; /* database to drop */
3309  bool missing_ok; /* skip error if db is missing? */
3310  List *options; /* currently only FORCE is supported */
3311 } DropdbStmt;
3312 
3313 /* ----------------------
3314  * Alter System Statement
3315  * ----------------------
3316  */
3317 typedef struct AlterSystemStmt
3318 {
3320  VariableSetStmt *setstmt; /* SET subcommand */
3321 } AlterSystemStmt;
3322 
3323 /* ----------------------
3324  * Cluster Statement (support pbrown's cluster index implementation)
3325  * ----------------------
3326  */
3327 typedef struct ClusterStmt
3328 {
3330  RangeVar *relation; /* relation being indexed, or NULL if all */
3331  char *indexname; /* original index defined */
3332  List *params; /* list of DefElem nodes */
3333 } ClusterStmt;
3334 
3335 /* ----------------------
3336  * Vacuum and Analyze Statements
3337  *
3338  * Even though these are nominally two statements, it's convenient to use
3339  * just one node type for both.
3340  * ----------------------
3341  */
3342 typedef struct VacuumStmt
3343 {
3345  List *options; /* list of DefElem nodes */
3346  List *rels; /* list of VacuumRelation, or NIL for all */
3347  bool is_vacuumcmd; /* true for VACUUM, false for ANALYZE */
3348 } VacuumStmt;
3349 
3350 /*
3351  * Info about a single target table of VACUUM/ANALYZE.
3352  *
3353  * If the OID field is set, it always identifies the table to process.
3354  * Then the relation field can be NULL; if it isn't, it's used only to report
3355  * failure to open/lock the relation.
3356  */
3357 typedef struct VacuumRelation
3358 {
3360  RangeVar *relation; /* table name to process, or NULL */
3361  Oid oid; /* table's OID; InvalidOid if not looked up */
3362  List *va_cols; /* list of column names, or NIL for all */
3363 } VacuumRelation;
3364 
3365 /* ----------------------
3366  * Explain Statement
3367  *
3368  * The "query" field is initially a raw parse tree, and is converted to a
3369  * Query node during parse analysis. Note that rewriting and planning
3370  * of the query are always postponed until execution.
3371  * ----------------------
3372  */
3373 typedef struct ExplainStmt
3374 {
3376  Node *query; /* the query (see comments above) */
3377  List *options; /* list of DefElem nodes */
3378 } ExplainStmt;
3379 
3380 /* ----------------------
3381  * CREATE TABLE AS Statement (a/k/a SELECT INTO)
3382  *
3383  * A query written as CREATE TABLE AS will produce this node type natively.
3384  * A query written as SELECT ... INTO will be transformed to this form during
3385  * parse analysis.
3386  * A query written as CREATE MATERIALIZED view will produce this node type,
3387  * during parse analysis, since it needs all the same data.
3388  *
3389  * The "query" field is handled similarly to EXPLAIN, though note that it
3390  * can be a SELECT or an EXECUTE, but not other DML statements.
3391  * ----------------------
3392  */
3393 typedef struct CreateTableAsStmt
3394 {
3396  Node *query; /* the query (see comments above) */
3397  IntoClause *into; /* destination table */
3398  ObjectType objtype; /* OBJECT_TABLE or OBJECT_MATVIEW */
3399  bool is_select_into; /* it was written as SELECT INTO */
3400  bool if_not_exists; /* just do nothing if it already exists? */
3402 
3403 /* ----------------------
3404  * REFRESH MATERIALIZED VIEW Statement
3405  * ----------------------
3406  */
3407 typedef struct RefreshMatViewStmt
3408 {
3410  bool concurrent; /* allow concurrent access? */
3411  bool skipData; /* true for WITH NO DATA */
3412  RangeVar *relation; /* relation to insert into */
3414 
3415 /* ----------------------
3416  * Checkpoint Statement
3417  * ----------------------
3418  */
3419 typedef struct CheckPointStmt
3420 {
3422 } CheckPointStmt;
3423 
3424 /* ----------------------
3425  * Discard Statement
3426  * ----------------------
3427  */
3428 
3429 typedef enum DiscardMode
3430 {
3435 } DiscardMode;
3436 
3437 typedef struct DiscardStmt
3438 {
3441 } DiscardStmt;
3442 
3443 /* ----------------------
3444  * LOCK Statement
3445  * ----------------------
3446  */
3447 typedef struct LockStmt
3448 {
3450  List *relations; /* relations to lock */
3451  int mode; /* lock mode */
3452  bool nowait; /* no wait mode */
3453 } LockStmt;
3454 
3455 /* ----------------------
3456  * SET CONSTRAINTS Statement
3457  * ----------------------
3458  */
3459 typedef struct ConstraintsSetStmt
3460 {
3462  List *constraints; /* List of names as RangeVars */
3463  bool deferred;
3465 
3466 /* ----------------------
3467  * REINDEX Statement
3468  * ----------------------
3469  */
3470 typedef enum ReindexObjectType
3471 {
3473  REINDEX_OBJECT_TABLE, /* table or materialized view */
3475  REINDEX_OBJECT_SYSTEM, /* system catalogs */
3478 
3479 typedef struct ReindexStmt
3480 {
3482  ReindexObjectType kind; /* REINDEX_OBJECT_INDEX, REINDEX_OBJECT_TABLE,
3483  * etc. */
3484  RangeVar *relation; /* Table or index to reindex */
3485  const char *name; /* name of database to reindex */
3486  List *params; /* list of DefElem nodes */
3487 } ReindexStmt;
3488 
3489 /* ----------------------
3490  * CREATE CONVERSION Statement
3491  * ----------------------
3492  */
3493 typedef struct CreateConversionStmt
3494 {
3496  List *conversion_name; /* Name of the conversion */
3497  char *for_encoding_name; /* source encoding name */
3498  char *to_encoding_name; /* destination encoding name */
3499  List *func_name; /* qualified conversion function name */
3500  bool def; /* is this a default conversion? */
3502 
3503 /* ----------------------
3504  * CREATE CAST Statement
3505  * ----------------------
3506  */
3507 typedef struct CreateCastStmt
3508 {
3514  bool inout;
3515 } CreateCastStmt;
3516 
3517 /* ----------------------
3518  * CREATE TRANSFORM Statement
3519  * ----------------------
3520  */
3521 typedef struct CreateTransformStmt
3522 {
3524  bool replace;
3526  char *lang;
3530 
3531 /* ----------------------
3532  * PREPARE Statement
3533  * ----------------------
3534  */
3535 typedef struct PrepareStmt
3536 {
3538  char *name; /* Name of plan, arbitrary */
3539  List *argtypes; /* Types of parameters (List of TypeName) */
3540  Node *query; /* The query itself (as a raw parsetree) */
3541 } PrepareStmt;
3542 
3543 
3544 /* ----------------------
3545  * EXECUTE Statement
3546  * ----------------------
3547  */
3548 
3549 typedef struct ExecuteStmt
3550 {
3552  char *name; /* The name of the plan to execute */
3553  List *params; /* Values to assign to parameters */
3554 } ExecuteStmt;
3555 
3556 
3557 /* ----------------------
3558  * DEALLOCATE Statement
3559  * ----------------------
3560  */
3561 typedef struct DeallocateStmt
3562 {
3564  char *name; /* The name of the plan to remove */
3565  /* NULL means DEALLOCATE ALL */
3566 } DeallocateStmt;
3567 
3568 /*
3569  * DROP OWNED statement
3570  */
3571 typedef struct DropOwnedStmt
3572 {
3576 } DropOwnedStmt;
3577 
3578 /*
3579  * REASSIGN OWNED statement
3580  */
3581 typedef struct ReassignOwnedStmt
3582 {
3587 
3588 /*
3589  * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
3590  */
3592 {
3594  List *dictname; /* qualified name (list of Value strings) */
3595  List *options; /* List of DefElem nodes */
3597 
3598 /*
3599  * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
3600  */
3601 typedef enum AlterTSConfigType
3602 {
3609 
3611 {
3613  AlterTSConfigType kind; /* ALTER_TSCONFIG_ADD_MAPPING, etc */
3614  List *cfgname; /* qualified name (list of Value strings) */
3615 
3616  /*
3617  * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is
3618  * NIL, but tokentype isn't, DROP MAPPING was specified.
3619  */
3620  List *tokentype; /* list of Value strings */
3621  List *dicts; /* list of list of Value strings */
3622  bool override; /* if true - remove old variant */
3623  bool replace; /* if true - replace dictionary by another */
3624  bool missing_ok; /* for DROP - skip error if missing? */
3626 
3627 
3629 {
3631  char *pubname; /* Name of the publication */
3632  List *options; /* List of DefElem nodes */
3633  List *tables; /* Optional list of tables to add */
3634  bool for_all_tables; /* Special publication for all tables in db */
3636 
3637 typedef struct AlterPublicationStmt
3638 {
3640  char *pubname; /* Name of the publication */
3641 
3642  /* parameters used for ALTER PUBLICATION ... WITH */
3643  List *options; /* List of DefElem nodes */
3644 
3645  /* parameters used for ALTER PUBLICATION ... ADD/DROP TABLE */
3646  List *tables; /* List of tables to add/drop */
3647  bool for_all_tables; /* Special publication for all tables in db */
3648  DefElemAction tableAction; /* What action to perform with the tables */
3650 
3652 {
3654  char *subname; /* Name of the subscription */
3655  char *conninfo; /* Connection string to publisher */
3656  List *publication; /* One or more publication to subscribe to */
3657  List *options; /* List of DefElem nodes */
3659 
3661 {
3670 
3672 {
3674  AlterSubscriptionType kind; /* ALTER_SUBSCRIPTION_OPTIONS, etc */
3675  char *subname; /* Name of the subscription */
3676  char *conninfo; /* Connection string to publisher */
3677  List *publication; /* One or more publication to subscribe to */
3678  List *options; /* List of DefElem nodes */
3680 
3681 typedef struct DropSubscriptionStmt
3682 {
3684  char *subname; /* Name of the subscription */
3685  bool missing_ok; /* Skip error if missing? */
3686  DropBehavior behavior; /* RESTRICT or CASCADE behavior */
3688 
3689 #endif /* PARSENODES_H */
struct CreateFdwStmt CreateFdwStmt
bool deferrable
Definition: parsenodes.h:2895
RangeVar * relation
Definition: parsenodes.h:2171
ObjectType objtype
Definition: parsenodes.h:2780
bool replace
Definition: parsenodes.h:3257
List * lockedRels
Definition: parsenodes.h:764
RoleSpec * newowner
Definition: parsenodes.h:3092
struct FetchStmt FetchStmt
signed short int16
Definition: c.h:428
List * indirection
Definition: parsenodes.h:453
Node * limitOffset
Definition: parsenodes.h:171
struct AlterDatabaseSetStmt AlterDatabaseSetStmt
List * partitionClause
Definition: parsenodes.h:501
SortByDir
Definition: parsenodes.h:50
char * refname
Definition: parsenodes.h:1378
List * params
Definition: parsenodes.h:3332
NodeTag type
Definition: parsenodes.h:3139
Node * whereClause
Definition: parsenodes.h:2118
struct SelectStmt * larg
Definition: parsenodes.h:1683
bool primary
Definition: parsenodes.h:2893
LimitOption limitOption
Definition: parsenodes.h:1674
bool copiedOrder
Definition: parsenodes.h:1390
OnCommitAction oncommit
Definition: parsenodes.h:2180
TypeName * sourcetype
Definition: parsenodes.h:3510
ConstrType
Definition: parsenodes.h:2217
RoleSpec * role
Definition: parsenodes.h:2617
NodeTag type
Definition: parsenodes.h:3573
List * fromClause
Definition: parsenodes.h:1613
struct DropTableSpaceStmt DropTableSpaceStmt
struct ViewStmt ViewStmt
List * inhRelations
Definition: parsenodes.h:2173
NodeTag type
Definition: parsenodes.h:3481
bool nowait
Definition: parsenodes.h:3452
struct CreateSchemaStmt CreateSchemaStmt
bool search_breadth_first
Definition: parsenodes.h:1476
Alias * alias
Definition: parsenodes.h:579
Oid typeOid
Definition: parsenodes.h:222
ObjectType objtype
Definition: parsenodes.h:2792
List * keys
Definition: parsenodes.h:2266
struct CreateForeignTableStmt CreateForeignTableStmt
NodeTag type
Definition: parsenodes.h:2767
NodeTag type
Definition: parsenodes.h:3253
List * exclusions
Definition: parsenodes.h:2272
struct TableLikeClause TableLikeClause
ObjectWithArgs * tosql
Definition: parsenodes.h:3528
List * joinaliasvars
Definition: parsenodes.h:1070
Node * val
Definition: parsenodes.h:454
SortByDir ordering
Definition: parsenodes.h:720
Node * subquery
Definition: parsenodes.h:554
NodeTag type
Definition: parsenodes.h:3000
int stmt_location
Definition: parsenodes.h:192
Node * object
Definition: parsenodes.h:2793
char generated_when
Definition: parsenodes.h:2263
NodeTag type
Definition: parsenodes.h:2753
List * sortClause
Definition: parsenodes.h:169
struct CreateExtensionStmt CreateExtensionStmt
List * old_conpfeqop
Definition: parsenodes.h:2291
struct WindowDef WindowDef
struct FuncCall FuncCall
FetchDirection
Definition: parsenodes.h:2841
List * content
Definition: parsenodes.h:1353
bool inRangeNullsFirst
Definition: parsenodes.h:1388
List * names
Definition: parsenodes.h:221
IntoClause * intoClause
Definition: parsenodes.h:1648
A_Expr_Kind kind
Definition: parsenodes.h:285
struct DeclareCursorStmt DeclareCursorStmt
List * options
Definition: parsenodes.h:2883
struct CopyStmt CopyStmt
char storage
Definition: parsenodes.h:665
char * name
Definition: parsenodes.h:2930
DropBehavior behavior
Definition: parsenodes.h:1995
VariableSetKind kind
Definition: parsenodes.h:2141
List * attlist
Definition: parsenodes.h:2112
struct VacuumStmt VacuumStmt
List * fromClause
Definition: parsenodes.h:1650
SubTransactionId oldCreateSubid
Definition: parsenodes.h:2889
char * subname
Definition: parsenodes.h:3047
SortByDir sortby_dir
Definition: parsenodes.h:482
RangeVar * relation
Definition: parsenodes.h:3360
NodeTag type
Definition: parsenodes.h:3375
Alias * alias
Definition: parsenodes.h:1140
List * partParams
Definition: parsenodes.h:809
NodeTag type
Definition: parsenodes.h:3231
FuncExpr * funcexpr
Definition: parsenodes.h:3026
NodeTag type
Definition: parsenodes.h:480
bool is_local
Definition: parsenodes.h:662
ObjectType renameType
Definition: parsenodes.h:3043
struct AlterDomainStmt AlterDomainStmt
struct CreateCastStmt CreateCastStmt
RangeVar * relation
Definition: parsenodes.h:1596
FromExpr * jointree
Definition: parsenodes.h:148
TransactionStmtKind
Definition: parsenodes.h:3168
char * name
Definition: parsenodes.h:452
struct LoadStmt LoadStmt
int frameOptions
Definition: parsenodes.h:503
OnConflictExpr * onConflict
Definition: parsenodes.h:154
NodeTag type
Definition: parsenodes.h:360
TypeName * storedtype
Definition: parsenodes.h:2719
struct A_Indices A_Indices
struct AlterExtensionContentsStmt AlterExtensionContentsStmt
struct AlterObjectSchemaStmt AlterObjectSchemaStmt
RoleStmtType
Definition: parsenodes.h:2599
char identity
Definition: parsenodes.h:668
PartitionRangeDatumKind
Definition: parsenodes.h:850
char * search_seq_column
Definition: parsenodes.h:1477
struct ColumnDef ColumnDef
struct VariableShowStmt VariableShowStmt
FuncCall * funccall
Definition: parsenodes.h:3025
char * tableSpace
Definition: parsenodes.h:2879
NodeTag type
Definition: parsenodes.h:873
struct PartitionSpec PartitionSpec
Node * limitOffset
Definition: parsenodes.h:1672
List * constraintDeps
Definition: parsenodes.h:180
struct WithCheckOption WithCheckOption
struct CompositeTypeStmt CompositeTypeStmt
char fk_matchtype
Definition: parsenodes.h:2288
List * constraints
Definition: parsenodes.h:674
Node * whenClause
Definition: parsenodes.h:2541
List * securityQuals
Definition: parsenodes.h:1151
List * withCheckOptions
Definition: parsenodes.h:183
RoleStmtType stmt_type
Definition: parsenodes.h:2609
Node * agg_filter
Definition: parsenodes.h:364
struct DropUserMappingStmt DropUserMappingStmt
Node * raw_expr
Definition: parsenodes.h:2261
struct CreateRoleStmt CreateRoleStmt
struct A_Indirection A_Indirection
struct RoleSpec RoleSpec
List * objects
Definition: parsenodes.h:2754
bool missing_ok
Definition: parsenodes.h:2757
struct DeallocateStmt DeallocateStmt
struct InferClause InferClause
struct GrantRoleStmt GrantRoleStmt
bool if_not_exists
Definition: parsenodes.h:2649
struct TypeName TypeName
List * coltypmods
Definition: parsenodes.h:1128
struct AlterRoleSetStmt AlterRoleSetStmt
List * useOp
Definition: parsenodes.h:484
bool hasAggs
Definition: parsenodes.h:133
char * name
Definition: parsenodes.h:499
struct CommonTableExpr CommonTableExpr
struct WindowClause WindowClause
struct AlterForeignServerStmt AlterForeignServerStmt
struct PartitionElem PartitionElem
bool groupDistinct
Definition: parsenodes.h:159
ObjectType objectType
Definition: parsenodes.h:3089
List * columns
Definition: parsenodes.h:594
NodeTag type
Definition: parsenodes.h:256
int resultRelation
Definition: parsenodes.h:130
struct AccessPriv AccessPriv
bool is_vacuumcmd
Definition: parsenodes.h:3347
List * indexElems
Definition: parsenodes.h:1438
RangeVar * typevar
Definition: parsenodes.h:3199
char * defnamespace
Definition: parsenodes.h:745
struct CreateStmt CreateStmt
Index tleSortGroupRef
Definition: parsenodes.h:1283
QuerySource
Definition: parsenodes.h:40
PartitionRangeDatumKind kind
Definition: parsenodes.h:861
Node * whereClause
Definition: parsenodes.h:2884
Oid endInRangeFunc
Definition: parsenodes.h:1385
AlterTSConfigType
Definition: parsenodes.h:3601
char * provider
Definition: parsenodes.h:2794
bool grant_option
Definition: parsenodes.h:2022
List * indirection
Definition: parsenodes.h:1748
CoercionForm funcformat
Definition: parsenodes.h:370
List * groupingSets
Definition: parsenodes.h:161
DefElemAction defaction
Definition: parsenodes.h:748
NodeTag type
Definition: parsenodes.h:246
Definition: nodes.h:539
struct AlterCollationStmt AlterCollationStmt
struct RangeTableSample RangeTableSample
NodeTag type
Definition: parsenodes.h:3150
struct RenameStmt RenameStmt
NodeTag type
Definition: parsenodes.h:3344
bool initdeferred
Definition: parsenodes.h:2256
char * filename
Definition: parsenodes.h:3269
AlterTableType subtype
Definition: parsenodes.h:1950
List * actions
Definition: parsenodes.h:3129
List * granted_roles
Definition: parsenodes.h:2079
char * comment
Definition: parsenodes.h:2782
SelectStmt * val
Definition: parsenodes.h:1750
List * targetList
Definition: parsenodes.h:1611
List * options
Definition: parsenodes.h:3377
RoleSpec * role
Definition: parsenodes.h:2625
List * typeName
Definition: parsenodes.h:3113
uint32 SubTransactionId
Definition: c.h:591
AclMode requiredPerms
Definition: parsenodes.h:1145
char generated
Definition: parsenodes.h:671
List * roles
Definition: parsenodes.h:2633
List * pk_attrs
Definition: parsenodes.h:2287
List * cols
Definition: parsenodes.h:2064
TypeName * typeName
Definition: parsenodes.h:777
char * conname
Definition: parsenodes.h:2254
struct AlterOpFamilyStmt AlterOpFamilyStmt
bool is_not_null
Definition: parsenodes.h:663
NodeTag type
Definition: parsenodes.h:1351
struct DropStmt DropStmt
Node * object
Definition: parsenodes.h:2781
NodeTag type
Definition: parsenodes.h:1376
bool funcordinality
Definition: parsenodes.h:1090
NodeTag type
Definition: parsenodes.h:3268
int location
Definition: parsenodes.h:371
char * newname
Definition: parsenodes.h:3049
struct SetOperationStmt SetOperationStmt
unsigned int Oid
Definition: postgres_ext.h:31
NodeTag
Definition: nodes.h:26
List * rowMarks
Definition: parsenodes.h:175
Node * utilityStmt
Definition: parsenodes.h:128
bool is_program
Definition: parsenodes.h:2115
struct CreateDomainStmt CreateDomainStmt
NodeTag type
Definition: parsenodes.h:1745
struct TransactionStmt TransactionStmt
struct PrepareStmt PrepareStmt
ReindexObjectType
Definition: parsenodes.h:3470
ObjectType objtype
Definition: parsenodes.h:3398
struct ReturnStmt ReturnStmt
struct LockingClause LockingClause
List * colcollations
Definition: parsenodes.h:1129
CoercionContext
Definition: primnodes.h:461
WithClause * withClause
Definition: parsenodes.h:1585
struct RangeFunction RangeFunction
RangeVar * relation
Definition: parsenodes.h:3412
List * agg_order
Definition: parsenodes.h:363
List * values_lists
Definition: parsenodes.h:1100
ObjectType removeType
Definition: parsenodes.h:2755
bool instead
Definition: parsenodes.h:3128
OnCommitAction
Definition: primnodes.h:47
LockClauseStrength strength
Definition: parsenodes.h:1409
bool hasDistinctOn
Definition: parsenodes.h:137
RangeVar * table
Definition: parsenodes.h:2504
Node * whereClause
Definition: parsenodes.h:1612
List * options
Definition: parsenodes.h:2656
struct VacuumRelation VacuumRelation
RangeVar * view
Definition: parsenodes.h:3254
signed int int32
Definition: c.h:429
OnConflictClause * onConflictClause
Definition: parsenodes.h:1583
List * opclassopts
Definition: parsenodes.h:719
struct TruncateStmt TruncateStmt
struct CreatePLangStmt CreatePLangStmt
List * options
Definition: parsenodes.h:2275
List * windowClause
Definition: parsenodes.h:165
DropBehavior behavior
Definition: parsenodes.h:3686
JoinType
Definition: nodes.h:706
struct StatsElem StatsElem
List * targetList
Definition: parsenodes.h:150
RoleSpec * newowner
Definition: parsenodes.h:1955