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