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