]> granicus.if.org Git - postgresql/blob - src/include/nodes/parsenodes.h
Restructure SELECT INTO's parsetree representation into CreateTableAsStmt.
[postgresql] / src / include / nodes / parsenodes.h
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.
11  *
12  *
13  * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
14  * Portions Copyright (c) 1994, Regents of the University of California
15  *
16  * src/include/nodes/parsenodes.h
17  *
18  *-------------------------------------------------------------------------
19  */
20 #ifndef PARSENODES_H
21 #define PARSENODES_H
22
23 #include "nodes/bitmapset.h"
24 #include "nodes/primnodes.h"
25 #include "nodes/value.h"
26
27 /* Possible sources of a Query */
28 typedef enum QuerySource
29 {
30         QSRC_ORIGINAL,                          /* original parsetree (explicit query) */
31         QSRC_PARSER,                            /* added by parse analysis (now unused) */
32         QSRC_INSTEAD_RULE,                      /* added by unconditional INSTEAD rule */
33         QSRC_QUAL_INSTEAD_RULE,         /* added by conditional INSTEAD rule */
34         QSRC_NON_INSTEAD_RULE           /* added by non-INSTEAD rule */
35 } QuerySource;
36
37 /* Sort ordering options for ORDER BY and CREATE INDEX */
38 typedef enum SortByDir
39 {
40         SORTBY_DEFAULT,
41         SORTBY_ASC,
42         SORTBY_DESC,
43         SORTBY_USING                            /* not allowed in CREATE INDEX ... */
44 } SortByDir;
45
46 typedef enum SortByNulls
47 {
48         SORTBY_NULLS_DEFAULT,
49         SORTBY_NULLS_FIRST,
50         SORTBY_NULLS_LAST
51 } SortByNulls;
52
53 /*
54  * Grantable rights are encoded so that we can OR them together in a bitmask.
55  * The present representation of AclItem limits us to 16 distinct rights,
56  * even though AclMode is defined as uint32.  See utils/acl.h.
57  *
58  * Caution: changing these codes breaks stored ACLs, hence forces initdb.
59  */
60 typedef uint32 AclMode;                 /* a bitmask of privilege bits */
61
62 #define ACL_INSERT              (1<<0)  /* for relations */
63 #define ACL_SELECT              (1<<1)
64 #define ACL_UPDATE              (1<<2)
65 #define ACL_DELETE              (1<<3)
66 #define ACL_TRUNCATE    (1<<4)
67 #define ACL_REFERENCES  (1<<5)
68 #define ACL_TRIGGER             (1<<6)
69 #define ACL_EXECUTE             (1<<7)  /* for functions */
70 #define ACL_USAGE               (1<<8)  /* for languages, namespaces, FDWs, and
71                                                                  * servers */
72 #define ACL_CREATE              (1<<9)  /* for namespaces and databases */
73 #define ACL_CREATE_TEMP (1<<10) /* for databases */
74 #define ACL_CONNECT             (1<<11) /* for databases */
75 #define N_ACL_RIGHTS    12              /* 1 plus the last 1<<x */
76 #define ACL_NO_RIGHTS   0
77 /* Currently, SELECT ... FOR UPDATE/FOR SHARE requires UPDATE privileges */
78 #define ACL_SELECT_FOR_UPDATE   ACL_UPDATE
79
80
81 /*****************************************************************************
82  *      Query Tree
83  *****************************************************************************/
84
85 /*
86  * Query -
87  *        Parse analysis turns all statements into a Query tree
88  *        for further processing by the rewriter and planner.
89  *
90  *        Utility statements (i.e. non-optimizable statements) have the
91  *        utilityStmt field set, and the Query itself is mostly dummy.
92  *        DECLARE CURSOR is a special case: it is represented like a SELECT,
93  *        but the original DeclareCursorStmt is stored in utilityStmt.
94  *
95  *        Planning converts a Query tree into a Plan tree headed by a PlannedStmt
96  *        node --- the Query structure is not used by the executor.
97  */
98 typedef struct Query
99 {
100         NodeTag         type;
101
102         CmdType         commandType;    /* select|insert|update|delete|utility */
103
104         QuerySource querySource;        /* where did I come from? */
105
106         bool            canSetTag;              /* do I set the command result tag? */
107
108         Node       *utilityStmt;        /* non-null if this is DECLARE CURSOR or a
109                                                                  * non-optimizable statement */
110
111         int                     resultRelation; /* rtable index of target relation for
112                                                                  * INSERT/UPDATE/DELETE; 0 for SELECT */
113
114         bool            hasAggs;                /* has aggregates in tlist or havingQual */
115         bool            hasWindowFuncs; /* has window functions in tlist */
116         bool            hasSubLinks;    /* has subquery SubLink */
117         bool            hasDistinctOn;  /* distinctClause is from DISTINCT ON */
118         bool            hasRecursive;   /* WITH RECURSIVE was specified */
119         bool            hasModifyingCTE;        /* has INSERT/UPDATE/DELETE in WITH */
120         bool            hasForUpdate;   /* FOR UPDATE or FOR SHARE was specified */
121
122         List       *cteList;            /* WITH list (of CommonTableExpr's) */
123
124         List       *rtable;                     /* list of range table entries */
125         FromExpr   *jointree;           /* table join tree (FROM and WHERE clauses) */
126
127         List       *targetList;         /* target list (of TargetEntry) */
128
129         List       *returningList;      /* return-values list (of TargetEntry) */
130
131         List       *groupClause;        /* a list of SortGroupClause's */
132
133         Node       *havingQual;         /* qualifications applied to groups */
134
135         List       *windowClause;       /* a list of WindowClause's */
136
137         List       *distinctClause; /* a list of SortGroupClause's */
138
139         List       *sortClause;         /* a list of SortGroupClause's */
140
141         Node       *limitOffset;        /* # of result tuples to skip (int8 expr) */
142         Node       *limitCount;         /* # of result tuples to return (int8 expr) */
143
144         List       *rowMarks;           /* a list of RowMarkClause's */
145
146         Node       *setOperations;      /* set-operation tree if this is top level of
147                                                                  * a UNION/INTERSECT/EXCEPT query */
148
149         List       *constraintDeps; /* a list of pg_constraint OIDs that the query
150                                                                  * depends on to be semantically valid */
151 } Query;
152
153
154 /****************************************************************************
155  *      Supporting data structures for Parse Trees
156  *
157  *      Most of these node types appear in raw parsetrees output by the grammar,
158  *      and get transformed to something else by the analyzer.  A few of them
159  *      are used as-is in transformed querytrees.
160  ****************************************************************************/
161
162 /*
163  * TypeName - specifies a type in definitions
164  *
165  * For TypeName structures generated internally, it is often easier to
166  * specify the type by OID than by name.  If "names" is NIL then the
167  * actual type OID is given by typeOid, otherwise typeOid is unused.
168  * Similarly, if "typmods" is NIL then the actual typmod is expected to
169  * be prespecified in typemod, otherwise typemod is unused.
170  *
171  * If pct_type is TRUE, then names is actually a field name and we look up
172  * the type of that field.      Otherwise (the normal case), names is a type
173  * name possibly qualified with schema and database name.
174  */
175 typedef struct TypeName
176 {
177         NodeTag         type;
178         List       *names;                      /* qualified name (list of Value strings) */
179         Oid                     typeOid;                /* type identified by OID */
180         bool            setof;                  /* is a set? */
181         bool            pct_type;               /* %TYPE specified? */
182         List       *typmods;            /* type modifier expression(s) */
183         int32           typemod;                /* prespecified type modifier */
184         List       *arrayBounds;        /* array bounds */
185         int                     location;               /* token location, or -1 if unknown */
186 } TypeName;
187
188 /*
189  * ColumnRef - specifies a reference to a column, or possibly a whole tuple
190  *
191  * The "fields" list must be nonempty.  It can contain string Value nodes
192  * (representing names) and A_Star nodes (representing occurrence of a '*').
193  * Currently, A_Star must appear only as the last list element --- the grammar
194  * is responsible for enforcing this!
195  *
196  * Note: any array subscripting or selection of fields from composite columns
197  * is represented by an A_Indirection node above the ColumnRef.  However,
198  * for simplicity in the normal case, initial field selection from a table
199  * name is represented within ColumnRef and not by adding A_Indirection.
200  */
201 typedef struct ColumnRef
202 {
203         NodeTag         type;
204         List       *fields;                     /* field names (Value strings) or A_Star */
205         int                     location;               /* token location, or -1 if unknown */
206 } ColumnRef;
207
208 /*
209  * ParamRef - specifies a $n parameter reference
210  */
211 typedef struct ParamRef
212 {
213         NodeTag         type;
214         int                     number;                 /* the number of the parameter */
215         int                     location;               /* token location, or -1 if unknown */
216 } ParamRef;
217
218 /*
219  * A_Expr - infix, prefix, and postfix expressions
220  */
221 typedef enum A_Expr_Kind
222 {
223         AEXPR_OP,                                       /* normal operator */
224         AEXPR_AND,                                      /* booleans - name field is unused */
225         AEXPR_OR,
226         AEXPR_NOT,
227         AEXPR_OP_ANY,                           /* scalar op ANY (array) */
228         AEXPR_OP_ALL,                           /* scalar op ALL (array) */
229         AEXPR_DISTINCT,                         /* IS DISTINCT FROM - name must be "=" */
230         AEXPR_NULLIF,                           /* NULLIF - name must be "=" */
231         AEXPR_OF,                                       /* IS [NOT] OF - name must be "=" or "<>" */
232         AEXPR_IN                                        /* [NOT] IN - name must be "=" or "<>" */
233 } A_Expr_Kind;
234
235 typedef struct A_Expr
236 {
237         NodeTag         type;
238         A_Expr_Kind kind;                       /* see above */
239         List       *name;                       /* possibly-qualified name of operator */
240         Node       *lexpr;                      /* left argument, or NULL if none */
241         Node       *rexpr;                      /* right argument, or NULL if none */
242         int                     location;               /* token location, or -1 if unknown */
243 } A_Expr;
244
245 /*
246  * A_Const - a literal constant
247  */
248 typedef struct A_Const
249 {
250         NodeTag         type;
251         Value           val;                    /* value (includes type info, see value.h) */
252         int                     location;               /* token location, or -1 if unknown */
253 } A_Const;
254
255 /*
256  * TypeCast - a CAST expression
257  */
258 typedef struct TypeCast
259 {
260         NodeTag         type;
261         Node       *arg;                        /* the expression being casted */
262         TypeName   *typeName;           /* the target type */
263         int                     location;               /* token location, or -1 if unknown */
264 } TypeCast;
265
266 /*
267  * CollateClause - a COLLATE expression
268  */
269 typedef struct CollateClause
270 {
271         NodeTag         type;
272         Node       *arg;                        /* input expression */
273         List       *collname;           /* possibly-qualified collation name */
274         int                     location;               /* token location, or -1 if unknown */
275 } CollateClause;
276
277 /*
278  * FuncCall - a function or aggregate invocation
279  *
280  * agg_order (if not NIL) indicates we saw 'foo(... ORDER BY ...)'.
281  * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
282  * indicates we saw 'foo(DISTINCT ...)'.  In any of these cases, the
283  * construct *must* be an aggregate call.  Otherwise, it might be either an
284  * aggregate or some other kind of function.  However, if OVER is present
285  * it had better be an aggregate or window function.
286  */
287 typedef struct FuncCall
288 {
289         NodeTag         type;
290         List       *funcname;           /* qualified name of function */
291         List       *args;                       /* the arguments (list of exprs) */
292         List       *agg_order;          /* ORDER BY (list of SortBy) */
293         bool            agg_star;               /* argument was really '*' */
294         bool            agg_distinct;   /* arguments were labeled DISTINCT */
295         bool            func_variadic;  /* last argument was labeled VARIADIC */
296         struct WindowDef *over;         /* OVER clause, if any */
297         int                     location;               /* token location, or -1 if unknown */
298 } FuncCall;
299
300 /*
301  * A_Star - '*' representing all columns of a table or compound field
302  *
303  * This can appear within ColumnRef.fields, A_Indirection.indirection, and
304  * ResTarget.indirection lists.
305  */
306 typedef struct A_Star
307 {
308         NodeTag         type;
309 } A_Star;
310
311 /*
312  * A_Indices - array subscript or slice bounds ([lidx:uidx] or [uidx])
313  */
314 typedef struct A_Indices
315 {
316         NodeTag         type;
317         Node       *lidx;                       /* NULL if it's a single subscript */
318         Node       *uidx;
319 } A_Indices;
320
321 /*
322  * A_Indirection - select a field and/or array element from an expression
323  *
324  * The indirection list can contain A_Indices nodes (representing
325  * subscripting), string Value nodes (representing field selection --- the
326  * string value is the name of the field to select), and A_Star nodes
327  * (representing selection of all fields of a composite type).
328  * For example, a complex selection operation like
329  *                              (foo).field1[42][7].field2
330  * would be represented with a single A_Indirection node having a 4-element
331  * indirection list.
332  *
333  * Currently, A_Star must appear only as the last list element --- the grammar
334  * is responsible for enforcing this!
335  */
336 typedef struct A_Indirection
337 {
338         NodeTag         type;
339         Node       *arg;                        /* the thing being selected from */
340         List       *indirection;        /* subscripts and/or field names and/or * */
341 } A_Indirection;
342
343 /*
344  * A_ArrayExpr - an ARRAY[] construct
345  */
346 typedef struct A_ArrayExpr
347 {
348         NodeTag         type;
349         List       *elements;           /* array element expressions */
350         int                     location;               /* token location, or -1 if unknown */
351 } A_ArrayExpr;
352
353 /*
354  * ResTarget -
355  *        result target (used in target list of pre-transformed parse trees)
356  *
357  * In a SELECT target list, 'name' is the column label from an
358  * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
359  * value expression itself.  The 'indirection' field is not used.
360  *
361  * INSERT uses ResTarget in its target-column-names list.  Here, 'name' is
362  * the name of the destination column, 'indirection' stores any subscripts
363  * attached to the destination, and 'val' is not used.
364  *
365  * In an UPDATE target list, 'name' is the name of the destination column,
366  * 'indirection' stores any subscripts attached to the destination, and
367  * 'val' is the expression to assign.
368  *
369  * See A_Indirection for more info about what can appear in 'indirection'.
370  */
371 typedef struct ResTarget
372 {
373         NodeTag         type;
374         char       *name;                       /* column name or NULL */
375         List       *indirection;        /* subscripts, field names, and '*', or NIL */
376         Node       *val;                        /* the value expression to compute or assign */
377         int                     location;               /* token location, or -1 if unknown */
378 } ResTarget;
379
380 /*
381  * SortBy - for ORDER BY clause
382  */
383 typedef struct SortBy
384 {
385         NodeTag         type;
386         Node       *node;                       /* expression to sort on */
387         SortByDir       sortby_dir;             /* ASC/DESC/USING/default */
388         SortByNulls sortby_nulls;       /* NULLS FIRST/LAST */
389         List       *useOp;                      /* name of op to use, if SORTBY_USING */
390         int                     location;               /* operator location, or -1 if none/unknown */
391 } SortBy;
392
393 /*
394  * WindowDef - raw representation of WINDOW and OVER clauses
395  *
396  * For entries in a WINDOW list, "name" is the window name being defined.
397  * For OVER clauses, we use "name" for the "OVER window" syntax, or "refname"
398  * for the "OVER (window)" syntax, which is subtly different --- the latter
399  * implies overriding the window frame clause.
400  */
401 typedef struct WindowDef
402 {
403         NodeTag         type;
404         char       *name;                       /* window's own name */
405         char       *refname;            /* referenced window name, if any */
406         List       *partitionClause;    /* PARTITION BY expression list */
407         List       *orderClause;        /* ORDER BY (list of SortBy) */
408         int                     frameOptions;   /* frame_clause options, see below */
409         Node       *startOffset;        /* expression for starting bound, if any */
410         Node       *endOffset;          /* expression for ending bound, if any */
411         int                     location;               /* parse location, or -1 if none/unknown */
412 } WindowDef;
413
414 /*
415  * frameOptions is an OR of these bits.  The NONDEFAULT and BETWEEN bits are
416  * used so that ruleutils.c can tell which properties were specified and
417  * which were defaulted; the correct behavioral bits must be set either way.
418  * The START_foo and END_foo options must come in pairs of adjacent bits for
419  * the convenience of gram.y, even though some of them are useless/invalid.
420  * We will need more bits (and fields) to cover the full SQL:2008 option set.
421  */
422 #define FRAMEOPTION_NONDEFAULT                                  0x00001 /* any specified? */
423 #define FRAMEOPTION_RANGE                                               0x00002 /* RANGE behavior */
424 #define FRAMEOPTION_ROWS                                                0x00004 /* ROWS behavior */
425 #define FRAMEOPTION_BETWEEN                                             0x00008 /* BETWEEN given? */
426 #define FRAMEOPTION_START_UNBOUNDED_PRECEDING   0x00010 /* start is U. P. */
427 #define FRAMEOPTION_END_UNBOUNDED_PRECEDING             0x00020 /* (disallowed) */
428 #define FRAMEOPTION_START_UNBOUNDED_FOLLOWING   0x00040 /* (disallowed) */
429 #define FRAMEOPTION_END_UNBOUNDED_FOLLOWING             0x00080 /* end is U. F. */
430 #define FRAMEOPTION_START_CURRENT_ROW                   0x00100 /* start is C. R. */
431 #define FRAMEOPTION_END_CURRENT_ROW                             0x00200 /* end is C. R. */
432 #define FRAMEOPTION_START_VALUE_PRECEDING               0x00400 /* start is V. P. */
433 #define FRAMEOPTION_END_VALUE_PRECEDING                 0x00800 /* end is V. P. */
434 #define FRAMEOPTION_START_VALUE_FOLLOWING               0x01000 /* start is V. F. */
435 #define FRAMEOPTION_END_VALUE_FOLLOWING                 0x02000 /* end is V. F. */
436
437 #define FRAMEOPTION_START_VALUE \
438         (FRAMEOPTION_START_VALUE_PRECEDING | FRAMEOPTION_START_VALUE_FOLLOWING)
439 #define FRAMEOPTION_END_VALUE \
440         (FRAMEOPTION_END_VALUE_PRECEDING | FRAMEOPTION_END_VALUE_FOLLOWING)
441
442 #define FRAMEOPTION_DEFAULTS \
443         (FRAMEOPTION_RANGE | FRAMEOPTION_START_UNBOUNDED_PRECEDING | \
444          FRAMEOPTION_END_CURRENT_ROW)
445
446 /*
447  * RangeSubselect - subquery appearing in a FROM clause
448  */
449 typedef struct RangeSubselect
450 {
451         NodeTag         type;
452         Node       *subquery;           /* the untransformed sub-select clause */
453         Alias      *alias;                      /* table alias & optional column aliases */
454 } RangeSubselect;
455
456 /*
457  * RangeFunction - function call appearing in a FROM clause
458  */
459 typedef struct RangeFunction
460 {
461         NodeTag         type;
462         Node       *funccallnode;       /* untransformed function call tree */
463         Alias      *alias;                      /* table alias & optional column aliases */
464         List       *coldeflist;         /* list of ColumnDef nodes to describe result
465                                                                  * of function returning RECORD */
466 } RangeFunction;
467
468 /*
469  * ColumnDef - column definition (used in various creates)
470  *
471  * If the column has a default value, we may have the value expression
472  * in either "raw" form (an untransformed parse tree) or "cooked" form
473  * (a post-parse-analysis, executable expression tree), depending on
474  * how this ColumnDef node was created (by parsing, or by inheritance
475  * from an existing relation).  We should never have both in the same node!
476  *
477  * Similarly, we may have a COLLATE specification in either raw form
478  * (represented as a CollateClause with arg==NULL) or cooked form
479  * (the collation's OID).
480  *
481  * The constraints list may contain a CONSTR_DEFAULT item in a raw
482  * parsetree produced by gram.y, but transformCreateStmt will remove
483  * the item and set raw_default instead.  CONSTR_DEFAULT items
484  * should not appear in any subsequent processing.
485  */
486 typedef struct ColumnDef
487 {
488         NodeTag         type;
489         char       *colname;            /* name of column */
490         TypeName   *typeName;           /* type of column */
491         int                     inhcount;               /* number of times column is inherited */
492         bool            is_local;               /* column has local (non-inherited) def'n */
493         bool            is_not_null;    /* NOT NULL constraint specified? */
494         bool            is_from_type;   /* column definition came from table type */
495         char            storage;                /* attstorage setting, or 0 for default */
496         Node       *raw_default;        /* default value (untransformed parse tree) */
497         Node       *cooked_default; /* default value (transformed expr tree) */
498         CollateClause *collClause;      /* untransformed COLLATE spec, if any */
499         Oid                     collOid;                /* collation OID (InvalidOid if not set) */
500         List       *constraints;        /* other constraints on column */
501         List       *fdwoptions;         /* per-column FDW options */
502 } ColumnDef;
503
504 /*
505  * TableLikeClause - CREATE TABLE ( ... LIKE ... ) clause
506  */
507 typedef struct TableLikeClause
508 {
509         NodeTag         type;
510         RangeVar   *relation;
511         bits32          options;                /* OR of TableLikeOption flags */
512 } TableLikeClause;
513
514 typedef enum TableLikeOption
515 {
516         CREATE_TABLE_LIKE_DEFAULTS = 1 << 0,
517         CREATE_TABLE_LIKE_CONSTRAINTS = 1 << 1,
518         CREATE_TABLE_LIKE_INDEXES = 1 << 2,
519         CREATE_TABLE_LIKE_STORAGE = 1 << 3,
520         CREATE_TABLE_LIKE_COMMENTS = 1 << 4,
521         CREATE_TABLE_LIKE_ALL = 0x7FFFFFFF
522 } TableLikeOption;
523
524 /*
525  * IndexElem - index parameters (used in CREATE INDEX)
526  *
527  * For a plain index attribute, 'name' is the name of the table column to
528  * index, and 'expr' is NULL.  For an index expression, 'name' is NULL and
529  * 'expr' is the expression tree.
530  */
531 typedef struct IndexElem
532 {
533         NodeTag         type;
534         char       *name;                       /* name of attribute to index, or NULL */
535         Node       *expr;                       /* expression to index, or NULL */
536         char       *indexcolname;       /* name for index column; NULL = default */
537         List       *collation;          /* name of collation; NIL = default */
538         List       *opclass;            /* name of desired opclass; NIL = default */
539         SortByDir       ordering;               /* ASC/DESC/default */
540         SortByNulls nulls_ordering; /* FIRST/LAST/default */
541 } IndexElem;
542
543 /*
544  * DefElem - a generic "name = value" option definition
545  *
546  * In some contexts the name can be qualified.  Also, certain SQL commands
547  * allow a SET/ADD/DROP action to be attached to option settings, so it's
548  * convenient to carry a field for that too.  (Note: currently, it is our
549  * practice that the grammar allows namespace and action only in statements
550  * where they are relevant; C code can just ignore those fields in other
551  * statements.)
552  */
553 typedef enum DefElemAction
554 {
555         DEFELEM_UNSPEC,                         /* no action given */
556         DEFELEM_SET,
557         DEFELEM_ADD,
558         DEFELEM_DROP
559 } DefElemAction;
560
561 typedef struct DefElem
562 {
563         NodeTag         type;
564         char       *defnamespace;       /* NULL if unqualified name */
565         char       *defname;
566         Node       *arg;                        /* a (Value *) or a (TypeName *) */
567         DefElemAction defaction;        /* unspecified action, or SET/ADD/DROP */
568 } DefElem;
569
570 /*
571  * LockingClause - raw representation of FOR UPDATE/SHARE options
572  *
573  * Note: lockedRels == NIL means "all relations in query".      Otherwise it
574  * is a list of RangeVar nodes.  (We use RangeVar mainly because it carries
575  * a location field --- currently, parse analysis insists on unqualified
576  * names in LockingClause.)
577  */
578 typedef struct LockingClause
579 {
580         NodeTag         type;
581         List       *lockedRels;         /* FOR UPDATE or FOR SHARE relations */
582         bool            forUpdate;              /* true = FOR UPDATE, false = FOR SHARE */
583         bool            noWait;                 /* NOWAIT option */
584 } LockingClause;
585
586 /*
587  * XMLSERIALIZE (in raw parse tree only)
588  */
589 typedef struct XmlSerialize
590 {
591         NodeTag         type;
592         XmlOptionType xmloption;        /* DOCUMENT or CONTENT */
593         Node       *expr;
594         TypeName   *typeName;
595         int                     location;               /* token location, or -1 if unknown */
596 } XmlSerialize;
597
598
599 /****************************************************************************
600  *      Nodes for a Query tree
601  ****************************************************************************/
602
603 /*--------------------
604  * RangeTblEntry -
605  *        A range table is a List of RangeTblEntry nodes.
606  *
607  *        A range table entry may represent a plain relation, a sub-select in
608  *        FROM, or the result of a JOIN clause.  (Only explicit JOIN syntax
609  *        produces an RTE, not the implicit join resulting from multiple FROM
610  *        items.  This is because we only need the RTE to deal with SQL features
611  *        like outer joins and join-output-column aliasing.)  Other special
612  *        RTE types also exist, as indicated by RTEKind.
613  *
614  *        Note that we consider RTE_RELATION to cover anything that has a pg_class
615  *        entry.  relkind distinguishes the sub-cases.
616  *
617  *        alias is an Alias node representing the AS alias-clause attached to the
618  *        FROM expression, or NULL if no clause.
619  *
620  *        eref is the table reference name and column reference names (either
621  *        real or aliases).  Note that system columns (OID etc) are not included
622  *        in the column list.
623  *        eref->aliasname is required to be present, and should generally be used
624  *        to identify the RTE for error messages etc.
625  *
626  *        In RELATION RTEs, the colnames in both alias and eref are indexed by
627  *        physical attribute number; this means there must be colname entries for
628  *        dropped columns.      When building an RTE we insert empty strings ("") for
629  *        dropped columns.      Note however that a stored rule may have nonempty
630  *        colnames for columns dropped since the rule was created (and for that
631  *        matter the colnames might be out of date due to column renamings).
632  *        The same comments apply to FUNCTION RTEs when the function's return type
633  *        is a named composite type.
634  *
635  *        In JOIN RTEs, the colnames in both alias and eref are one-to-one with
636  *        joinaliasvars entries.  A JOIN RTE will omit columns of its inputs when
637  *        those columns are known to be dropped at parse time.  Again, however,
638  *        a stored rule might contain entries for columns dropped since the rule
639  *        was created.  (This is only possible for columns not actually referenced
640  *        in the rule.)  When loading a stored rule, we replace the joinaliasvars
641  *        items for any such columns with NULL Consts.  (We can't simply delete
642  *        them from the joinaliasvars list, because that would affect the attnums
643  *        of Vars referencing the rest of the list.)
644  *
645  *        inh is TRUE for relation references that should be expanded to include
646  *        inheritance children, if the rel has any.  This *must* be FALSE for
647  *        RTEs other than RTE_RELATION entries.
648  *
649  *        inFromCl marks those range variables that are listed in the FROM clause.
650  *        It's false for RTEs that are added to a query behind the scenes, such
651  *        as the NEW and OLD variables for a rule, or the subqueries of a UNION.
652  *        This flag is not used anymore during parsing, since the parser now uses
653  *        a separate "namespace" data structure to control visibility, but it is
654  *        needed by ruleutils.c to determine whether RTEs should be shown in
655  *        decompiled queries.
656  *
657  *        requiredPerms and checkAsUser specify run-time access permissions
658  *        checks to be performed at query startup.      The user must have *all*
659  *        of the permissions that are OR'd together in requiredPerms (zero
660  *        indicates no permissions checking).  If checkAsUser is not zero,
661  *        then do the permissions checks using the access rights of that user,
662  *        not the current effective user ID.  (This allows rules to act as
663  *        setuid gateways.)  Permissions checks only apply to RELATION RTEs.
664  *
665  *        For SELECT/INSERT/UPDATE permissions, if the user doesn't have
666  *        table-wide permissions then it is sufficient to have the permissions
667  *        on all columns identified in selectedCols (for SELECT) and/or
668  *        modifiedCols (for INSERT/UPDATE; we can tell which from the query type).
669  *        selectedCols and modifiedCols are bitmapsets, which cannot have negative
670  *        integer members, so we subtract FirstLowInvalidHeapAttributeNumber from
671  *        column numbers before storing them in these fields.  A whole-row Var
672  *        reference is represented by setting the bit for InvalidAttrNumber.
673  *--------------------
674  */
675 typedef enum RTEKind
676 {
677         RTE_RELATION,                           /* ordinary relation reference */
678         RTE_SUBQUERY,                           /* subquery in FROM */
679         RTE_JOIN,                                       /* join */
680         RTE_FUNCTION,                           /* function in FROM */
681         RTE_VALUES,                                     /* VALUES (<exprlist>), (<exprlist>), ... */
682         RTE_CTE                                         /* common table expr (WITH list element) */
683 } RTEKind;
684
685 typedef struct RangeTblEntry
686 {
687         NodeTag         type;
688
689         RTEKind         rtekind;                /* see above */
690
691         /*
692          * XXX the fields applicable to only some rte kinds should be merged into
693          * a union.  I didn't do this yet because the diffs would impact a lot of
694          * code that is being actively worked on.  FIXME someday.
695          */
696
697         /*
698          * Fields valid for a plain relation RTE (else zero):
699          */
700         Oid                     relid;                  /* OID of the relation */
701         char            relkind;                /* relation kind (see pg_class.relkind) */
702
703         /*
704          * Fields valid for a subquery RTE (else NULL):
705          */
706         Query      *subquery;           /* the sub-query */
707         bool            security_barrier;       /* subquery from security_barrier view */
708
709         /*
710          * Fields valid for a join RTE (else NULL/zero):
711          *
712          * joinaliasvars is a list of Vars or COALESCE expressions corresponding
713          * to the columns of the join result.  An alias Var referencing column K
714          * of the join result can be replaced by the K'th element of joinaliasvars
715          * --- but to simplify the task of reverse-listing aliases correctly, we
716          * do not do that until planning time.  In a Query loaded from a stored
717          * rule, it is also possible for joinaliasvars items to be NULL Consts,
718          * denoting columns dropped since the rule was made.
719          */
720         JoinType        jointype;               /* type of join */
721         List       *joinaliasvars;      /* list of alias-var expansions */
722
723         /*
724          * Fields valid for a function RTE (else NULL):
725          *
726          * If the function returns RECORD, funccoltypes lists the column types
727          * declared in the RTE's column type specification, funccoltypmods lists
728          * their declared typmods, funccolcollations their collations.  Otherwise,
729          * those fields are NIL.
730          */
731         Node       *funcexpr;           /* expression tree for func call */
732         List       *funccoltypes;       /* OID list of column type OIDs */
733         List       *funccoltypmods; /* integer list of column typmods */
734         List       *funccolcollations;          /* OID list of column collation OIDs */
735
736         /*
737          * Fields valid for a values RTE (else NIL):
738          */
739         List       *values_lists;       /* list of expression lists */
740         List       *values_collations;          /* OID list of column collation OIDs */
741
742         /*
743          * Fields valid for a CTE RTE (else NULL/zero):
744          */
745         char       *ctename;            /* name of the WITH list item */
746         Index           ctelevelsup;    /* number of query levels up */
747         bool            self_reference; /* is this a recursive self-reference? */
748         List       *ctecoltypes;        /* OID list of column type OIDs */
749         List       *ctecoltypmods;      /* integer list of column typmods */
750         List       *ctecolcollations;           /* OID list of column collation OIDs */
751
752         /*
753          * Fields valid in all RTEs:
754          */
755         Alias      *alias;                      /* user-written alias clause, if any */
756         Alias      *eref;                       /* expanded reference names */
757         bool            inh;                    /* inheritance requested? */
758         bool            inFromCl;               /* present in FROM clause? */
759         AclMode         requiredPerms;  /* bitmask of required access permissions */
760         Oid                     checkAsUser;    /* if valid, check access as this role */
761         Bitmapset  *selectedCols;       /* columns needing SELECT permission */
762         Bitmapset  *modifiedCols;       /* columns needing INSERT/UPDATE permission */
763 } RangeTblEntry;
764
765 /*
766  * SortGroupClause -
767  *              representation of ORDER BY, GROUP BY, PARTITION BY,
768  *              DISTINCT, DISTINCT ON items
769  *
770  * You might think that ORDER BY is only interested in defining ordering,
771  * and GROUP/DISTINCT are only interested in defining equality.  However,
772  * one way to implement grouping is to sort and then apply a "uniq"-like
773  * filter.      So it's also interesting to keep track of possible sort operators
774  * for GROUP/DISTINCT, and in particular to try to sort for the grouping
775  * in a way that will also yield a requested ORDER BY ordering.  So we need
776  * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates
777  * the decision to give them the same representation.
778  *
779  * tleSortGroupRef must match ressortgroupref of exactly one entry of the
780  *              query's targetlist; that is the expression to be sorted or grouped by.
781  * eqop is the OID of the equality operator.
782  * sortop is the OID of the ordering operator (a "<" or ">" operator),
783  *              or InvalidOid if not available.
784  * nulls_first means about what you'd expect.  If sortop is InvalidOid
785  *              then nulls_first is meaningless and should be set to false.
786  * hashable is TRUE if eqop is hashable (note this condition also depends
787  *              on the datatype of the input expression).
788  *
789  * In an ORDER BY item, all fields must be valid.  (The eqop isn't essential
790  * here, but it's cheap to get it along with the sortop, and requiring it
791  * to be valid eases comparisons to grouping items.)  Note that this isn't
792  * actually enough information to determine an ordering: if the sortop is
793  * collation-sensitive, a collation OID is needed too.  We don't store the
794  * collation in SortGroupClause because it's not available at the time the
795  * parser builds the SortGroupClause; instead, consult the exposed collation
796  * of the referenced targetlist expression to find out what it is.
797  *
798  * In a grouping item, eqop must be valid.      If the eqop is a btree equality
799  * operator, then sortop should be set to a compatible ordering operator.
800  * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that
801  * the query presents for the same tlist item.  If there is none, we just
802  * use the default ordering op for the datatype.
803  *
804  * If the tlist item's type has a hash opclass but no btree opclass, then
805  * we will set eqop to the hash equality operator, sortop to InvalidOid,
806  * and nulls_first to false.  A grouping item of this kind can only be
807  * implemented by hashing, and of course it'll never match an ORDER BY item.
808  *
809  * The hashable flag is provided since we generally have the requisite
810  * information readily available when the SortGroupClause is constructed,
811  * and it's relatively expensive to get it again later.  Note there is no
812  * need for a "sortable" flag since OidIsValid(sortop) serves the purpose.
813  *
814  * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses.
815  * In SELECT DISTINCT, the distinctClause list is as long or longer than the
816  * sortClause list, while in SELECT DISTINCT ON it's typically shorter.
817  * The two lists must match up to the end of the shorter one --- the parser
818  * rearranges the distinctClause if necessary to make this true.  (This
819  * restriction ensures that only one sort step is needed to both satisfy the
820  * ORDER BY and set up for the Unique step.  This is semantically necessary
821  * for DISTINCT ON, and presents no real drawback for DISTINCT.)
822  */
823 typedef struct SortGroupClause
824 {
825         NodeTag         type;
826         Index           tleSortGroupRef;        /* reference into targetlist */
827         Oid                     eqop;                   /* the equality operator ('=' op) */
828         Oid                     sortop;                 /* the ordering operator ('<' op), or 0 */
829         bool            nulls_first;    /* do NULLs come before normal values? */
830         bool            hashable;               /* can eqop be implemented by hashing? */
831 } SortGroupClause;
832
833 /*
834  * WindowClause -
835  *              transformed representation of WINDOW and OVER clauses
836  *
837  * A parsed Query's windowClause list contains these structs.  "name" is set
838  * if the clause originally came from WINDOW, and is NULL if it originally
839  * was an OVER clause (but note that we collapse out duplicate OVERs).
840  * partitionClause and orderClause are lists of SortGroupClause structs.
841  * winref is an ID number referenced by WindowFunc nodes; it must be unique
842  * among the members of a Query's windowClause list.
843  * When refname isn't null, the partitionClause is always copied from there;
844  * the orderClause might or might not be copied (see copiedOrder); the framing
845  * options are never copied, per spec.
846  */
847 typedef struct WindowClause
848 {
849         NodeTag         type;
850         char       *name;                       /* window name (NULL in an OVER clause) */
851         char       *refname;            /* referenced window name, if any */
852         List       *partitionClause;    /* PARTITION BY list */
853         List       *orderClause;        /* ORDER BY list */
854         int                     frameOptions;   /* frame_clause options, see WindowDef */
855         Node       *startOffset;        /* expression for starting bound, if any */
856         Node       *endOffset;          /* expression for ending bound, if any */
857         Index           winref;                 /* ID referenced by window functions */
858         bool            copiedOrder;    /* did we copy orderClause from refname? */
859 } WindowClause;
860
861 /*
862  * RowMarkClause -
863  *         parser output representation of FOR UPDATE/SHARE clauses
864  *
865  * Query.rowMarks contains a separate RowMarkClause node for each relation
866  * identified as a FOR UPDATE/SHARE target.  If FOR UPDATE/SHARE is applied
867  * to a subquery, we generate RowMarkClauses for all normal and subquery rels
868  * in the subquery, but they are marked pushedDown = true to distinguish them
869  * from clauses that were explicitly written at this query level.  Also,
870  * Query.hasForUpdate tells whether there were explicit FOR UPDATE/SHARE
871  * clauses in the current query level.
872  */
873 typedef struct RowMarkClause
874 {
875         NodeTag         type;
876         Index           rti;                    /* range table index of target relation */
877         bool            forUpdate;              /* true = FOR UPDATE, false = FOR SHARE */
878         bool            noWait;                 /* NOWAIT option */
879         bool            pushedDown;             /* pushed down from higher query level? */
880 } RowMarkClause;
881
882 /*
883  * WithClause -
884  *         representation of WITH clause
885  *
886  * Note: WithClause does not propagate into the Query representation;
887  * but CommonTableExpr does.
888  */
889 typedef struct WithClause
890 {
891         NodeTag         type;
892         List       *ctes;                       /* list of CommonTableExprs */
893         bool            recursive;              /* true = WITH RECURSIVE */
894         int                     location;               /* token location, or -1 if unknown */
895 } WithClause;
896
897 /*
898  * CommonTableExpr -
899  *         representation of WITH list element
900  *
901  * We don't currently support the SEARCH or CYCLE clause.
902  */
903 typedef struct CommonTableExpr
904 {
905         NodeTag         type;
906         char       *ctename;            /* query name (never qualified) */
907         List       *aliascolnames;      /* optional list of column names */
908         /* SelectStmt/InsertStmt/etc before parse analysis, Query afterwards: */
909         Node       *ctequery;           /* the CTE's subquery */
910         int                     location;               /* token location, or -1 if unknown */
911         /* These fields are set during parse analysis: */
912         bool            cterecursive;   /* is this CTE actually recursive? */
913         int                     cterefcount;    /* number of RTEs referencing this CTE
914                                                                  * (excluding internal self-references) */
915         List       *ctecolnames;        /* list of output column names */
916         List       *ctecoltypes;        /* OID list of output column type OIDs */
917         List       *ctecoltypmods;      /* integer list of output column typmods */
918         List       *ctecolcollations;           /* OID list of column collation OIDs */
919 } CommonTableExpr;
920
921 /* Convenience macro to get the output tlist of a CTE's query */
922 #define GetCTETargetList(cte) \
923         (AssertMacro(IsA((cte)->ctequery, Query)), \
924          ((Query *) (cte)->ctequery)->commandType == CMD_SELECT ? \
925          ((Query *) (cte)->ctequery)->targetList : \
926          ((Query *) (cte)->ctequery)->returningList)
927
928
929 /*****************************************************************************
930  *              Optimizable Statements
931  *****************************************************************************/
932
933 /* ----------------------
934  *              Insert Statement
935  *
936  * The source expression is represented by SelectStmt for both the
937  * SELECT and VALUES cases.  If selectStmt is NULL, then the query
938  * is INSERT ... DEFAULT VALUES.
939  * ----------------------
940  */
941 typedef struct InsertStmt
942 {
943         NodeTag         type;
944         RangeVar   *relation;           /* relation to insert into */
945         List       *cols;                       /* optional: names of the target columns */
946         Node       *selectStmt;         /* the source SELECT/VALUES, or NULL */
947         List       *returningList;      /* list of expressions to return */
948         WithClause *withClause;         /* WITH clause */
949 } InsertStmt;
950
951 /* ----------------------
952  *              Delete Statement
953  * ----------------------
954  */
955 typedef struct DeleteStmt
956 {
957         NodeTag         type;
958         RangeVar   *relation;           /* relation to delete from */
959         List       *usingClause;        /* optional using clause for more tables */
960         Node       *whereClause;        /* qualifications */
961         List       *returningList;      /* list of expressions to return */
962         WithClause *withClause;         /* WITH clause */
963 } DeleteStmt;
964
965 /* ----------------------
966  *              Update Statement
967  * ----------------------
968  */
969 typedef struct UpdateStmt
970 {
971         NodeTag         type;
972         RangeVar   *relation;           /* relation to update */
973         List       *targetList;         /* the target list (of ResTarget) */
974         Node       *whereClause;        /* qualifications */
975         List       *fromClause;         /* optional from clause for more tables */
976         List       *returningList;      /* list of expressions to return */
977         WithClause *withClause;         /* WITH clause */
978 } UpdateStmt;
979
980 /* ----------------------
981  *              Select Statement
982  *
983  * A "simple" SELECT is represented in the output of gram.y by a single
984  * SelectStmt node; so is a VALUES construct.  A query containing set
985  * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
986  * nodes, in which the leaf nodes are component SELECTs and the internal nodes
987  * represent UNION, INTERSECT, or EXCEPT operators.  Using the same node
988  * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
989  * LIMIT, etc, clause values into a SELECT statement without worrying
990  * whether it is a simple or compound SELECT.
991  * ----------------------
992  */
993 typedef enum SetOperation
994 {
995         SETOP_NONE = 0,
996         SETOP_UNION,
997         SETOP_INTERSECT,
998         SETOP_EXCEPT
999 } SetOperation;
1000
1001 typedef struct SelectStmt
1002 {
1003         NodeTag         type;
1004
1005         /*
1006          * These fields are used only in "leaf" SelectStmts.
1007          */
1008         List       *distinctClause; /* NULL, list of DISTINCT ON exprs, or
1009                                                                  * lcons(NIL,NIL) for all (SELECT DISTINCT) */
1010         IntoClause *intoClause;         /* target for SELECT INTO */
1011         List       *targetList;         /* the target list (of ResTarget) */
1012         List       *fromClause;         /* the FROM clause */
1013         Node       *whereClause;        /* WHERE qualification */
1014         List       *groupClause;        /* GROUP BY clauses */
1015         Node       *havingClause;       /* HAVING conditional-expression */
1016         List       *windowClause;       /* WINDOW window_name AS (...), ... */
1017         WithClause *withClause;         /* WITH clause */
1018
1019         /*
1020          * In a "leaf" node representing a VALUES list, the above fields are all
1021          * null, and instead this field is set.  Note that the elements of the
1022          * sublists are just expressions, without ResTarget decoration. Also note
1023          * that a list element can be DEFAULT (represented as a SetToDefault
1024          * node), regardless of the context of the VALUES list. It's up to parse
1025          * analysis to reject that where not valid.
1026          */
1027         List       *valuesLists;        /* untransformed list of expression lists */
1028
1029         /*
1030          * These fields are used in both "leaf" SelectStmts and upper-level
1031          * SelectStmts.
1032          */
1033         List       *sortClause;         /* sort clause (a list of SortBy's) */
1034         Node       *limitOffset;        /* # of result tuples to skip */
1035         Node       *limitCount;         /* # of result tuples to return */
1036         List       *lockingClause;      /* FOR UPDATE (list of LockingClause's) */
1037
1038         /*
1039          * These fields are used only in upper-level SelectStmts.
1040          */
1041         SetOperation op;                        /* type of set op */
1042         bool            all;                    /* ALL specified? */
1043         struct SelectStmt *larg;        /* left child */
1044         struct SelectStmt *rarg;        /* right child */
1045         /* Eventually add fields for CORRESPONDING spec here */
1046 } SelectStmt;
1047
1048
1049 /* ----------------------
1050  *              Set Operation node for post-analysis query trees
1051  *
1052  * After parse analysis, a SELECT with set operations is represented by a
1053  * top-level Query node containing the leaf SELECTs as subqueries in its
1054  * range table.  Its setOperations field shows the tree of set operations,
1055  * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
1056  * nodes replaced by SetOperationStmt nodes.  Information about the output
1057  * column types is added, too.  (Note that the child nodes do not necessarily
1058  * produce these types directly, but we've checked that their output types
1059  * can be coerced to the output column type.)  Also, if it's not UNION ALL,
1060  * information about the types' sort/group semantics is provided in the form
1061  * of a SortGroupClause list (same representation as, eg, DISTINCT).
1062  * The resolved common column collations are provided too; but note that if
1063  * it's not UNION ALL, it's okay for a column to not have a common collation,
1064  * so a member of the colCollations list could be InvalidOid even though the
1065  * column has a collatable type.
1066  * ----------------------
1067  */
1068 typedef struct SetOperationStmt
1069 {
1070         NodeTag         type;
1071         SetOperation op;                        /* type of set op */
1072         bool            all;                    /* ALL specified? */
1073         Node       *larg;                       /* left child */
1074         Node       *rarg;                       /* right child */
1075         /* Eventually add fields for CORRESPONDING spec here */
1076
1077         /* Fields derived during parse analysis: */
1078         List       *colTypes;           /* OID list of output column type OIDs */
1079         List       *colTypmods;         /* integer list of output column typmods */
1080         List       *colCollations;      /* OID list of output column collation OIDs */
1081         List       *groupClauses;       /* a list of SortGroupClause's */
1082         /* groupClauses is NIL if UNION ALL, but must be set otherwise */
1083 } SetOperationStmt;
1084
1085
1086 /*****************************************************************************
1087  *              Other Statements (no optimizations required)
1088  *
1089  *              These are not touched by parser/analyze.c except to put them into
1090  *              the utilityStmt field of a Query.  This is eventually passed to
1091  *              ProcessUtility (by-passing rewriting and planning).  Some of the
1092  *              statements do need attention from parse analysis, and this is
1093  *              done by routines in parser/parse_utilcmd.c after ProcessUtility
1094  *              receives the command for execution.
1095  *****************************************************************************/
1096
1097 /*
1098  * When a command can act on several kinds of objects with only one
1099  * parse structure required, use these constants to designate the
1100  * object type.  Note that commands typically don't support all the types.
1101  */
1102
1103 typedef enum ObjectType
1104 {
1105         OBJECT_AGGREGATE,
1106         OBJECT_ATTRIBUTE,                       /* type's attribute, when distinct from column */
1107         OBJECT_CAST,
1108         OBJECT_COLUMN,
1109         OBJECT_CONSTRAINT,
1110         OBJECT_COLLATION,
1111         OBJECT_CONVERSION,
1112         OBJECT_DATABASE,
1113         OBJECT_DOMAIN,
1114         OBJECT_EXTENSION,
1115         OBJECT_FDW,
1116         OBJECT_FOREIGN_SERVER,
1117         OBJECT_FOREIGN_TABLE,
1118         OBJECT_FUNCTION,
1119         OBJECT_INDEX,
1120         OBJECT_LANGUAGE,
1121         OBJECT_LARGEOBJECT,
1122         OBJECT_OPCLASS,
1123         OBJECT_OPERATOR,
1124         OBJECT_OPFAMILY,
1125         OBJECT_ROLE,
1126         OBJECT_RULE,
1127         OBJECT_SCHEMA,
1128         OBJECT_SEQUENCE,
1129         OBJECT_TABLE,
1130         OBJECT_TABLESPACE,
1131         OBJECT_TRIGGER,
1132         OBJECT_TSCONFIGURATION,
1133         OBJECT_TSDICTIONARY,
1134         OBJECT_TSPARSER,
1135         OBJECT_TSTEMPLATE,
1136         OBJECT_TYPE,
1137         OBJECT_VIEW
1138 } ObjectType;
1139
1140 /* ----------------------
1141  *              Create Schema Statement
1142  *
1143  * NOTE: the schemaElts list contains raw parsetrees for component statements
1144  * of the schema, such as CREATE TABLE, GRANT, etc.  These are analyzed and
1145  * executed after the schema itself is created.
1146  * ----------------------
1147  */
1148 typedef struct CreateSchemaStmt
1149 {
1150         NodeTag         type;
1151         char       *schemaname;         /* the name of the schema to create */
1152         char       *authid;                     /* the owner of the created schema */
1153         List       *schemaElts;         /* schema components (list of parsenodes) */
1154 } CreateSchemaStmt;
1155
1156 typedef enum DropBehavior
1157 {
1158         DROP_RESTRICT,                          /* drop fails if any dependent objects */
1159         DROP_CASCADE                            /* remove dependent objects too */
1160 } DropBehavior;
1161
1162 /* ----------------------
1163  *      Alter Table
1164  * ----------------------
1165  */
1166 typedef struct AlterTableStmt
1167 {
1168         NodeTag         type;
1169         RangeVar   *relation;           /* table to work on */
1170         List       *cmds;                       /* list of subcommands */
1171         ObjectType      relkind;                /* type of object */
1172         bool       missing_ok;          /* skip error if table missing */
1173 } AlterTableStmt;
1174
1175 typedef enum AlterTableType
1176 {
1177         AT_AddColumn,                           /* add column */
1178         AT_AddColumnRecurse,            /* internal to commands/tablecmds.c */
1179         AT_AddColumnToView,                     /* implicitly via CREATE OR REPLACE VIEW */
1180         AT_ColumnDefault,                       /* alter column default */
1181         AT_DropNotNull,                         /* alter column drop not null */
1182         AT_SetNotNull,                          /* alter column set not null */
1183         AT_SetStatistics,                       /* alter column set statistics */
1184         AT_SetOptions,                          /* alter column set ( options ) */
1185         AT_ResetOptions,                        /* alter column reset ( options ) */
1186         AT_SetStorage,                          /* alter column set storage */
1187         AT_DropColumn,                          /* drop column */
1188         AT_DropColumnRecurse,           /* internal to commands/tablecmds.c */
1189         AT_AddIndex,                            /* add index */
1190         AT_ReAddIndex,                          /* internal to commands/tablecmds.c */
1191         AT_AddConstraint,                       /* add constraint */
1192         AT_AddConstraintRecurse,        /* internal to commands/tablecmds.c */
1193         AT_ValidateConstraint,          /* validate constraint */
1194         AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */
1195         AT_ProcessedConstraint,         /* pre-processed add constraint (local in
1196                                                                  * parser/parse_utilcmd.c) */
1197         AT_AddIndexConstraint,          /* add constraint using existing index */
1198         AT_DropConstraint,                      /* drop constraint */
1199         AT_DropConstraintRecurse,       /* internal to commands/tablecmds.c */
1200         AT_AlterColumnType,                     /* alter column type */
1201         AT_AlterColumnGenericOptions,   /* alter column OPTIONS (...) */
1202         AT_ChangeOwner,                         /* change owner */
1203         AT_ClusterOn,                           /* CLUSTER ON */
1204         AT_DropCluster,                         /* SET WITHOUT CLUSTER */
1205         AT_AddOids,                                     /* SET WITH OIDS */
1206         AT_AddOidsRecurse,                      /* internal to commands/tablecmds.c */
1207         AT_DropOids,                            /* SET WITHOUT OIDS */
1208         AT_SetTableSpace,                       /* SET TABLESPACE */
1209         AT_SetRelOptions,                       /* SET (...) -- AM specific parameters */
1210         AT_ResetRelOptions,                     /* RESET (...) -- AM specific parameters */
1211         AT_ReplaceRelOptions,           /* replace reloption list in its entirety */
1212         AT_EnableTrig,                          /* ENABLE TRIGGER name */
1213         AT_EnableAlwaysTrig,            /* ENABLE ALWAYS TRIGGER name */
1214         AT_EnableReplicaTrig,           /* ENABLE REPLICA TRIGGER name */
1215         AT_DisableTrig,                         /* DISABLE TRIGGER name */
1216         AT_EnableTrigAll,                       /* ENABLE TRIGGER ALL */
1217         AT_DisableTrigAll,                      /* DISABLE TRIGGER ALL */
1218         AT_EnableTrigUser,                      /* ENABLE TRIGGER USER */
1219         AT_DisableTrigUser,                     /* DISABLE TRIGGER USER */
1220         AT_EnableRule,                          /* ENABLE RULE name */
1221         AT_EnableAlwaysRule,            /* ENABLE ALWAYS RULE name */
1222         AT_EnableReplicaRule,           /* ENABLE REPLICA RULE name */
1223         AT_DisableRule,                         /* DISABLE RULE name */
1224         AT_AddInherit,                          /* INHERIT parent */
1225         AT_DropInherit,                         /* NO INHERIT parent */
1226         AT_AddOf,                                       /* OF <type_name> */
1227         AT_DropOf,                                      /* NOT OF */
1228         AT_GenericOptions                       /* OPTIONS (...) */
1229 } AlterTableType;
1230
1231 typedef struct AlterTableCmd    /* one subcommand of an ALTER TABLE */
1232 {
1233         NodeTag         type;
1234         AlterTableType subtype;         /* Type of table alteration to apply */
1235         char       *name;                       /* column, constraint, or trigger to act on,
1236                                                                  * or new owner or tablespace */
1237         Node       *def;                        /* definition of new column, index,
1238                                                                  * constraint, or parent table */
1239         DropBehavior behavior;          /* RESTRICT or CASCADE for DROP cases */
1240         bool            missing_ok;             /* skip error if missing? */
1241 } AlterTableCmd;
1242
1243
1244 /* ----------------------
1245  *      Alter Domain
1246  *
1247  * The fields are used in different ways by the different variants of
1248  * this command.
1249  * ----------------------
1250  */
1251 typedef struct AlterDomainStmt
1252 {
1253         NodeTag         type;
1254         char            subtype;                /*------------
1255                                                                  *      T = alter column default
1256                                                                  *      N = alter column drop not null
1257                                                                  *      O = alter column set not null
1258                                                                  *      C = add constraint
1259                                                                  *      X = drop constraint
1260                                                                  *------------
1261                                                                  */
1262         List       *typeName;           /* domain to work on */
1263         char       *name;                       /* column or constraint name to act on */
1264         Node       *def;                        /* definition of default or constraint */
1265         DropBehavior behavior;          /* RESTRICT or CASCADE for DROP cases */
1266         bool            missing_ok;             /* skip error if missing? */
1267 } AlterDomainStmt;
1268
1269
1270 /* ----------------------
1271  *              Grant|Revoke Statement
1272  * ----------------------
1273  */
1274 typedef enum GrantTargetType
1275 {
1276         ACL_TARGET_OBJECT,                      /* grant on specific named object(s) */
1277         ACL_TARGET_ALL_IN_SCHEMA,       /* grant on all objects in given schema(s) */
1278         ACL_TARGET_DEFAULTS                     /* ALTER DEFAULT PRIVILEGES */
1279 } GrantTargetType;
1280
1281 typedef enum GrantObjectType
1282 {
1283         ACL_OBJECT_COLUMN,                      /* column */
1284         ACL_OBJECT_RELATION,            /* table, view */
1285         ACL_OBJECT_SEQUENCE,            /* sequence */
1286         ACL_OBJECT_DATABASE,            /* database */
1287         ACL_OBJECT_DOMAIN,                      /* domain */
1288         ACL_OBJECT_FDW,                         /* foreign-data wrapper */
1289         ACL_OBJECT_FOREIGN_SERVER,      /* foreign server */
1290         ACL_OBJECT_FUNCTION,            /* function */
1291         ACL_OBJECT_LANGUAGE,            /* procedural language */
1292         ACL_OBJECT_LARGEOBJECT,         /* largeobject */
1293         ACL_OBJECT_NAMESPACE,           /* namespace */
1294         ACL_OBJECT_TABLESPACE,          /* tablespace */
1295         ACL_OBJECT_TYPE                         /* type */
1296 } GrantObjectType;
1297
1298 typedef struct GrantStmt
1299 {
1300         NodeTag         type;
1301         bool            is_grant;               /* true = GRANT, false = REVOKE */
1302         GrantTargetType targtype;       /* type of the grant target */
1303         GrantObjectType objtype;        /* kind of object being operated on */
1304         List       *objects;            /* list of RangeVar nodes, FuncWithArgs nodes,
1305                                                                  * or plain names (as Value strings) */
1306         List       *privileges;         /* list of AccessPriv nodes */
1307         /* privileges == NIL denotes ALL PRIVILEGES */
1308         List       *grantees;           /* list of PrivGrantee nodes */
1309         bool            grant_option;   /* grant or revoke grant option */
1310         DropBehavior behavior;          /* drop behavior (for REVOKE) */
1311 } GrantStmt;
1312
1313 typedef struct PrivGrantee
1314 {
1315         NodeTag         type;
1316         char       *rolname;            /* if NULL then PUBLIC */
1317 } PrivGrantee;
1318
1319 /*
1320  * Note: FuncWithArgs carries only the types of the input parameters of the
1321  * function.  So it is sufficient to identify an existing function, but it
1322  * is not enough info to define a function nor to call it.
1323  */
1324 typedef struct FuncWithArgs
1325 {
1326         NodeTag         type;
1327         List       *funcname;           /* qualified name of function */
1328         List       *funcargs;           /* list of Typename nodes */
1329 } FuncWithArgs;
1330
1331 /*
1332  * An access privilege, with optional list of column names
1333  * priv_name == NULL denotes ALL PRIVILEGES (only used with a column list)
1334  * cols == NIL denotes "all columns"
1335  * Note that simple "ALL PRIVILEGES" is represented as a NIL list, not
1336  * an AccessPriv with both fields null.
1337  */
1338 typedef struct AccessPriv
1339 {
1340         NodeTag         type;
1341         char       *priv_name;          /* string name of privilege */
1342         List       *cols;                       /* list of Value strings */
1343 } AccessPriv;
1344
1345 /* ----------------------
1346  *              Grant/Revoke Role Statement
1347  *
1348  * Note: because of the parsing ambiguity with the GRANT <privileges>
1349  * statement, granted_roles is a list of AccessPriv; the execution code
1350  * should complain if any column lists appear.  grantee_roles is a list
1351  * of role names, as Value strings.
1352  * ----------------------
1353  */
1354 typedef struct GrantRoleStmt
1355 {
1356         NodeTag         type;
1357         List       *granted_roles;      /* list of roles to be granted/revoked */
1358         List       *grantee_roles;      /* list of member roles to add/delete */
1359         bool            is_grant;               /* true = GRANT, false = REVOKE */
1360         bool            admin_opt;              /* with admin option */
1361         char       *grantor;            /* set grantor to other than current role */
1362         DropBehavior behavior;          /* drop behavior (for REVOKE) */
1363 } GrantRoleStmt;
1364
1365 /* ----------------------
1366  *      Alter Default Privileges Statement
1367  * ----------------------
1368  */
1369 typedef struct AlterDefaultPrivilegesStmt
1370 {
1371         NodeTag         type;
1372         List       *options;            /* list of DefElem */
1373         GrantStmt  *action;                     /* GRANT/REVOKE action (with objects=NIL) */
1374 } AlterDefaultPrivilegesStmt;
1375
1376 /* ----------------------
1377  *              Copy Statement
1378  *
1379  * We support "COPY relation FROM file", "COPY relation TO file", and
1380  * "COPY (query) TO file".      In any given CopyStmt, exactly one of "relation"
1381  * and "query" must be non-NULL.
1382  * ----------------------
1383  */
1384 typedef struct CopyStmt
1385 {
1386         NodeTag         type;
1387         RangeVar   *relation;           /* the relation to copy */
1388         Node       *query;                      /* the SELECT query to copy */
1389         List       *attlist;            /* List of column names (as Strings), or NIL
1390                                                                  * for all columns */
1391         bool            is_from;                /* TO or FROM */
1392         char       *filename;           /* filename, or NULL for STDIN/STDOUT */
1393         List       *options;            /* List of DefElem nodes */
1394 } CopyStmt;
1395
1396 /* ----------------------
1397  * SET Statement (includes RESET)
1398  *
1399  * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
1400  * preserve the distinction in VariableSetKind for CreateCommandTag().
1401  * ----------------------
1402  */
1403 typedef enum
1404 {
1405         VAR_SET_VALUE,                          /* SET var = value */
1406         VAR_SET_DEFAULT,                        /* SET var TO DEFAULT */
1407         VAR_SET_CURRENT,                        /* SET var FROM CURRENT */
1408         VAR_SET_MULTI,                          /* special case for SET TRANSACTION ... */
1409         VAR_RESET,                                      /* RESET var */
1410         VAR_RESET_ALL                           /* RESET ALL */
1411 } VariableSetKind;
1412
1413 typedef struct VariableSetStmt
1414 {
1415         NodeTag         type;
1416         VariableSetKind kind;
1417         char       *name;                       /* variable to be set */
1418         List       *args;                       /* List of A_Const nodes */
1419         bool            is_local;               /* SET LOCAL? */
1420 } VariableSetStmt;
1421
1422 /* ----------------------
1423  * Show Statement
1424  * ----------------------
1425  */
1426 typedef struct VariableShowStmt
1427 {
1428         NodeTag         type;
1429         char       *name;
1430 } VariableShowStmt;
1431
1432 /* ----------------------
1433  *              Create Table Statement
1434  *
1435  * NOTE: in the raw gram.y output, ColumnDef and Constraint nodes are
1436  * intermixed in tableElts, and constraints is NIL.  After parse analysis,
1437  * tableElts contains just ColumnDefs, and constraints contains just
1438  * Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
1439  * implementation).
1440  * ----------------------
1441  */
1442
1443 typedef struct CreateStmt
1444 {
1445         NodeTag         type;
1446         RangeVar   *relation;           /* relation to create */
1447         List       *tableElts;          /* column definitions (list of ColumnDef) */
1448         List       *inhRelations;       /* relations to inherit from (list of
1449                                                                  * inhRelation) */
1450         TypeName   *ofTypename;         /* OF typename */
1451         List       *constraints;        /* constraints (list of Constraint nodes) */
1452         List       *options;            /* options from WITH clause */
1453         OnCommitAction oncommit;        /* what do we do at COMMIT? */
1454         char       *tablespacename; /* table space to use, or NULL */
1455         bool            if_not_exists;  /* just do nothing if it already exists? */
1456 } CreateStmt;
1457
1458 /* ----------
1459  * Definitions for constraints in CreateStmt
1460  *
1461  * Note that column defaults are treated as a type of constraint,
1462  * even though that's a bit odd semantically.
1463  *
1464  * For constraints that use expressions (CONSTR_CHECK, CONSTR_DEFAULT)
1465  * we may have the expression in either "raw" form (an untransformed
1466  * parse tree) or "cooked" form (the nodeToString representation of
1467  * an executable expression tree), depending on how this Constraint
1468  * node was created (by parsing, or by inheritance from an existing
1469  * relation).  We should never have both in the same node!
1470  *
1471  * FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
1472  * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
1473  * stored into pg_constraint.confmatchtype.  Changing the code values may
1474  * require an initdb!
1475  *
1476  * If skip_validation is true then we skip checking that the existing rows
1477  * in the table satisfy the constraint, and just install the catalog entries
1478  * for the constraint.  A new FK constraint is marked as valid iff
1479  * initially_valid is true.  (Usually skip_validation and initially_valid
1480  * are inverses, but we can set both true if the table is known empty.)
1481  *
1482  * Constraint attributes (DEFERRABLE etc) are initially represented as
1483  * separate Constraint nodes for simplicity of parsing.  parse_utilcmd.c makes
1484  * a pass through the constraints list to insert the info into the appropriate
1485  * Constraint node.
1486  * ----------
1487  */
1488
1489 typedef enum ConstrType                 /* types of constraints */
1490 {
1491         CONSTR_NULL,                            /* not SQL92, but a lot of people expect it */
1492         CONSTR_NOTNULL,
1493         CONSTR_DEFAULT,
1494         CONSTR_CHECK,
1495         CONSTR_PRIMARY,
1496         CONSTR_UNIQUE,
1497         CONSTR_EXCLUSION,
1498         CONSTR_FOREIGN,
1499         CONSTR_ATTR_DEFERRABLE,         /* attributes for previous constraint node */
1500         CONSTR_ATTR_NOT_DEFERRABLE,
1501         CONSTR_ATTR_DEFERRED,
1502         CONSTR_ATTR_IMMEDIATE
1503 } ConstrType;
1504
1505 /* Foreign key action codes */
1506 #define FKCONSTR_ACTION_NOACTION        'a'
1507 #define FKCONSTR_ACTION_RESTRICT        'r'
1508 #define FKCONSTR_ACTION_CASCADE         'c'
1509 #define FKCONSTR_ACTION_SETNULL         'n'
1510 #define FKCONSTR_ACTION_SETDEFAULT      'd'
1511
1512 /* Foreign key matchtype codes */
1513 #define FKCONSTR_MATCH_FULL                     'f'
1514 #define FKCONSTR_MATCH_PARTIAL          'p'
1515 #define FKCONSTR_MATCH_UNSPECIFIED      'u'
1516
1517 typedef struct Constraint
1518 {
1519         NodeTag         type;
1520         ConstrType      contype;                /* see above */
1521
1522         /* Fields used for most/all constraint types: */
1523         char       *conname;            /* Constraint name, or NULL if unnamed */
1524         bool            deferrable;             /* DEFERRABLE? */
1525         bool            initdeferred;   /* INITIALLY DEFERRED? */
1526         int                     location;               /* token location, or -1 if unknown */
1527
1528         /* Fields used for constraints with expressions (CHECK and DEFAULT): */
1529         Node       *raw_expr;           /* expr, as untransformed parse tree */
1530         char       *cooked_expr;        /* expr, as nodeToString representation */
1531
1532         /* Fields used for unique constraints (UNIQUE and PRIMARY KEY): */
1533         List       *keys;                       /* String nodes naming referenced column(s) */
1534
1535         /* Fields used for EXCLUSION constraints: */
1536         List       *exclusions;         /* list of (IndexElem, operator name) pairs */
1537
1538         /* Fields used for index constraints (UNIQUE, PRIMARY KEY, EXCLUSION): */
1539         List       *options;            /* options from WITH clause */
1540         char       *indexname;          /* existing index to use; otherwise NULL */
1541         char       *indexspace;         /* index tablespace; NULL for default */
1542         /* These could be, but currently are not, used for UNIQUE/PKEY: */
1543         char       *access_method;      /* index access method; NULL for default */
1544         Node       *where_clause;       /* partial index predicate */
1545
1546         /* Fields used for FOREIGN KEY constraints: */
1547         RangeVar   *pktable;            /* Primary key table */
1548         List       *fk_attrs;           /* Attributes of foreign key */
1549         List       *pk_attrs;           /* Corresponding attrs in PK table */
1550         char            fk_matchtype;   /* FULL, PARTIAL, UNSPECIFIED */
1551         char            fk_upd_action;  /* ON UPDATE action */
1552         char            fk_del_action;  /* ON DELETE action */
1553         List       *old_conpfeqop;      /* pg_constraint.conpfeqop of my former self */
1554
1555         /* Fields used for constraints that allow a NOT VALID specification */
1556         bool            skip_validation;        /* skip validation of existing rows? */
1557         bool            initially_valid;        /* mark the new constraint as valid? */
1558 } Constraint;
1559
1560 /* ----------------------
1561  *              Create/Drop Table Space Statements
1562  * ----------------------
1563  */
1564
1565 typedef struct CreateTableSpaceStmt
1566 {
1567         NodeTag         type;
1568         char       *tablespacename;
1569         char       *owner;
1570         char       *location;
1571 } CreateTableSpaceStmt;
1572
1573 typedef struct DropTableSpaceStmt
1574 {
1575         NodeTag         type;
1576         char       *tablespacename;
1577         bool            missing_ok;             /* skip error if missing? */
1578 } DropTableSpaceStmt;
1579
1580 typedef struct AlterTableSpaceOptionsStmt
1581 {
1582         NodeTag         type;
1583         char       *tablespacename;
1584         List       *options;
1585         bool            isReset;
1586 } AlterTableSpaceOptionsStmt;
1587
1588 /* ----------------------
1589  *              Create/Alter Extension Statements
1590  * ----------------------
1591  */
1592
1593 typedef struct CreateExtensionStmt
1594 {
1595         NodeTag         type;
1596         char       *extname;
1597         bool            if_not_exists;  /* just do nothing if it already exists? */
1598         List       *options;            /* List of DefElem nodes */
1599 } CreateExtensionStmt;
1600
1601 /* Only used for ALTER EXTENSION UPDATE; later might need an action field */
1602 typedef struct AlterExtensionStmt
1603 {
1604         NodeTag         type;
1605         char       *extname;
1606         List       *options;            /* List of DefElem nodes */
1607 } AlterExtensionStmt;
1608
1609 typedef struct AlterExtensionContentsStmt
1610 {
1611         NodeTag         type;
1612         char       *extname;            /* Extension's name */
1613         int                     action;                 /* +1 = add object, -1 = drop object */
1614         ObjectType      objtype;                /* Object's type */
1615         List       *objname;            /* Qualified name of the object */
1616         List       *objargs;            /* Arguments if needed (eg, for functions) */
1617 } AlterExtensionContentsStmt;
1618
1619 /* ----------------------
1620  *              Create/Alter FOREIGN DATA WRAPPER Statements
1621  * ----------------------
1622  */
1623
1624 typedef struct CreateFdwStmt
1625 {
1626         NodeTag         type;
1627         char       *fdwname;            /* foreign-data wrapper name */
1628         List       *func_options;       /* HANDLER/VALIDATOR options */
1629         List       *options;            /* generic options to FDW */
1630 } CreateFdwStmt;
1631
1632 typedef struct AlterFdwStmt
1633 {
1634         NodeTag         type;
1635         char       *fdwname;            /* foreign-data wrapper name */
1636         List       *func_options;       /* HANDLER/VALIDATOR options */
1637         List       *options;            /* generic options to FDW */
1638 } AlterFdwStmt;
1639
1640 /* ----------------------
1641  *              Create/Alter FOREIGN SERVER Statements
1642  * ----------------------
1643  */
1644
1645 typedef struct CreateForeignServerStmt
1646 {
1647         NodeTag         type;
1648         char       *servername;         /* server name */
1649         char       *servertype;         /* optional server type */
1650         char       *version;            /* optional server version */
1651         char       *fdwname;            /* FDW name */
1652         List       *options;            /* generic options to server */
1653 } CreateForeignServerStmt;
1654
1655 typedef struct AlterForeignServerStmt
1656 {
1657         NodeTag         type;
1658         char       *servername;         /* server name */
1659         char       *version;            /* optional server version */
1660         List       *options;            /* generic options to server */
1661         bool            has_version;    /* version specified */
1662 } AlterForeignServerStmt;
1663
1664 /* ----------------------
1665  *              Create FOREIGN TABLE Statements
1666  * ----------------------
1667  */
1668
1669 typedef struct CreateForeignTableStmt
1670 {
1671         CreateStmt      base;
1672         char       *servername;
1673         List       *options;
1674 } CreateForeignTableStmt;
1675
1676 /* ----------------------
1677  *              Create/Drop USER MAPPING Statements
1678  * ----------------------
1679  */
1680
1681 typedef struct CreateUserMappingStmt
1682 {
1683         NodeTag         type;
1684         char       *username;           /* username or PUBLIC/CURRENT_USER */
1685         char       *servername;         /* server name */
1686         List       *options;            /* generic options to server */
1687 } CreateUserMappingStmt;
1688
1689 typedef struct AlterUserMappingStmt
1690 {
1691         NodeTag         type;
1692         char       *username;           /* username or PUBLIC/CURRENT_USER */
1693         char       *servername;         /* server name */
1694         List       *options;            /* generic options to server */
1695 } AlterUserMappingStmt;
1696
1697 typedef struct DropUserMappingStmt
1698 {
1699         NodeTag         type;
1700         char       *username;           /* username or PUBLIC/CURRENT_USER */
1701         char       *servername;         /* server name */
1702         bool            missing_ok;             /* ignore missing mappings */
1703 } DropUserMappingStmt;
1704
1705 /* ----------------------
1706  *              Create TRIGGER Statement
1707  * ----------------------
1708  */
1709 typedef struct CreateTrigStmt
1710 {
1711         NodeTag         type;
1712         char       *trigname;           /* TRIGGER's name */
1713         RangeVar   *relation;           /* relation trigger is on */
1714         List       *funcname;           /* qual. name of function to call */
1715         List       *args;                       /* list of (T_String) Values or NIL */
1716         bool            row;                    /* ROW/STATEMENT */
1717         /* timing uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */
1718         int16           timing;                 /* BEFORE, AFTER, or INSTEAD */
1719         /* events uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */
1720         int16           events;                 /* "OR" of INSERT/UPDATE/DELETE/TRUNCATE */
1721         List       *columns;            /* column names, or NIL for all columns */
1722         Node       *whenClause;         /* qual expression, or NULL if none */
1723         bool            isconstraint;   /* This is a constraint trigger */
1724         /* The remaining fields are only used for constraint triggers */
1725         bool            deferrable;             /* [NOT] DEFERRABLE */
1726         bool            initdeferred;   /* INITIALLY {DEFERRED|IMMEDIATE} */
1727         RangeVar   *constrrel;          /* opposite relation, if RI trigger */
1728 } CreateTrigStmt;
1729
1730 /* ----------------------
1731  *              Create PROCEDURAL LANGUAGE Statements
1732  * ----------------------
1733  */
1734 typedef struct CreatePLangStmt
1735 {
1736         NodeTag         type;
1737         bool            replace;                /* T => replace if already exists */
1738         char       *plname;                     /* PL name */
1739         List       *plhandler;          /* PL call handler function (qual. name) */
1740         List       *plinline;           /* optional inline function (qual. name) */
1741         List       *plvalidator;        /* optional validator function (qual. name) */
1742         bool            pltrusted;              /* PL is trusted */
1743 } CreatePLangStmt;
1744
1745 /* ----------------------
1746  *      Create/Alter/Drop Role Statements
1747  *
1748  * Note: these node types are also used for the backwards-compatible
1749  * Create/Alter/Drop User/Group statements.  In the ALTER and DROP cases
1750  * there's really no need to distinguish what the original spelling was,
1751  * but for CREATE we mark the type because the defaults vary.
1752  * ----------------------
1753  */
1754 typedef enum RoleStmtType
1755 {
1756         ROLESTMT_ROLE,
1757         ROLESTMT_USER,
1758         ROLESTMT_GROUP
1759 } RoleStmtType;
1760
1761 typedef struct CreateRoleStmt
1762 {
1763         NodeTag         type;
1764         RoleStmtType stmt_type;         /* ROLE/USER/GROUP */
1765         char       *role;                       /* role name */
1766         List       *options;            /* List of DefElem nodes */
1767 } CreateRoleStmt;
1768
1769 typedef struct AlterRoleStmt
1770 {
1771         NodeTag         type;
1772         char       *role;                       /* role name */
1773         List       *options;            /* List of DefElem nodes */
1774         int                     action;                 /* +1 = add members, -1 = drop members */
1775 } AlterRoleStmt;
1776
1777 typedef struct AlterRoleSetStmt
1778 {
1779         NodeTag         type;
1780         char       *role;                       /* role name */
1781         char       *database;           /* database name, or NULL */
1782         VariableSetStmt *setstmt;       /* SET or RESET subcommand */
1783 } AlterRoleSetStmt;
1784
1785 typedef struct DropRoleStmt
1786 {
1787         NodeTag         type;
1788         List       *roles;                      /* List of roles to remove */
1789         bool            missing_ok;             /* skip error if a role is missing? */
1790 } DropRoleStmt;
1791
1792 /* ----------------------
1793  *              {Create|Alter} SEQUENCE Statement
1794  * ----------------------
1795  */
1796
1797 typedef struct CreateSeqStmt
1798 {
1799         NodeTag         type;
1800         RangeVar   *sequence;           /* the sequence to create */
1801         List       *options;
1802         Oid                     ownerId;                /* ID of owner, or InvalidOid for default */
1803 } CreateSeqStmt;
1804
1805 typedef struct AlterSeqStmt
1806 {
1807         NodeTag         type;
1808         RangeVar   *sequence;           /* the sequence to alter */
1809         List       *options;
1810         bool            missing_ok;             /* skip error if a role is missing? */
1811 } AlterSeqStmt;
1812
1813 /* ----------------------
1814  *              Create {Aggregate|Operator|Type} Statement
1815  * ----------------------
1816  */
1817 typedef struct DefineStmt
1818 {
1819         NodeTag         type;
1820         ObjectType      kind;                   /* aggregate, operator, type */
1821         bool            oldstyle;               /* hack to signal old CREATE AGG syntax */
1822         List       *defnames;           /* qualified name (list of Value strings) */
1823         List       *args;                       /* a list of TypeName (if needed) */
1824         List       *definition;         /* a list of DefElem */
1825 } DefineStmt;
1826
1827 /* ----------------------
1828  *              Create Domain Statement
1829  * ----------------------
1830  */
1831 typedef struct CreateDomainStmt
1832 {
1833         NodeTag         type;
1834         List       *domainname;         /* qualified name (list of Value strings) */
1835         TypeName   *typeName;           /* the base type */
1836         CollateClause *collClause;      /* untransformed COLLATE spec, if any */
1837         List       *constraints;        /* constraints (list of Constraint nodes) */
1838 } CreateDomainStmt;
1839
1840 /* ----------------------
1841  *              Create Operator Class Statement
1842  * ----------------------
1843  */
1844 typedef struct CreateOpClassStmt
1845 {
1846         NodeTag         type;
1847         List       *opclassname;        /* qualified name (list of Value strings) */
1848         List       *opfamilyname;       /* qualified name (ditto); NIL if omitted */
1849         char       *amname;                     /* name of index AM opclass is for */
1850         TypeName   *datatype;           /* datatype of indexed column */
1851         List       *items;                      /* List of CreateOpClassItem nodes */
1852         bool            isDefault;              /* Should be marked as default for type? */
1853 } CreateOpClassStmt;
1854
1855 #define OPCLASS_ITEM_OPERATOR           1
1856 #define OPCLASS_ITEM_FUNCTION           2
1857 #define OPCLASS_ITEM_STORAGETYPE        3
1858
1859 typedef struct CreateOpClassItem
1860 {
1861         NodeTag         type;
1862         int                     itemtype;               /* see codes above */
1863         /* fields used for an operator or function item: */
1864         List       *name;                       /* operator or function name */
1865         List       *args;                       /* argument types */
1866         int                     number;                 /* strategy num or support proc num */
1867         List       *order_family;       /* only used for ordering operators */
1868         List       *class_args;         /* only used for functions */
1869         /* fields used for a storagetype item: */
1870         TypeName   *storedtype;         /* datatype stored in index */
1871 } CreateOpClassItem;
1872
1873 /* ----------------------
1874  *              Create Operator Family Statement
1875  * ----------------------
1876  */
1877 typedef struct CreateOpFamilyStmt
1878 {
1879         NodeTag         type;
1880         List       *opfamilyname;       /* qualified name (list of Value strings) */
1881         char       *amname;                     /* name of index AM opfamily is for */
1882 } CreateOpFamilyStmt;
1883
1884 /* ----------------------
1885  *              Alter Operator Family Statement
1886  * ----------------------
1887  */
1888 typedef struct AlterOpFamilyStmt
1889 {
1890         NodeTag         type;
1891         List       *opfamilyname;       /* qualified name (list of Value strings) */
1892         char       *amname;                     /* name of index AM opfamily is for */
1893         bool            isDrop;                 /* ADD or DROP the items? */
1894         List       *items;                      /* List of CreateOpClassItem nodes */
1895 } AlterOpFamilyStmt;
1896
1897 /* ----------------------
1898  *              Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
1899  * ----------------------
1900  */
1901
1902 typedef struct DropStmt
1903 {
1904         NodeTag         type;
1905         List       *objects;            /* list of sublists of names (as Values) */
1906         List       *arguments;          /* list of sublists of arguments (as Values) */
1907         ObjectType      removeType;             /* object type */
1908         DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
1909         bool            missing_ok;             /* skip error if object is missing? */
1910 } DropStmt;
1911
1912 /* ----------------------
1913  *                              Truncate Table Statement
1914  * ----------------------
1915  */
1916 typedef struct TruncateStmt
1917 {
1918         NodeTag         type;
1919         List       *relations;          /* relations (RangeVars) to be truncated */
1920         bool            restart_seqs;   /* restart owned sequences? */
1921         DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
1922 } TruncateStmt;
1923
1924 /* ----------------------
1925  *                              Comment On Statement
1926  * ----------------------
1927  */
1928 typedef struct CommentStmt
1929 {
1930         NodeTag         type;
1931         ObjectType      objtype;                /* Object's type */
1932         List       *objname;            /* Qualified name of the object */
1933         List       *objargs;            /* Arguments if needed (eg, for functions) */
1934         char       *comment;            /* Comment to insert, or NULL to remove */
1935 } CommentStmt;
1936
1937 /* ----------------------
1938  *                              SECURITY LABEL Statement
1939  * ----------------------
1940  */
1941 typedef struct SecLabelStmt
1942 {
1943         NodeTag         type;
1944         ObjectType      objtype;                /* Object's type */
1945         List       *objname;            /* Qualified name of the object */
1946         List       *objargs;            /* Arguments if needed (eg, for functions) */
1947         char       *provider;           /* Label provider (or NULL) */
1948         char       *label;                      /* New security label to be assigned */
1949 } SecLabelStmt;
1950
1951 /* ----------------------
1952  *              Declare Cursor Statement
1953  *
1954  * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar
1955  * output.      After parse analysis it's set to null, and the Query points to the
1956  * DeclareCursorStmt, not vice versa.
1957  * ----------------------
1958  */
1959 #define CURSOR_OPT_BINARY               0x0001  /* BINARY */
1960 #define CURSOR_OPT_SCROLL               0x0002  /* SCROLL explicitly given */
1961 #define CURSOR_OPT_NO_SCROLL    0x0004  /* NO SCROLL explicitly given */
1962 #define CURSOR_OPT_INSENSITIVE  0x0008  /* INSENSITIVE */
1963 #define CURSOR_OPT_HOLD                 0x0010  /* WITH HOLD */
1964 /* these planner-control flags do not correspond to any SQL grammar: */
1965 #define CURSOR_OPT_FAST_PLAN    0x0020  /* prefer fast-start plan */
1966 #define CURSOR_OPT_GENERIC_PLAN 0x0040  /* force use of generic plan */
1967 #define CURSOR_OPT_CUSTOM_PLAN  0x0080  /* force use of custom plan */
1968
1969 typedef struct DeclareCursorStmt
1970 {
1971         NodeTag         type;
1972         char       *portalname;         /* name of the portal (cursor) */
1973         int                     options;                /* bitmask of options (see above) */
1974         Node       *query;                      /* the raw SELECT query */
1975 } DeclareCursorStmt;
1976
1977 /* ----------------------
1978  *              Close Portal Statement
1979  * ----------------------
1980  */
1981 typedef struct ClosePortalStmt
1982 {
1983         NodeTag         type;
1984         char       *portalname;         /* name of the portal (cursor) */
1985         /* NULL means CLOSE ALL */
1986 } ClosePortalStmt;
1987
1988 /* ----------------------
1989  *              Fetch Statement (also Move)
1990  * ----------------------
1991  */
1992 typedef enum FetchDirection
1993 {
1994         /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1995         FETCH_FORWARD,
1996         FETCH_BACKWARD,
1997         /* for these, howMany indicates a position; only one row is fetched */
1998         FETCH_ABSOLUTE,
1999         FETCH_RELATIVE
2000 } FetchDirection;
2001
2002 #define FETCH_ALL       LONG_MAX
2003
2004 typedef struct FetchStmt
2005 {
2006         NodeTag         type;
2007         FetchDirection direction;       /* see above */
2008         long            howMany;                /* number of rows, or position argument */
2009         char       *portalname;         /* name of portal (cursor) */
2010         bool            ismove;                 /* TRUE if MOVE */
2011 } FetchStmt;
2012
2013 /* ----------------------
2014  *              Create Index Statement
2015  *
2016  * This represents creation of an index and/or an associated constraint.
2017  * If indexOid isn't InvalidOid, we are not creating an index, just a
2018  * UNIQUE/PKEY constraint using an existing index.      isconstraint must always
2019  * be true in this case, and the fields describing the index properties are
2020  * empty.
2021  * ----------------------
2022  */
2023 typedef struct IndexStmt
2024 {
2025         NodeTag         type;
2026         char       *idxname;            /* name of new index, or NULL for default */
2027         RangeVar   *relation;           /* relation to build index on */
2028         char       *accessMethod;       /* name of access method (eg. btree) */
2029         char       *tableSpace;         /* tablespace, or NULL for default */
2030         List       *indexParams;        /* a list of IndexElem */
2031         List       *options;            /* options from WITH clause */
2032         Node       *whereClause;        /* qualification (partial-index predicate) */
2033         List       *excludeOpNames; /* exclusion operator names, or NIL if none */
2034         Oid                     indexOid;               /* OID of an existing index, if any */
2035         Oid                     oldNode;                /* relfilenode of my former self */
2036         bool            unique;                 /* is index unique? */
2037         bool            primary;                /* is index on primary key? */
2038         bool            isconstraint;   /* is it from a CONSTRAINT clause? */
2039         bool            deferrable;             /* is the constraint DEFERRABLE? */
2040         bool            initdeferred;   /* is the constraint INITIALLY DEFERRED? */
2041         bool            concurrent;             /* should this be a concurrent index build? */
2042 } IndexStmt;
2043
2044 /* ----------------------
2045  *              Create Function Statement
2046  * ----------------------
2047  */
2048 typedef struct CreateFunctionStmt
2049 {
2050         NodeTag         type;
2051         bool            replace;                /* T => replace if already exists */
2052         List       *funcname;           /* qualified name of function to create */
2053         List       *parameters;         /* a list of FunctionParameter */
2054         TypeName   *returnType;         /* the return type */
2055         List       *options;            /* a list of DefElem */
2056         List       *withClause;         /* a list of DefElem */
2057 } CreateFunctionStmt;
2058
2059 typedef enum FunctionParameterMode
2060 {
2061         /* the assigned enum values appear in pg_proc, don't change 'em! */
2062         FUNC_PARAM_IN = 'i',            /* input only */
2063         FUNC_PARAM_OUT = 'o',           /* output only */
2064         FUNC_PARAM_INOUT = 'b',         /* both */
2065         FUNC_PARAM_VARIADIC = 'v',      /* variadic (always input) */
2066         FUNC_PARAM_TABLE = 't'          /* table function output column */
2067 } FunctionParameterMode;
2068
2069 typedef struct FunctionParameter
2070 {
2071         NodeTag         type;
2072         char       *name;                       /* parameter name, or NULL if not given */
2073         TypeName   *argType;            /* TypeName for parameter type */
2074         FunctionParameterMode mode; /* IN/OUT/etc */
2075         Node       *defexpr;            /* raw default expr, or NULL if not given */
2076 } FunctionParameter;
2077
2078 typedef struct AlterFunctionStmt
2079 {
2080         NodeTag         type;
2081         FuncWithArgs *func;                     /* name and args of function */
2082         List       *actions;            /* list of DefElem */
2083 } AlterFunctionStmt;
2084
2085 /* ----------------------
2086  *              DO Statement
2087  *
2088  * DoStmt is the raw parser output, InlineCodeBlock is the execution-time API
2089  * ----------------------
2090  */
2091 typedef struct DoStmt
2092 {
2093         NodeTag         type;
2094         List       *args;                       /* List of DefElem nodes */
2095 } DoStmt;
2096
2097 typedef struct InlineCodeBlock
2098 {
2099         NodeTag         type;
2100         char       *source_text;        /* source text of anonymous code block */
2101         Oid                     langOid;                /* OID of selected language */
2102         bool            langIsTrusted;  /* trusted property of the language */
2103 } InlineCodeBlock;
2104
2105 /* ----------------------
2106  *              Alter Object Rename Statement
2107  * ----------------------
2108  */
2109 typedef struct RenameStmt
2110 {
2111         NodeTag         type;
2112         ObjectType      renameType;             /* OBJECT_TABLE, OBJECT_COLUMN, etc */
2113         ObjectType      relationType;   /* if column name, associated relation type */
2114         RangeVar   *relation;           /* in case it's a table */
2115         List       *object;                     /* in case it's some other object */
2116         List       *objarg;                     /* argument types, if applicable */
2117         char       *subname;            /* name of contained object (column, rule,
2118                                                                  * trigger, etc) */
2119         char       *newname;            /* the new name */
2120         DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
2121         bool            missing_ok;     /* skip error if missing? */
2122 } RenameStmt;
2123
2124 /* ----------------------
2125  *              ALTER object SET SCHEMA Statement
2126  * ----------------------
2127  */
2128 typedef struct AlterObjectSchemaStmt
2129 {
2130         NodeTag         type;
2131         ObjectType objectType;          /* OBJECT_TABLE, OBJECT_TYPE, etc */
2132         RangeVar   *relation;           /* in case it's a table */
2133         List       *object;                     /* in case it's some other object */
2134         List       *objarg;                     /* argument types, if applicable */
2135         char       *addname;            /* additional name if needed */
2136         char       *newschema;          /* the new schema */
2137         bool            missing_ok;     /* skip error if missing? */
2138 } AlterObjectSchemaStmt;
2139
2140 /* ----------------------
2141  *              Alter Object Owner Statement
2142  * ----------------------
2143  */
2144 typedef struct AlterOwnerStmt
2145 {
2146         NodeTag         type;
2147         ObjectType objectType;          /* OBJECT_TABLE, OBJECT_TYPE, etc */
2148         RangeVar   *relation;           /* in case it's a table */
2149         List       *object;                     /* in case it's some other object */
2150         List       *objarg;                     /* argument types, if applicable */
2151         char       *addname;            /* additional name if needed */
2152         char       *newowner;           /* the new owner */
2153 } AlterOwnerStmt;
2154
2155
2156 /* ----------------------
2157  *              Create Rule Statement
2158  * ----------------------
2159  */
2160 typedef struct RuleStmt
2161 {
2162         NodeTag         type;
2163         RangeVar   *relation;           /* relation the rule is for */
2164         char       *rulename;           /* name of the rule */
2165         Node       *whereClause;        /* qualifications */
2166         CmdType         event;                  /* SELECT, INSERT, etc */
2167         bool            instead;                /* is a 'do instead'? */
2168         List       *actions;            /* the action statements */
2169         bool            replace;                /* OR REPLACE */
2170 } RuleStmt;
2171
2172 /* ----------------------
2173  *              Notify Statement
2174  * ----------------------
2175  */
2176 typedef struct NotifyStmt
2177 {
2178         NodeTag         type;
2179         char       *conditionname;      /* condition name to notify */
2180         char       *payload;            /* the payload string, or NULL if none */
2181 } NotifyStmt;
2182
2183 /* ----------------------
2184  *              Listen Statement
2185  * ----------------------
2186  */
2187 typedef struct ListenStmt
2188 {
2189         NodeTag         type;
2190         char       *conditionname;      /* condition name to listen on */
2191 } ListenStmt;
2192
2193 /* ----------------------
2194  *              Unlisten Statement
2195  * ----------------------
2196  */
2197 typedef struct UnlistenStmt
2198 {
2199         NodeTag         type;
2200         char       *conditionname;      /* name to unlisten on, or NULL for all */
2201 } UnlistenStmt;
2202
2203 /* ----------------------
2204  *              {Begin|Commit|Rollback} Transaction Statement
2205  * ----------------------
2206  */
2207 typedef enum TransactionStmtKind
2208 {
2209         TRANS_STMT_BEGIN,
2210         TRANS_STMT_START,                       /* semantically identical to BEGIN */
2211         TRANS_STMT_COMMIT,
2212         TRANS_STMT_ROLLBACK,
2213         TRANS_STMT_SAVEPOINT,
2214         TRANS_STMT_RELEASE,
2215         TRANS_STMT_ROLLBACK_TO,
2216         TRANS_STMT_PREPARE,
2217         TRANS_STMT_COMMIT_PREPARED,
2218         TRANS_STMT_ROLLBACK_PREPARED
2219 } TransactionStmtKind;
2220
2221 typedef struct TransactionStmt
2222 {
2223         NodeTag         type;
2224         TransactionStmtKind kind;       /* see above */
2225         List       *options;            /* for BEGIN/START and savepoint commands */
2226         char       *gid;                        /* for two-phase-commit related commands */
2227 } TransactionStmt;
2228
2229 /* ----------------------
2230  *              Create Type Statement, composite types
2231  * ----------------------
2232  */
2233 typedef struct CompositeTypeStmt
2234 {
2235         NodeTag         type;
2236         RangeVar   *typevar;            /* the composite type to be created */
2237         List       *coldeflist;         /* list of ColumnDef nodes */
2238 } CompositeTypeStmt;
2239
2240 /* ----------------------
2241  *              Create Type Statement, enum types
2242  * ----------------------
2243  */
2244 typedef struct CreateEnumStmt
2245 {
2246         NodeTag         type;
2247         List       *typeName;           /* qualified name (list of Value strings) */
2248         List       *vals;                       /* enum values (list of Value strings) */
2249 } CreateEnumStmt;
2250
2251 /* ----------------------
2252  *              Create Type Statement, range types
2253  * ----------------------
2254  */
2255 typedef struct CreateRangeStmt
2256 {
2257         NodeTag         type;
2258         List       *typeName;           /* qualified name (list of Value strings) */
2259         List       *params;                     /* range parameters (list of DefElem) */
2260 } CreateRangeStmt;
2261
2262 /* ----------------------
2263  *              Alter Type Statement, enum types
2264  * ----------------------
2265  */
2266 typedef struct AlterEnumStmt
2267 {
2268         NodeTag         type;
2269         List       *typeName;           /* qualified name (list of Value strings) */
2270         char       *newVal;                     /* new enum value's name */
2271         char       *newValNeighbor; /* neighboring enum value, if specified */
2272         bool            newValIsAfter;  /* place new enum value after neighbor? */
2273 } AlterEnumStmt;
2274
2275 /* ----------------------
2276  *              Create View Statement
2277  * ----------------------
2278  */
2279 typedef struct ViewStmt
2280 {
2281         NodeTag         type;
2282         RangeVar   *view;                       /* the view to be created */
2283         List       *aliases;            /* target column names */
2284         Node       *query;                      /* the SELECT query */
2285         bool            replace;                /* replace an existing view? */
2286         List       *options;            /* options from WITH clause */
2287 } ViewStmt;
2288
2289 /* ----------------------
2290  *              Load Statement
2291  * ----------------------
2292  */
2293 typedef struct LoadStmt
2294 {
2295         NodeTag         type;
2296         char       *filename;           /* file to load */
2297 } LoadStmt;
2298
2299 /* ----------------------
2300  *              Createdb Statement
2301  * ----------------------
2302  */
2303 typedef struct CreatedbStmt
2304 {
2305         NodeTag         type;
2306         char       *dbname;                     /* name of database to create */
2307         List       *options;            /* List of DefElem nodes */
2308 } CreatedbStmt;
2309
2310 /* ----------------------
2311  *      Alter Database
2312  * ----------------------
2313  */
2314 typedef struct AlterDatabaseStmt
2315 {
2316         NodeTag         type;
2317         char       *dbname;                     /* name of database to alter */
2318         List       *options;            /* List of DefElem nodes */
2319 } AlterDatabaseStmt;
2320
2321 typedef struct AlterDatabaseSetStmt
2322 {
2323         NodeTag         type;
2324         char       *dbname;                     /* database name */
2325         VariableSetStmt *setstmt;       /* SET or RESET subcommand */
2326 } AlterDatabaseSetStmt;
2327
2328 /* ----------------------
2329  *              Dropdb Statement
2330  * ----------------------
2331  */
2332 typedef struct DropdbStmt
2333 {
2334         NodeTag         type;
2335         char       *dbname;                     /* database to drop */
2336         bool            missing_ok;             /* skip error if db is missing? */
2337 } DropdbStmt;
2338
2339 /* ----------------------
2340  *              Cluster Statement (support pbrown's cluster index implementation)
2341  * ----------------------
2342  */
2343 typedef struct ClusterStmt
2344 {
2345         NodeTag         type;
2346         RangeVar   *relation;           /* relation being indexed, or NULL if all */
2347         char       *indexname;          /* original index defined */
2348         bool            verbose;                /* print progress info */
2349 } ClusterStmt;
2350
2351 /* ----------------------
2352  *              Vacuum and Analyze Statements
2353  *
2354  * Even though these are nominally two statements, it's convenient to use
2355  * just one node type for both.  Note that at least one of VACOPT_VACUUM
2356  * and VACOPT_ANALYZE must be set in options.  VACOPT_FREEZE is an internal
2357  * convenience for the grammar and is not examined at runtime --- the
2358  * freeze_min_age and freeze_table_age fields are what matter.
2359  * ----------------------
2360  */
2361 typedef enum VacuumOption
2362 {
2363         VACOPT_VACUUM = 1 << 0,         /* do VACUUM */
2364         VACOPT_ANALYZE = 1 << 1,        /* do ANALYZE */
2365         VACOPT_VERBOSE = 1 << 2,        /* print progress info */
2366         VACOPT_FREEZE = 1 << 3,         /* FREEZE option */
2367         VACOPT_FULL = 1 << 4,           /* FULL (non-concurrent) vacuum */
2368         VACOPT_NOWAIT = 1 << 5          /* don't wait to get lock (autovacuum only) */
2369 } VacuumOption;
2370
2371 typedef struct VacuumStmt
2372 {
2373         NodeTag         type;
2374         int                     options;                /* OR of VacuumOption flags */
2375         int                     freeze_min_age; /* min freeze age, or -1 to use default */
2376         int                     freeze_table_age;               /* age at which to scan whole table */
2377         RangeVar   *relation;           /* single table to process, or NULL */
2378         List       *va_cols;            /* list of column names, or NIL for all */
2379 } VacuumStmt;
2380
2381 /* ----------------------
2382  *              Explain Statement
2383  *
2384  * The "query" field is either a raw parse tree (SelectStmt, InsertStmt, etc)
2385  * or a Query node if parse analysis has been done.  Note that rewriting and
2386  * planning of the query are always postponed until execution of EXPLAIN.
2387  * ----------------------
2388  */
2389 typedef struct ExplainStmt
2390 {
2391         NodeTag         type;
2392         Node       *query;                      /* the query (see comments above) */
2393         List       *options;            /* list of DefElem nodes */
2394 } ExplainStmt;
2395
2396 /* ----------------------
2397  *              CREATE TABLE AS Statement (a/k/a SELECT INTO)
2398  *
2399  * A query written as CREATE TABLE AS will produce this node type natively.
2400  * A query written as SELECT ... INTO will be transformed to this form during
2401  * parse analysis.
2402  *
2403  * The "query" field is handled similarly to EXPLAIN, though note that it
2404  * can be a SELECT or an EXECUTE, but not other DML statements.
2405  * ----------------------
2406  */
2407 typedef struct CreateTableAsStmt
2408 {
2409         NodeTag         type;
2410         Node       *query;                      /* the query (see comments above) */
2411         IntoClause *into;                       /* destination table */
2412         bool            is_select_into; /* it was written as SELECT INTO */
2413 } CreateTableAsStmt;
2414
2415 /* ----------------------
2416  * Checkpoint Statement
2417  * ----------------------
2418  */
2419 typedef struct CheckPointStmt
2420 {
2421         NodeTag         type;
2422 } CheckPointStmt;
2423
2424 /* ----------------------
2425  * Discard Statement
2426  * ----------------------
2427  */
2428
2429 typedef enum DiscardMode
2430 {
2431         DISCARD_ALL,
2432         DISCARD_PLANS,
2433         DISCARD_TEMP
2434 } DiscardMode;
2435
2436 typedef struct DiscardStmt
2437 {
2438         NodeTag         type;
2439         DiscardMode target;
2440 } DiscardStmt;
2441
2442 /* ----------------------
2443  *              LOCK Statement
2444  * ----------------------
2445  */
2446 typedef struct LockStmt
2447 {
2448         NodeTag         type;
2449         List       *relations;          /* relations to lock */
2450         int                     mode;                   /* lock mode */
2451         bool            nowait;                 /* no wait mode */
2452 } LockStmt;
2453
2454 /* ----------------------
2455  *              SET CONSTRAINTS Statement
2456  * ----------------------
2457  */
2458 typedef struct ConstraintsSetStmt
2459 {
2460         NodeTag         type;
2461         List       *constraints;        /* List of names as RangeVars */
2462         bool            deferred;
2463 } ConstraintsSetStmt;
2464
2465 /* ----------------------
2466  *              REINDEX Statement
2467  * ----------------------
2468  */
2469 typedef struct ReindexStmt
2470 {
2471         NodeTag         type;
2472         ObjectType      kind;                   /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_DATABASE */
2473         RangeVar   *relation;           /* Table or index to reindex */
2474         const char *name;                       /* name of database to reindex */
2475         bool            do_system;              /* include system tables in database case */
2476         bool            do_user;                /* include user tables in database case */
2477 } ReindexStmt;
2478
2479 /* ----------------------
2480  *              CREATE CONVERSION Statement
2481  * ----------------------
2482  */
2483 typedef struct CreateConversionStmt
2484 {
2485         NodeTag         type;
2486         List       *conversion_name;    /* Name of the conversion */
2487         char       *for_encoding_name;          /* source encoding name */
2488         char       *to_encoding_name;           /* destination encoding name */
2489         List       *func_name;          /* qualified conversion function name */
2490         bool            def;                    /* is this a default conversion? */
2491 } CreateConversionStmt;
2492
2493 /* ----------------------
2494  *      CREATE CAST Statement
2495  * ----------------------
2496  */
2497 typedef struct CreateCastStmt
2498 {
2499         NodeTag         type;
2500         TypeName   *sourcetype;
2501         TypeName   *targettype;
2502         FuncWithArgs *func;
2503         CoercionContext context;
2504         bool            inout;
2505 } CreateCastStmt;
2506
2507 /* ----------------------
2508  *              PREPARE Statement
2509  * ----------------------
2510  */
2511 typedef struct PrepareStmt
2512 {
2513         NodeTag         type;
2514         char       *name;                       /* Name of plan, arbitrary */
2515         List       *argtypes;           /* Types of parameters (List of TypeName) */
2516         Node       *query;                      /* The query itself (as a raw parsetree) */
2517 } PrepareStmt;
2518
2519
2520 /* ----------------------
2521  *              EXECUTE Statement
2522  * ----------------------
2523  */
2524
2525 typedef struct ExecuteStmt
2526 {
2527         NodeTag         type;
2528         char       *name;                       /* The name of the plan to execute */
2529         List       *params;                     /* Values to assign to parameters */
2530 } ExecuteStmt;
2531
2532
2533 /* ----------------------
2534  *              DEALLOCATE Statement
2535  * ----------------------
2536  */
2537 typedef struct DeallocateStmt
2538 {
2539         NodeTag         type;
2540         char       *name;                       /* The name of the plan to remove */
2541         /* NULL means DEALLOCATE ALL */
2542 } DeallocateStmt;
2543
2544 /*
2545  *              DROP OWNED statement
2546  */
2547 typedef struct DropOwnedStmt
2548 {
2549         NodeTag         type;
2550         List       *roles;
2551         DropBehavior behavior;
2552 } DropOwnedStmt;
2553
2554 /*
2555  *              REASSIGN OWNED statement
2556  */
2557 typedef struct ReassignOwnedStmt
2558 {
2559         NodeTag         type;
2560         List       *roles;
2561         char       *newrole;
2562 } ReassignOwnedStmt;
2563
2564 /*
2565  * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
2566  */
2567 typedef struct AlterTSDictionaryStmt
2568 {
2569         NodeTag         type;
2570         List       *dictname;           /* qualified name (list of Value strings) */
2571         List       *options;            /* List of DefElem nodes */
2572 } AlterTSDictionaryStmt;
2573
2574 /*
2575  * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
2576  */
2577 typedef struct AlterTSConfigurationStmt
2578 {
2579         NodeTag         type;
2580         List       *cfgname;            /* qualified name (list of Value strings) */
2581
2582         /*
2583          * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is
2584          * NIL, but tokentype isn't, DROP MAPPING was specified.
2585          */
2586         List       *tokentype;          /* list of Value strings */
2587         List       *dicts;                      /* list of list of Value strings */
2588         bool            override;               /* if true - remove old variant */
2589         bool            replace;                /* if true - replace dictionary by another */
2590         bool            missing_ok;             /* for DROP - skip error if missing? */
2591 } AlterTSConfigurationStmt;
2592
2593 #endif   /* PARSENODES_H */