OSDN Git Service

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