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