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