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