]> granicus.if.org Git - postgresql/blob - src/include/nodes/parsenodes.h
65c3698a841995ee793c6e72c75e3eb2b9750ca3
[postgresql] / src / include / nodes / parsenodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * parsenodes.h
4  *        definitions for parse tree nodes
5  *
6  *
7  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.371 2008/08/07 01:11:51 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PARSENODES_H
15 #define PARSENODES_H
16
17 #include "nodes/primnodes.h"
18 #include "nodes/value.h"
19
20 /* Possible sources of a Query */
21 typedef enum QuerySource
22 {
23         QSRC_ORIGINAL,                          /* original parsetree (explicit query) */
24         QSRC_PARSER,                            /* added by parse analysis (now unused) */
25         QSRC_INSTEAD_RULE,                      /* added by unconditional INSTEAD rule */
26         QSRC_QUAL_INSTEAD_RULE,         /* added by conditional INSTEAD rule */
27         QSRC_NON_INSTEAD_RULE           /* added by non-INSTEAD rule */
28 } QuerySource;
29
30 /* Sort ordering options for ORDER BY and CREATE INDEX */
31 typedef enum SortByDir
32 {
33         SORTBY_DEFAULT,
34         SORTBY_ASC,
35         SORTBY_DESC,
36         SORTBY_USING                            /* not allowed in CREATE INDEX ... */
37 } SortByDir;
38
39 typedef enum SortByNulls
40 {
41         SORTBY_NULLS_DEFAULT,
42         SORTBY_NULLS_FIRST,
43         SORTBY_NULLS_LAST
44 } SortByNulls;
45
46
47 /*
48  * Grantable rights are encoded so that we can OR them together in a bitmask.
49  * The present representation of AclItem limits us to 16 distinct rights,
50  * even though AclMode is defined as uint32.  See utils/acl.h.
51  *
52  * Caution: changing these codes breaks stored ACLs, hence forces initdb.
53  */
54 typedef uint32 AclMode;                 /* a bitmask of privilege bits */
55
56 #define ACL_INSERT              (1<<0)  /* for relations */
57 #define ACL_SELECT              (1<<1)
58 #define ACL_UPDATE              (1<<2)
59 #define ACL_DELETE              (1<<3)
60 /* #define ACL_RULE             (1<<4)  unused, available */
61 #define ACL_REFERENCES  (1<<5)
62 #define ACL_TRIGGER             (1<<6)
63 #define ACL_EXECUTE             (1<<7)  /* for functions */
64 #define ACL_USAGE               (1<<8)  /* for languages and namespaces */
65 #define ACL_CREATE              (1<<9)  /* for namespaces and databases */
66 #define ACL_CREATE_TEMP (1<<10) /* for databases */
67 #define ACL_CONNECT             (1<<11) /* for databases */
68 #define N_ACL_RIGHTS    12              /* 1 plus the last 1<<x */
69 #define ACL_NO_RIGHTS   0
70 /* Currently, SELECT ... FOR UPDATE/FOR SHARE requires UPDATE privileges */
71 #define ACL_SELECT_FOR_UPDATE   ACL_UPDATE
72
73
74 /*****************************************************************************
75  *      Query Tree
76  *****************************************************************************/
77
78 /*
79  * Query -
80  *        Parse analysis turns all statements into a Query tree (via transformStmt)
81  *        for further processing by the rewriter and planner.
82  *
83  *        Utility statements (i.e. non-optimizable statements) have the
84  *        utilityStmt field set, and the Query itself is mostly dummy.
85  *        DECLARE CURSOR is a special case: it is represented like a SELECT,
86  *        but the original DeclareCursorStmt is stored in utilityStmt.
87  *
88  *        Planning converts a Query tree into a Plan tree headed by a PlannedStmt
89  *        node --- the Query structure is not used by the executor.
90  */
91 typedef struct Query
92 {
93         NodeTag         type;
94
95         CmdType         commandType;    /* select|insert|update|delete|utility */
96
97         QuerySource querySource;        /* where did I come from? */
98
99         bool            canSetTag;              /* do I set the command result tag? */
100
101         Node       *utilityStmt;        /* non-null if this is DECLARE CURSOR or a
102                                                                  * non-optimizable statement */
103
104         int                     resultRelation; /* rtable index of target relation for
105                                                                  * INSERT/UPDATE/DELETE; 0 for SELECT */
106
107         IntoClause *intoClause;         /* target for SELECT INTO / CREATE TABLE AS */
108
109         bool            hasAggs;                /* has aggregates in tlist or havingQual */
110         bool            hasSubLinks;    /* has subquery SubLink */
111         bool            hasDistinctOn;  /* distinctClause is from DISTINCT ON */
112
113         List       *rtable;                     /* list of range table entries */
114         FromExpr   *jointree;           /* table join tree (FROM and WHERE clauses) */
115
116         List       *targetList;         /* target list (of TargetEntry) */
117
118         List       *returningList;      /* return-values list (of TargetEntry) */
119
120         List       *groupClause;        /* a list of SortGroupClause's */
121
122         Node       *havingQual;         /* qualifications applied to groups */
123
124         List       *distinctClause; /* a list of SortGroupClause's */
125
126         List       *sortClause;         /* a list of SortGroupClause's */
127
128         Node       *limitOffset;        /* # of result tuples to skip (int8 expr) */
129         Node       *limitCount;         /* # of result tuples to return (int8 expr) */
130
131         List       *rowMarks;           /* a list of RowMarkClause's */
132
133         Node       *setOperations;      /* set-operation tree if this is top level of
134                                                                  * a UNION/INTERSECT/EXCEPT query */
135 } Query;
136
137
138 /****************************************************************************
139  *      Supporting data structures for Parse Trees
140  *
141  *      Most of these node types appear in raw parsetrees output by the grammar,
142  *      and get transformed to something else by the analyzer.  A few of them
143  *      are used as-is in transformed querytrees.
144  *
145  *      Many of the node types used in raw parsetrees include a "location" field.
146  *      This is a byte (not character) offset in the original source text, to be
147  *      used for positioning an error cursor when there is an analysis-time
148  *      error related to the node.
149  ****************************************************************************/
150
151 /*
152  * TypeName - specifies a type in definitions
153  *
154  * For TypeName structures generated internally, it is often easier to
155  * specify the type by OID than by name.  If "names" is NIL then the
156  * actual type OID is given by typeid, otherwise typeid is unused.
157  * Similarly, if "typmods" is NIL then the actual typmod is expected to
158  * be prespecified in typemod, otherwise typemod is unused.
159  *
160  * If pct_type is TRUE, then names is actually a field name and we look up
161  * the type of that field.      Otherwise (the normal case), names is a type
162  * name possibly qualified with schema and database name.
163  */
164 typedef struct TypeName
165 {
166         NodeTag         type;
167         List       *names;                      /* qualified name (list of Value strings) */
168         Oid                     typeid;                 /* type identified by OID */
169         bool            setof;                  /* is a set? */
170         bool            pct_type;               /* %TYPE specified? */
171         List       *typmods;            /* type modifier expression(s) */
172         int32           typemod;                /* prespecified type modifier */
173         List       *arrayBounds;        /* array bounds */
174         int                     location;               /* token location, or -1 if unknown */
175 } TypeName;
176
177 /*
178  * ColumnRef - specifies a reference to a column, or possibly a whole tuple
179  *
180  *              The "fields" list must be nonempty; its last component may be "*"
181  *              instead of a regular field name.
182  *
183  * Note: any array subscripting or selection of fields from composite columns
184  * is represented by an A_Indirection node above the ColumnRef.  However,
185  * for simplicity in the normal case, initial field selection from a table
186  * name is represented within ColumnRef and not by adding A_Indirection.
187  */
188 typedef struct ColumnRef
189 {
190         NodeTag         type;
191         List       *fields;                     /* field names (list of Value strings) */
192         int                     location;               /* token location, or -1 if unknown */
193 } ColumnRef;
194
195 /*
196  * ParamRef - specifies a $n parameter reference
197  */
198 typedef struct ParamRef
199 {
200         NodeTag         type;
201         int                     number;                 /* the number of the parameter */
202 } ParamRef;
203
204 /*
205  * A_Expr - infix, prefix, and postfix expressions
206  */
207 typedef enum A_Expr_Kind
208 {
209         AEXPR_OP,                                       /* normal operator */
210         AEXPR_AND,                                      /* booleans - name field is unused */
211         AEXPR_OR,
212         AEXPR_NOT,
213         AEXPR_OP_ANY,                           /* scalar op ANY (array) */
214         AEXPR_OP_ALL,                           /* scalar op ALL (array) */
215         AEXPR_DISTINCT,                         /* IS DISTINCT FROM - name must be "=" */
216         AEXPR_NULLIF,                           /* NULLIF - name must be "=" */
217         AEXPR_OF,                                       /* IS [NOT] OF - name must be "=" or "<>" */
218         AEXPR_IN                                        /* [NOT] IN - name must be "=" or "<>" */
219 } A_Expr_Kind;
220
221 typedef struct A_Expr
222 {
223         NodeTag         type;
224         A_Expr_Kind kind;                       /* see above */
225         List       *name;                       /* possibly-qualified name of operator */
226         Node       *lexpr;                      /* left argument, or NULL if none */
227         Node       *rexpr;                      /* right argument, or NULL if none */
228         int                     location;               /* token location, or -1 if unknown */
229 } A_Expr;
230
231 /*
232  * A_Const - a literal constant
233  */
234 typedef struct A_Const
235 {
236         NodeTag         type;
237         Value           val;                    /* value (includes type info, see value.h) */
238 } A_Const;
239
240 /*
241  * TypeCast - a CAST expression
242  */
243 typedef struct TypeCast
244 {
245         NodeTag         type;
246         Node       *arg;                        /* the expression being casted */
247         TypeName   *typename;           /* the target type */
248 } TypeCast;
249
250 /*
251  * FuncCall - a function or aggregate invocation
252  *
253  * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
254  * indicates we saw 'foo(DISTINCT ...)'.  In either case, the construct
255  * *must* be an aggregate call.  Otherwise, it might be either an
256  * aggregate or some other kind of function.
257  */
258 typedef struct FuncCall
259 {
260         NodeTag         type;
261         List       *funcname;           /* qualified name of function */
262         List       *args;                       /* the arguments (list of exprs) */
263         bool            agg_star;               /* argument was really '*' */
264         bool            agg_distinct;   /* arguments were labeled DISTINCT */
265         bool            func_variadic;  /* last argument was labeled VARIADIC */
266         int                     location;               /* token location, or -1 if unknown */
267 } FuncCall;
268
269 /*
270  * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
271  */
272 typedef struct A_Indices
273 {
274         NodeTag         type;
275         Node       *lidx;                       /* could be NULL */
276         Node       *uidx;
277 } A_Indices;
278
279 /*
280  * A_Indirection - select a field and/or array element from an expression
281  *
282  * The indirection list can contain both A_Indices nodes (representing
283  * subscripting) and string Value nodes (representing field selection
284  * --- the string value is the name of the field to select).  For example,
285  * a complex selection operation like
286  *                              (foo).field1[42][7].field2
287  * would be represented with a single A_Indirection node having a 4-element
288  * indirection list.
289  *
290  * Note: as of Postgres 8.0, we don't support arrays of composite values,
291  * so cases in which a field select follows a subscript aren't actually
292  * semantically legal.  However the parser is prepared to handle such.
293  */
294 typedef struct A_Indirection
295 {
296         NodeTag         type;
297         Node       *arg;                        /* the thing being selected from */
298         List       *indirection;        /* subscripts and/or field names */
299 } A_Indirection;
300
301 /*
302  * A_ArrayExpr - an ARRAY[] construct
303  */
304 typedef struct A_ArrayExpr
305 {
306         NodeTag         type;
307         List       *elements;           /* array element expressions */
308 } A_ArrayExpr;
309
310 /*
311  * ResTarget -
312  *        result target (used in target list of pre-transformed parse trees)
313  *
314  * In a SELECT target list, 'name' is the column label from an
315  * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
316  * value expression itself.  The 'indirection' field is not used.
317  *
318  * INSERT uses ResTarget in its target-column-names list.  Here, 'name' is
319  * the name of the destination column, 'indirection' stores any subscripts
320  * attached to the destination, and 'val' is not used.
321  *
322  * In an UPDATE target list, 'name' is the name of the destination column,
323  * 'indirection' stores any subscripts attached to the destination, and
324  * 'val' is the expression to assign.
325  *
326  * See A_Indirection for more info about what can appear in 'indirection'.
327  */
328 typedef struct ResTarget
329 {
330         NodeTag         type;
331         char       *name;                       /* column name or NULL */
332         List       *indirection;        /* subscripts and field names, or NIL */
333         Node       *val;                        /* the value expression to compute or assign */
334         int                     location;               /* token location, or -1 if unknown */
335 } ResTarget;
336
337 /*
338  * SortBy - for ORDER BY clause
339  */
340 typedef struct SortBy
341 {
342         NodeTag         type;
343         SortByDir       sortby_dir;             /* ASC/DESC/USING */
344         SortByNulls sortby_nulls;       /* NULLS FIRST/LAST */
345         List       *useOp;                      /* name of op to use, if SORTBY_USING */
346         Node       *node;                       /* expression to sort on */
347 } SortBy;
348
349 /*
350  * RangeSubselect - subquery appearing in a FROM clause
351  */
352 typedef struct RangeSubselect
353 {
354         NodeTag         type;
355         Node       *subquery;           /* the untransformed sub-select clause */
356         Alias      *alias;                      /* table alias & optional column aliases */
357 } RangeSubselect;
358
359 /*
360  * RangeFunction - function call appearing in a FROM clause
361  */
362 typedef struct RangeFunction
363 {
364         NodeTag         type;
365         Node       *funccallnode;       /* untransformed function call tree */
366         Alias      *alias;                      /* table alias & optional column aliases */
367         List       *coldeflist;         /* list of ColumnDef nodes to describe result
368                                                                  * of function returning RECORD */
369 } RangeFunction;
370
371 /*
372  * ColumnDef - column definition (used in various creates)
373  *
374  * If the column has a default value, we may have the value expression
375  * in either "raw" form (an untransformed parse tree) or "cooked" form
376  * (the nodeToString representation of an executable expression tree),
377  * depending on how this ColumnDef node was created (by parsing, or by
378  * inheritance from an existing relation).      We should never have both
379  * in the same node!
380  *
381  * The constraints list may contain a CONSTR_DEFAULT item in a raw
382  * parsetree produced by gram.y, but transformCreateStmt will remove
383  * the item and set raw_default instead.  CONSTR_DEFAULT items
384  * should not appear in any subsequent processing.
385  */
386 typedef struct ColumnDef
387 {
388         NodeTag         type;
389         char       *colname;            /* name of column */
390         TypeName   *typename;           /* type of column */
391         int                     inhcount;               /* number of times column is inherited */
392         bool            is_local;               /* column has local (non-inherited) def'n */
393         bool            is_not_null;    /* NOT NULL constraint specified? */
394         Node       *raw_default;        /* default value (untransformed parse tree) */
395         char       *cooked_default; /* nodeToString representation */
396         List       *constraints;        /* other constraints on column */
397 } ColumnDef;
398
399 /*
400  * inhRelation - Relations a CREATE TABLE is to inherit attributes of
401  */
402 typedef struct InhRelation
403 {
404         NodeTag         type;
405         RangeVar   *relation;
406         List       *options;            /* integer List of CreateStmtLikeOption */
407 } InhRelation;
408
409 typedef enum CreateStmtLikeOption
410 {
411         CREATE_TABLE_LIKE_INCLUDING_DEFAULTS,
412         CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS,
413         CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS,
414         CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS,
415         CREATE_TABLE_LIKE_INCLUDING_INDEXES,
416         CREATE_TABLE_LIKE_EXCLUDING_INDEXES
417 } CreateStmtLikeOption;
418
419 /*
420  * IndexElem - index parameters (used in CREATE INDEX)
421  *
422  * For a plain index attribute, 'name' is the name of the table column to
423  * index, and 'expr' is NULL.  For an index expression, 'name' is NULL and
424  * 'expr' is the expression tree.
425  */
426 typedef struct IndexElem
427 {
428         NodeTag         type;
429         char       *name;                       /* name of attribute to index, or NULL */
430         Node       *expr;                       /* expression to index, or NULL */
431         List       *opclass;            /* name of desired opclass; NIL = default */
432         SortByDir       ordering;               /* ASC/DESC/default */
433         SortByNulls nulls_ordering; /* FIRST/LAST/default */
434 } IndexElem;
435
436 /*
437  * DefElem -
438  *        a definition (used in definition lists in the form of defname = arg)
439  */
440 typedef struct DefElem
441 {
442         NodeTag         type;
443         char       *defname;
444         Node       *arg;                        /* a (Value *) or a (TypeName *) */
445 } DefElem;
446
447 /*
448  * LockingClause - raw representation of FOR UPDATE/SHARE options
449  *
450  * Note: lockedRels == NIL means "all relations in query".      Otherwise it
451  * is a list of String nodes giving relation eref names.
452  */
453 typedef struct LockingClause
454 {
455         NodeTag         type;
456         List       *lockedRels;         /* FOR UPDATE or FOR SHARE relations */
457         bool            forUpdate;              /* true = FOR UPDATE, false = FOR SHARE */
458         bool            noWait;                 /* NOWAIT option */
459 } LockingClause;
460
461 /*
462  * XMLSERIALIZE
463  */
464 typedef struct XmlSerialize
465 {
466         NodeTag         type;
467         XmlOptionType xmloption;
468         Node       *expr;
469         TypeName   *typename;
470 } XmlSerialize;
471
472
473 /****************************************************************************
474  *      Nodes for a Query tree
475  ****************************************************************************/
476
477 /*--------------------
478  * RangeTblEntry -
479  *        A range table is a List of RangeTblEntry nodes.
480  *
481  *        A range table entry may represent a plain relation, a sub-select in
482  *        FROM, or the result of a JOIN clause.  (Only explicit JOIN syntax
483  *        produces an RTE, not the implicit join resulting from multiple FROM
484  *        items.  This is because we only need the RTE to deal with SQL features
485  *        like outer joins and join-output-column aliasing.)  Other special
486  *        RTE types also exist, as indicated by RTEKind.
487  *
488  *        alias is an Alias node representing the AS alias-clause attached to the
489  *        FROM expression, or NULL if no clause.
490  *
491  *        eref is the table reference name and column reference names (either
492  *        real or aliases).  Note that system columns (OID etc) are not included
493  *        in the column list.
494  *        eref->aliasname is required to be present, and should generally be used
495  *        to identify the RTE for error messages etc.
496  *
497  *        In RELATION RTEs, the colnames in both alias and eref are indexed by
498  *        physical attribute number; this means there must be colname entries for
499  *        dropped columns.      When building an RTE we insert empty strings ("") for
500  *        dropped columns.      Note however that a stored rule may have nonempty
501  *        colnames for columns dropped since the rule was created (and for that
502  *        matter the colnames might be out of date due to column renamings).
503  *        The same comments apply to FUNCTION RTEs when the function's return type
504  *        is a named composite type.
505  *
506  *        In JOIN RTEs, the colnames in both alias and eref are one-to-one with
507  *        joinaliasvars entries.  A JOIN RTE will omit columns of its inputs when
508  *        those columns are known to be dropped at parse time.  Again, however,
509  *        a stored rule might contain entries for columns dropped since the rule
510  *        was created.  (This is only possible for columns not actually referenced
511  *        in the rule.)  When loading a stored rule, we replace the joinaliasvars
512  *        items for any such columns with NULL Consts.  (We can't simply delete
513  *        them from the joinaliasvars list, because that would affect the attnums
514  *        of Vars referencing the rest of the list.)
515  *
516  *        inh is TRUE for relation references that should be expanded to include
517  *        inheritance children, if the rel has any.  This *must* be FALSE for
518  *        RTEs other than RTE_RELATION entries.
519  *
520  *        inFromCl marks those range variables that are listed in the FROM clause.
521  *        It's false for RTEs that are added to a query behind the scenes, such
522  *        as the NEW and OLD variables for a rule, or the subqueries of a UNION.
523  *        This flag is not used anymore during parsing, since the parser now uses
524  *        a separate "namespace" data structure to control visibility, but it is
525  *        needed by ruleutils.c to determine whether RTEs should be shown in
526  *        decompiled queries.
527  *
528  *        requiredPerms and checkAsUser specify run-time access permissions
529  *        checks to be performed at query startup.      The user must have *all*
530  *        of the permissions that are OR'd together in requiredPerms (zero
531  *        indicates no permissions checking).  If checkAsUser is not zero,
532  *        then do the permissions checks using the access rights of that user,
533  *        not the current effective user ID.  (This allows rules to act as
534  *        setuid gateways.)
535  *--------------------
536  */
537 typedef enum RTEKind
538 {
539         RTE_RELATION,                           /* ordinary relation reference */
540         RTE_SUBQUERY,                           /* subquery in FROM */
541         RTE_JOIN,                                       /* join */
542         RTE_SPECIAL,                            /* special rule relation (NEW or OLD) */
543         RTE_FUNCTION,                           /* function in FROM */
544         RTE_VALUES                                      /* VALUES (<exprlist>), (<exprlist>), ... */
545 } RTEKind;
546
547 typedef struct RangeTblEntry
548 {
549         NodeTag         type;
550
551         RTEKind         rtekind;                /* see above */
552
553         /*
554          * XXX the fields applicable to only some rte kinds should be merged into
555          * a union.  I didn't do this yet because the diffs would impact a lot of
556          * code that is being actively worked on.  FIXME later.
557          */
558
559         /*
560          * Fields valid for a plain relation RTE (else zero):
561          */
562         Oid                     relid;                  /* OID of the relation */
563
564         /*
565          * Fields valid for a subquery RTE (else NULL):
566          */
567         Query      *subquery;           /* the sub-query */
568
569         /*
570          * Fields valid for a function RTE (else NULL):
571          *
572          * If the function returns RECORD, funccoltypes lists the column types
573          * declared in the RTE's column type specification, and funccoltypmods
574          * lists their declared typmods.  Otherwise, both fields are NIL.
575          */
576         Node       *funcexpr;           /* expression tree for func call */
577         List       *funccoltypes;       /* OID list of column type OIDs */
578         List       *funccoltypmods; /* integer list of column typmods */
579
580         /*
581          * Fields valid for a values RTE (else NIL):
582          */
583         List       *values_lists;       /* list of expression lists */
584
585         /*
586          * Fields valid for a join RTE (else NULL/zero):
587          *
588          * joinaliasvars is a list of Vars or COALESCE expressions corresponding
589          * to the columns of the join result.  An alias Var referencing column K
590          * of the join result can be replaced by the K'th element of joinaliasvars
591          * --- but to simplify the task of reverse-listing aliases correctly, we
592          * do not do that until planning time.  In a Query loaded from a stored
593          * rule, it is also possible for joinaliasvars items to be NULL Consts,
594          * denoting columns dropped since the rule was made.
595          */
596         JoinType        jointype;               /* type of join */
597         List       *joinaliasvars;      /* list of alias-var expansions */
598
599         /*
600          * Fields valid in all RTEs:
601          */
602         Alias      *alias;                      /* user-written alias clause, if any */
603         Alias      *eref;                       /* expanded reference names */
604         bool            inh;                    /* inheritance requested? */
605         bool            inFromCl;               /* present in FROM clause? */
606         AclMode         requiredPerms;  /* bitmask of required access permissions */
607         Oid                     checkAsUser;    /* if valid, check access as this role */
608 } RangeTblEntry;
609
610 /*
611  * SortGroupClause -
612  *         representation of ORDER BY, GROUP BY, DISTINCT, DISTINCT ON items
613  *
614  * You might think that ORDER BY is only interested in defining ordering,
615  * and GROUP/DISTINCT are only interested in defining equality.  However,
616  * one way to implement grouping is to sort and then apply a "uniq"-like
617  * filter.  So it's also interesting to keep track of possible sort operators
618  * for GROUP/DISTINCT, and in particular to try to sort for the grouping
619  * in a way that will also yield a requested ORDER BY ordering.  So we need
620  * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates
621  * the decision to give them the same representation.
622  *
623  * tleSortGroupRef must match ressortgroupref of exactly one entry of the
624  *              query's targetlist; that is the expression to be sorted or grouped by.
625  * eqop is the OID of the equality operator.
626  * sortop is the OID of the ordering operator (a "<" or ">" operator),
627  *              or InvalidOid if not available.
628  * nulls_first means about what you'd expect.  If sortop is InvalidOid
629  *              then nulls_first is meaningless and should be set to false.
630  *
631  * In an ORDER BY item, all fields must be valid.  (The eqop isn't essential
632  * here, but it's cheap to get it along with the sortop, and requiring it
633  * to be valid eases comparisons to grouping items.)
634  *
635  * In a grouping item, eqop must be valid.  If the eqop is a btree equality
636  * operator, then sortop should be set to a compatible ordering operator.
637  * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that
638  * the query presents for the same tlist item.  If there is none, we just
639  * use the default ordering op for the datatype.
640  *
641  * If the tlist item's type has a hash opclass but no btree opclass, then
642  * we will set eqop to the hash equality operator, sortop to InvalidOid,
643  * and nulls_first to false.  A grouping item of this kind can only be
644  * implemented by hashing, and of course it'll never match an ORDER BY item.
645  *
646  * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses.
647  * In SELECT DISTINCT, the distinctClause list is as long or longer than the
648  * sortClause list, while in SELECT DISTINCT ON it's typically shorter.
649  * The two lists must match up to the end of the shorter one --- the parser
650  * rearranges the distinctClause if necessary to make this true.  (This
651  * restriction ensures that only one sort step is needed to both satisfy the
652  * ORDER BY and set up for the Unique step.  This is semantically necessary
653  * for DISTINCT ON, and presents no real drawback for DISTINCT.)
654  */
655 typedef struct SortGroupClause
656 {
657         NodeTag         type;
658         Index           tleSortGroupRef;        /* reference into targetlist */
659         Oid                     eqop;                           /* the equality operator ('=' op) */
660         Oid                     sortop;                         /* the ordering operator ('<' op), or 0 */
661         bool            nulls_first;            /* do NULLs come before normal values? */
662 } SortGroupClause;
663
664 /*
665  * RowMarkClause -
666  *         representation of FOR UPDATE/SHARE clauses
667  *
668  * We create a separate RowMarkClause node for each target relation
669  */
670 typedef struct RowMarkClause
671 {
672         NodeTag         type;
673         Index           rti;                    /* range table index of target relation */
674         bool            forUpdate;              /* true = FOR UPDATE, false = FOR SHARE */
675         bool            noWait;                 /* NOWAIT option */
676 } RowMarkClause;
677
678 /*****************************************************************************
679  *              Optimizable Statements
680  *****************************************************************************/
681
682 /* ----------------------
683  *              Insert Statement
684  *
685  * The source expression is represented by SelectStmt for both the
686  * SELECT and VALUES cases.  If selectStmt is NULL, then the query
687  * is INSERT ... DEFAULT VALUES.
688  * ----------------------
689  */
690 typedef struct InsertStmt
691 {
692         NodeTag         type;
693         RangeVar   *relation;           /* relation to insert into */
694         List       *cols;                       /* optional: names of the target columns */
695         Node       *selectStmt;         /* the source SELECT/VALUES, or NULL */
696         List       *returningList;      /* list of expressions to return */
697 } InsertStmt;
698
699 /* ----------------------
700  *              Delete Statement
701  * ----------------------
702  */
703 typedef struct DeleteStmt
704 {
705         NodeTag         type;
706         RangeVar   *relation;           /* relation to delete from */
707         List       *usingClause;        /* optional using clause for more tables */
708         Node       *whereClause;        /* qualifications */
709         List       *returningList;      /* list of expressions to return */
710 } DeleteStmt;
711
712 /* ----------------------
713  *              Update Statement
714  * ----------------------
715  */
716 typedef struct UpdateStmt
717 {
718         NodeTag         type;
719         RangeVar   *relation;           /* relation to update */
720         List       *targetList;         /* the target list (of ResTarget) */
721         Node       *whereClause;        /* qualifications */
722         List       *fromClause;         /* optional from clause for more tables */
723         List       *returningList;      /* list of expressions to return */
724 } UpdateStmt;
725
726 /* ----------------------
727  *              Select Statement
728  *
729  * A "simple" SELECT is represented in the output of gram.y by a single
730  * SelectStmt node; so is a VALUES construct.  A query containing set
731  * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
732  * nodes, in which the leaf nodes are component SELECTs and the internal nodes
733  * represent UNION, INTERSECT, or EXCEPT operators.  Using the same node
734  * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
735  * LIMIT, etc, clause values into a SELECT statement without worrying
736  * whether it is a simple or compound SELECT.
737  * ----------------------
738  */
739 typedef enum SetOperation
740 {
741         SETOP_NONE = 0,
742         SETOP_UNION,
743         SETOP_INTERSECT,
744         SETOP_EXCEPT
745 } SetOperation;
746
747 typedef struct SelectStmt
748 {
749         NodeTag         type;
750
751         /*
752          * These fields are used only in "leaf" SelectStmts.
753          */
754         List       *distinctClause; /* NULL, list of DISTINCT ON exprs, or
755                                                                  * lcons(NIL,NIL) for all (SELECT DISTINCT) */
756         IntoClause *intoClause;         /* target for SELECT INTO / CREATE TABLE AS */
757         List       *targetList;         /* the target list (of ResTarget) */
758         List       *fromClause;         /* the FROM clause */
759         Node       *whereClause;        /* WHERE qualification */
760         List       *groupClause;        /* GROUP BY clauses */
761         Node       *havingClause;       /* HAVING conditional-expression */
762
763         /*
764          * In a "leaf" node representing a VALUES list, the above fields are all
765          * null, and instead this field is set.  Note that the elements of the
766          * sublists are just expressions, without ResTarget decoration. Also note
767          * that a list element can be DEFAULT (represented as a SetToDefault
768          * node), regardless of the context of the VALUES list. It's up to parse
769          * analysis to reject that where not valid.
770          */
771         List       *valuesLists;        /* untransformed list of expression lists */
772
773         /*
774          * These fields are used in both "leaf" SelectStmts and upper-level
775          * SelectStmts.
776          */
777         List       *sortClause;         /* sort clause (a list of SortBy's) */
778         Node       *limitOffset;        /* # of result tuples to skip */
779         Node       *limitCount;         /* # of result tuples to return */
780         List       *lockingClause;      /* FOR UPDATE (list of LockingClause's) */
781
782         /*
783          * These fields are used only in upper-level SelectStmts.
784          */
785         SetOperation op;                        /* type of set op */
786         bool            all;                    /* ALL specified? */
787         struct SelectStmt *larg;        /* left child */
788         struct SelectStmt *rarg;        /* right child */
789         /* Eventually add fields for CORRESPONDING spec here */
790 } SelectStmt;
791
792
793 /* ----------------------
794  *              Set Operation node for post-analysis query trees
795  *
796  * After parse analysis, a SELECT with set operations is represented by a
797  * top-level Query node containing the leaf SELECTs as subqueries in its
798  * range table.  Its setOperations field shows the tree of set operations,
799  * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
800  * nodes replaced by SetOperationStmt nodes.  Information about the output
801  * column types is added, too.  (Note that the child nodes do not necessarily
802  * produce these types directly, but we've checked that their output types
803  * can be coerced to the output column type.)  Also, if it's not UNION ALL,
804  * information about the types' sort/group semantics is provided in the form
805  * of a SortGroupClause list (same representation as, eg, DISTINCT).
806  * ----------------------
807  */
808 typedef struct SetOperationStmt
809 {
810         NodeTag         type;
811         SetOperation op;                        /* type of set op */
812         bool            all;                    /* ALL specified? */
813         Node       *larg;                       /* left child */
814         Node       *rarg;                       /* right child */
815         /* Eventually add fields for CORRESPONDING spec here */
816
817         /* Fields derived during parse analysis: */
818         List       *colTypes;           /* OID list of output column type OIDs */
819         List       *colTypmods;         /* integer list of output column typmods */
820         List       *groupClauses;       /* a list of SortGroupClause's */
821         /* groupClauses is NIL if UNION ALL, but must be set otherwise */
822 } SetOperationStmt;
823
824
825 /*****************************************************************************
826  *              Other Statements (no optimizations required)
827  *
828  *              These are not touched by parser/analyze.c except to put them into
829  *              the utilityStmt field of a Query.  This is eventually passed to
830  *              ProcessUtility (by-passing rewriting and planning).  Some of the
831  *              statements do need attention from parse analysis, and this is
832  *              done by routines in parser/parse_utilcmd.c after ProcessUtility
833  *              receives the command for execution.
834  *****************************************************************************/
835
836 /*
837  * When a command can act on several kinds of objects with only one
838  * parse structure required, use these constants to designate the
839  * object type.
840  */
841
842 typedef enum ObjectType
843 {
844         OBJECT_AGGREGATE,
845         OBJECT_CAST,
846         OBJECT_COLUMN,
847         OBJECT_CONSTRAINT,
848         OBJECT_CONVERSION,
849         OBJECT_DATABASE,
850         OBJECT_DOMAIN,
851         OBJECT_FUNCTION,
852         OBJECT_INDEX,
853         OBJECT_LANGUAGE,
854         OBJECT_LARGEOBJECT,
855         OBJECT_OPCLASS,
856         OBJECT_OPERATOR,
857         OBJECT_OPFAMILY,
858         OBJECT_ROLE,
859         OBJECT_RULE,
860         OBJECT_SCHEMA,
861         OBJECT_SEQUENCE,
862         OBJECT_TABLE,
863         OBJECT_TABLESPACE,
864         OBJECT_TRIGGER,
865         OBJECT_TSCONFIGURATION,
866         OBJECT_TSDICTIONARY,
867         OBJECT_TSPARSER,
868         OBJECT_TSTEMPLATE,
869         OBJECT_TYPE,
870         OBJECT_VIEW
871 } ObjectType;
872
873 /* ----------------------
874  *              Create Schema Statement
875  *
876  * NOTE: the schemaElts list contains raw parsetrees for component statements
877  * of the schema, such as CREATE TABLE, GRANT, etc.  These are analyzed and
878  * executed after the schema itself is created.
879  * ----------------------
880  */
881 typedef struct CreateSchemaStmt
882 {
883         NodeTag         type;
884         char       *schemaname;         /* the name of the schema to create */
885         char       *authid;                     /* the owner of the created schema */
886         List       *schemaElts;         /* schema components (list of parsenodes) */
887 } CreateSchemaStmt;
888
889 typedef enum DropBehavior
890 {
891         DROP_RESTRICT,                          /* drop fails if any dependent objects */
892         DROP_CASCADE                            /* remove dependent objects too */
893 } DropBehavior;
894
895 /* ----------------------
896  *      Alter Table
897  * ----------------------
898  */
899 typedef struct AlterTableStmt
900 {
901         NodeTag         type;
902         RangeVar   *relation;           /* table to work on */
903         List       *cmds;                       /* list of subcommands */
904         ObjectType      relkind;                /* type of object */
905 } AlterTableStmt;
906
907 typedef enum AlterTableType
908 {
909         AT_AddColumn,                           /* add column */
910         AT_ColumnDefault,                       /* alter column default */
911         AT_DropNotNull,                         /* alter column drop not null */
912         AT_SetNotNull,                          /* alter column set not null */
913         AT_SetStatistics,                       /* alter column statistics */
914         AT_SetStorage,                          /* alter column storage */
915         AT_DropColumn,                          /* drop column */
916         AT_DropColumnRecurse,           /* internal to commands/tablecmds.c */
917         AT_AddIndex,                            /* add index */
918         AT_ReAddIndex,                          /* internal to commands/tablecmds.c */
919         AT_AddConstraint,                       /* add constraint */
920         AT_AddConstraintRecurse,        /* internal to commands/tablecmds.c */
921         AT_ProcessedConstraint,         /* pre-processed add constraint (local in
922                                                                  * parser/parse_utilcmd.c) */
923         AT_DropConstraint,                      /* drop constraint */
924         AT_DropConstraintRecurse,       /* internal to commands/tablecmds.c */
925         AT_AlterColumnType,                     /* alter column type */
926         AT_ChangeOwner,                         /* change owner */
927         AT_ClusterOn,                           /* CLUSTER ON */
928         AT_DropCluster,                         /* SET WITHOUT CLUSTER */
929         AT_DropOids,                            /* SET WITHOUT OIDS */
930         AT_SetTableSpace,                       /* SET TABLESPACE */
931         AT_SetRelOptions,                       /* SET (...) -- AM specific parameters */
932         AT_ResetRelOptions,                     /* RESET (...) -- AM specific parameters */
933         AT_EnableTrig,                          /* ENABLE TRIGGER name */
934         AT_EnableAlwaysTrig,            /* ENABLE ALWAYS TRIGGER name */
935         AT_EnableReplicaTrig,           /* ENABLE REPLICA TRIGGER name */
936         AT_DisableTrig,                         /* DISABLE TRIGGER name */
937         AT_EnableTrigAll,                       /* ENABLE TRIGGER ALL */
938         AT_DisableTrigAll,                      /* DISABLE TRIGGER ALL */
939         AT_EnableTrigUser,                      /* ENABLE TRIGGER USER */
940         AT_DisableTrigUser,                     /* DISABLE TRIGGER USER */
941         AT_EnableRule,                          /* ENABLE RULE name */
942         AT_EnableAlwaysRule,            /* ENABLE ALWAYS RULE name */
943         AT_EnableReplicaRule,           /* ENABLE REPLICA RULE name */
944         AT_DisableRule,                         /* DISABLE RULE name */
945         AT_AddInherit,                          /* INHERIT parent */
946         AT_DropInherit                          /* NO INHERIT parent */
947 } AlterTableType;
948
949 typedef struct AlterTableCmd    /* one subcommand of an ALTER TABLE */
950 {
951         NodeTag         type;
952         AlterTableType subtype;         /* Type of table alteration to apply */
953         char       *name;                       /* column, constraint, or trigger to act on,
954                                                                  * or new owner or tablespace */
955         Node       *def;                        /* definition of new column, column type,
956                                                                  * index, constraint, or parent table */
957         Node       *transform;          /* transformation expr for ALTER TYPE */
958         DropBehavior behavior;          /* RESTRICT or CASCADE for DROP cases */
959 } AlterTableCmd;
960
961
962 /* ----------------------
963  *      Alter Domain
964  *
965  * The fields are used in different ways by the different variants of
966  * this command.
967  * ----------------------
968  */
969 typedef struct AlterDomainStmt
970 {
971         NodeTag         type;
972         char            subtype;                /*------------
973                                                                  *      T = alter column default
974                                                                  *      N = alter column drop not null
975                                                                  *      O = alter column set not null
976                                                                  *      C = add constraint
977                                                                  *      X = drop constraint
978                                                                  *------------
979                                                                  */
980         List       *typename;           /* domain to work on */
981         char       *name;                       /* column or constraint name to act on */
982         Node       *def;                        /* definition of default or constraint */
983         DropBehavior behavior;          /* RESTRICT or CASCADE for DROP cases */
984 } AlterDomainStmt;
985
986
987 /* ----------------------
988  *              Grant|Revoke Statement
989  * ----------------------
990  */
991 typedef enum GrantObjectType
992 {
993         ACL_OBJECT_RELATION,            /* table, view */
994         ACL_OBJECT_SEQUENCE,            /* sequence */
995         ACL_OBJECT_DATABASE,            /* database */
996         ACL_OBJECT_FUNCTION,            /* function */
997         ACL_OBJECT_LANGUAGE,            /* procedural language */
998         ACL_OBJECT_NAMESPACE,           /* namespace */
999         ACL_OBJECT_TABLESPACE           /* tablespace */
1000 } GrantObjectType;
1001
1002 typedef struct GrantStmt
1003 {
1004         NodeTag         type;
1005         bool            is_grant;               /* true = GRANT, false = REVOKE */
1006         GrantObjectType objtype;        /* kind of object being operated on */
1007         List       *objects;            /* list of RangeVar nodes, FuncWithArgs nodes,
1008                                                                  * or plain names (as Value strings) */
1009         List       *privileges;         /* list of privilege names (as Strings) */
1010         /* privileges == NIL denotes "all privileges" */
1011         List       *grantees;           /* list of PrivGrantee nodes */
1012         bool            grant_option;   /* grant or revoke grant option */
1013         DropBehavior behavior;          /* drop behavior (for REVOKE) */
1014 } GrantStmt;
1015
1016 typedef struct PrivGrantee
1017 {
1018         NodeTag         type;
1019         char       *rolname;            /* if NULL then PUBLIC */
1020 } PrivGrantee;
1021
1022 /*
1023  * Note: FuncWithArgs carries only the types of the input parameters of the
1024  * function.  So it is sufficient to identify an existing function, but it
1025  * is not enough info to define a function nor to call it.
1026  */
1027 typedef struct FuncWithArgs
1028 {
1029         NodeTag         type;
1030         List       *funcname;           /* qualified name of function */
1031         List       *funcargs;           /* list of Typename nodes */
1032 } FuncWithArgs;
1033
1034 /* This is only used internally in gram.y. */
1035 typedef struct PrivTarget
1036 {
1037         NodeTag         type;
1038         GrantObjectType objtype;
1039         List       *objs;
1040 } PrivTarget;
1041
1042 /* ----------------------
1043  *              Grant/Revoke Role Statement
1044  *
1045  * Note: the lists of roles are lists of names, as Value strings
1046  * ----------------------
1047  */
1048 typedef struct GrantRoleStmt
1049 {
1050         NodeTag         type;
1051         List       *granted_roles;      /* list of roles to be granted/revoked */
1052         List       *grantee_roles;      /* list of member roles to add/delete */
1053         bool            is_grant;               /* true = GRANT, false = REVOKE */
1054         bool            admin_opt;              /* with admin option */
1055         char       *grantor;            /* set grantor to other than current role */
1056         DropBehavior behavior;          /* drop behavior (for REVOKE) */
1057 } GrantRoleStmt;
1058
1059 /* ----------------------
1060  *              Copy Statement
1061  *
1062  * We support "COPY relation FROM file", "COPY relation TO file", and
1063  * "COPY (query) TO file".      In any given CopyStmt, exactly one of "relation"
1064  * and "query" must be non-NULL.
1065  * ----------------------
1066  */
1067 typedef struct CopyStmt
1068 {
1069         NodeTag         type;
1070         RangeVar   *relation;           /* the relation to copy */
1071         Node       *query;                      /* the SELECT query to copy */
1072         List       *attlist;            /* List of column names (as Strings), or NIL
1073                                                                  * for all columns */
1074         bool            is_from;                /* TO or FROM */
1075         char       *filename;           /* filename, or NULL for STDIN/STDOUT */
1076         List       *options;            /* List of DefElem nodes */
1077 } CopyStmt;
1078
1079 /* ----------------------
1080  * SET Statement (includes RESET)
1081  *
1082  * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
1083  * preserve the distinction in VariableSetKind for CreateCommandTag().
1084  * ----------------------
1085  */
1086 typedef enum
1087 {
1088         VAR_SET_VALUE,                          /* SET var = value */
1089         VAR_SET_DEFAULT,                        /* SET var TO DEFAULT */
1090         VAR_SET_CURRENT,                        /* SET var FROM CURRENT */
1091         VAR_SET_MULTI,                          /* special case for SET TRANSACTION ... */
1092         VAR_RESET,                                      /* RESET var */
1093         VAR_RESET_ALL                           /* RESET ALL */
1094 } VariableSetKind;
1095
1096 typedef struct VariableSetStmt
1097 {
1098         NodeTag         type;
1099         VariableSetKind kind;
1100         char       *name;                       /* variable to be set */
1101         List       *args;                       /* List of A_Const nodes */
1102         bool            is_local;               /* SET LOCAL? */
1103 } VariableSetStmt;
1104
1105 /* ----------------------
1106  * Show Statement
1107  * ----------------------
1108  */
1109 typedef struct VariableShowStmt
1110 {
1111         NodeTag         type;
1112         char       *name;
1113 } VariableShowStmt;
1114
1115 /* ----------------------
1116  *              Create Table Statement
1117  *
1118  * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
1119  * nodes are intermixed in tableElts, and constraints is NIL.  After parse
1120  * analysis, tableElts contains just ColumnDefs, and constraints contains
1121  * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
1122  * implementation).
1123  * ----------------------
1124  */
1125
1126 typedef struct CreateStmt
1127 {
1128         NodeTag         type;
1129         RangeVar   *relation;           /* relation to create */
1130         List       *tableElts;          /* column definitions (list of ColumnDef) */
1131         List       *inhRelations;       /* relations to inherit from (list of
1132                                                                  * inhRelation) */
1133         List       *constraints;        /* constraints (list of Constraint nodes) */
1134         List       *options;            /* options from WITH clause */
1135         OnCommitAction oncommit;        /* what do we do at COMMIT? */
1136         char       *tablespacename; /* table space to use, or NULL */
1137 } CreateStmt;
1138
1139 /* ----------
1140  * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
1141  *
1142  * XXX probably these ought to be unified with FkConstraints at some point?
1143  * To this end we include CONSTR_FOREIGN in the ConstrType enum, even though
1144  * the parser does not generate it.
1145  *
1146  * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
1147  * we may have the expression in either "raw" form (an untransformed
1148  * parse tree) or "cooked" form (the nodeToString representation of
1149  * an executable expression tree), depending on how this Constraint
1150  * node was created (by parsing, or by inheritance from an existing
1151  * relation).  We should never have both in the same node!
1152  *
1153  * Constraint attributes (DEFERRABLE etc) are initially represented as
1154  * separate Constraint nodes for simplicity of parsing.  parse_utilcmd.c makes
1155  * a pass through the constraints list to attach the info to the appropriate
1156  * FkConstraint node (and, perhaps, someday to other kinds of constraints).
1157  * ----------
1158  */
1159
1160 typedef enum ConstrType                 /* types of constraints */
1161 {
1162         CONSTR_NULL,                            /* not SQL92, but a lot of people expect it */
1163         CONSTR_NOTNULL,
1164         CONSTR_DEFAULT,
1165         CONSTR_CHECK,
1166         CONSTR_FOREIGN,
1167         CONSTR_PRIMARY,
1168         CONSTR_UNIQUE,
1169         CONSTR_ATTR_DEFERRABLE,         /* attributes for previous constraint node */
1170         CONSTR_ATTR_NOT_DEFERRABLE,
1171         CONSTR_ATTR_DEFERRED,
1172         CONSTR_ATTR_IMMEDIATE
1173 } ConstrType;
1174
1175 typedef struct Constraint
1176 {
1177         NodeTag         type;
1178         ConstrType      contype;
1179         char       *name;                       /* name, or NULL if unnamed */
1180         Node       *raw_expr;           /* expr, as untransformed parse tree */
1181         char       *cooked_expr;        /* expr, as nodeToString representation */
1182         List       *keys;                       /* String nodes naming referenced column(s) */
1183         List       *options;            /* options from WITH clause */
1184         char       *indexspace;         /* index tablespace for PKEY/UNIQUE
1185                                                                  * constraints; NULL for default */
1186 } Constraint;
1187
1188 /* ----------
1189  * Definitions for FOREIGN KEY constraints in CreateStmt
1190  *
1191  * Note: FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
1192  * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
1193  * stored into pg_constraint.confmatchtype.  Changing the code values may
1194  * require an initdb!
1195  *
1196  * If skip_validation is true then we skip checking that the existing rows
1197  * in the table satisfy the constraint, and just install the catalog entries
1198  * for the constraint.  This is currently used only during CREATE TABLE
1199  * (when we know the table must be empty).
1200  * ----------
1201  */
1202 #define FKCONSTR_ACTION_NOACTION        'a'
1203 #define FKCONSTR_ACTION_RESTRICT        'r'
1204 #define FKCONSTR_ACTION_CASCADE         'c'
1205 #define FKCONSTR_ACTION_SETNULL         'n'
1206 #define FKCONSTR_ACTION_SETDEFAULT      'd'
1207
1208 #define FKCONSTR_MATCH_FULL                     'f'
1209 #define FKCONSTR_MATCH_PARTIAL          'p'
1210 #define FKCONSTR_MATCH_UNSPECIFIED      'u'
1211
1212 typedef struct FkConstraint
1213 {
1214         NodeTag         type;
1215         char       *constr_name;        /* Constraint name, or NULL if unnamed */
1216         RangeVar   *pktable;            /* Primary key table */
1217         List       *fk_attrs;           /* Attributes of foreign key */
1218         List       *pk_attrs;           /* Corresponding attrs in PK table */
1219         char            fk_matchtype;   /* FULL, PARTIAL, UNSPECIFIED */
1220         char            fk_upd_action;  /* ON UPDATE action */
1221         char            fk_del_action;  /* ON DELETE action */
1222         bool            deferrable;             /* DEFERRABLE */
1223         bool            initdeferred;   /* INITIALLY DEFERRED */
1224         bool            skip_validation;        /* skip validation of existing rows? */
1225 } FkConstraint;
1226
1227
1228 /* ----------------------
1229  *              Create/Drop Table Space Statements
1230  * ----------------------
1231  */
1232
1233 typedef struct CreateTableSpaceStmt
1234 {
1235         NodeTag         type;
1236         char       *tablespacename;
1237         char       *owner;
1238         char       *location;
1239 } CreateTableSpaceStmt;
1240
1241 typedef struct DropTableSpaceStmt
1242 {
1243         NodeTag         type;
1244         char       *tablespacename;
1245         bool            missing_ok;             /* skip error if missing? */
1246 } DropTableSpaceStmt;
1247
1248 /* ----------------------
1249  *              Create/Drop TRIGGER Statements
1250  * ----------------------
1251  */
1252
1253 typedef struct CreateTrigStmt
1254 {
1255         NodeTag         type;
1256         char       *trigname;           /* TRIGGER's name */
1257         RangeVar   *relation;           /* relation trigger is on */
1258         List       *funcname;           /* qual. name of function to call */
1259         List       *args;                       /* list of (T_String) Values or NIL */
1260         bool            before;                 /* BEFORE/AFTER */
1261         bool            row;                    /* ROW/STATEMENT */
1262         char            actions[4];             /* 1 to 3 of 'i', 'u', 'd', + trailing \0 */
1263
1264         /* The following are used for referential */
1265         /* integrity constraint triggers */
1266         bool            isconstraint;   /* This is an RI trigger */
1267         bool            deferrable;             /* [NOT] DEFERRABLE */
1268         bool            initdeferred;   /* INITIALLY {DEFERRED|IMMEDIATE} */
1269         RangeVar   *constrrel;          /* opposite relation */
1270 } CreateTrigStmt;
1271
1272 /* ----------------------
1273  *              Create/Drop PROCEDURAL LANGUAGE Statement
1274  * ----------------------
1275  */
1276 typedef struct CreatePLangStmt
1277 {
1278         NodeTag         type;
1279         char       *plname;                     /* PL name */
1280         List       *plhandler;          /* PL call handler function (qual. name) */
1281         List       *plvalidator;        /* optional validator function (qual. name) */
1282         bool            pltrusted;              /* PL is trusted */
1283 } CreatePLangStmt;
1284
1285 typedef struct DropPLangStmt
1286 {
1287         NodeTag         type;
1288         char       *plname;                     /* PL name */
1289         DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
1290         bool            missing_ok;             /* skip error if missing? */
1291 } DropPLangStmt;
1292
1293 /* ----------------------
1294  *      Create/Alter/Drop Role Statements
1295  *
1296  * Note: these node types are also used for the backwards-compatible
1297  * Create/Alter/Drop User/Group statements.  In the ALTER and DROP cases
1298  * there's really no need to distinguish what the original spelling was,
1299  * but for CREATE we mark the type because the defaults vary.
1300  * ----------------------
1301  */
1302 typedef enum RoleStmtType
1303 {
1304         ROLESTMT_ROLE,
1305         ROLESTMT_USER,
1306         ROLESTMT_GROUP
1307 } RoleStmtType;
1308
1309 typedef struct CreateRoleStmt
1310 {
1311         NodeTag         type;
1312         RoleStmtType stmt_type;         /* ROLE/USER/GROUP */
1313         char       *role;                       /* role name */
1314         List       *options;            /* List of DefElem nodes */
1315 } CreateRoleStmt;
1316
1317 typedef struct AlterRoleStmt
1318 {
1319         NodeTag         type;
1320         char       *role;                       /* role name */
1321         List       *options;            /* List of DefElem nodes */
1322         int                     action;                 /* +1 = add members, -1 = drop members */
1323 } AlterRoleStmt;
1324
1325 typedef struct AlterRoleSetStmt
1326 {
1327         NodeTag         type;
1328         char       *role;                       /* role name */
1329         VariableSetStmt *setstmt;       /* SET or RESET subcommand */
1330 } AlterRoleSetStmt;
1331
1332 typedef struct DropRoleStmt
1333 {
1334         NodeTag         type;
1335         List       *roles;                      /* List of roles to remove */
1336         bool            missing_ok;             /* skip error if a role is missing? */
1337 } DropRoleStmt;
1338
1339 /* ----------------------
1340  *              {Create|Alter} SEQUENCE Statement
1341  * ----------------------
1342  */
1343
1344 typedef struct CreateSeqStmt
1345 {
1346         NodeTag         type;
1347         RangeVar   *sequence;           /* the sequence to create */
1348         List       *options;
1349 } CreateSeqStmt;
1350
1351 typedef struct AlterSeqStmt
1352 {
1353         NodeTag         type;
1354         RangeVar   *sequence;           /* the sequence to alter */
1355         List       *options;
1356 } AlterSeqStmt;
1357
1358 /* ----------------------
1359  *              Create {Aggregate|Operator|Type} Statement
1360  * ----------------------
1361  */
1362 typedef struct DefineStmt
1363 {
1364         NodeTag         type;
1365         ObjectType      kind;                   /* aggregate, operator, type */
1366         bool            oldstyle;               /* hack to signal old CREATE AGG syntax */
1367         List       *defnames;           /* qualified name (list of Value strings) */
1368         List       *args;                       /* a list of TypeName (if needed) */
1369         List       *definition;         /* a list of DefElem */
1370 } DefineStmt;
1371
1372 /* ----------------------
1373  *              Create Domain Statement
1374  * ----------------------
1375  */
1376 typedef struct CreateDomainStmt
1377 {
1378         NodeTag         type;
1379         List       *domainname;         /* qualified name (list of Value strings) */
1380         TypeName   *typename;           /* the base type */
1381         List       *constraints;        /* constraints (list of Constraint nodes) */
1382 } CreateDomainStmt;
1383
1384 /* ----------------------
1385  *              Create Operator Class Statement
1386  * ----------------------
1387  */
1388 typedef struct CreateOpClassStmt
1389 {
1390         NodeTag         type;
1391         List       *opclassname;        /* qualified name (list of Value strings) */
1392         List       *opfamilyname;       /* qualified name (ditto); NIL if omitted */
1393         char       *amname;                     /* name of index AM opclass is for */
1394         TypeName   *datatype;           /* datatype of indexed column */
1395         List       *items;                      /* List of CreateOpClassItem nodes */
1396         bool            isDefault;              /* Should be marked as default for type? */
1397 } CreateOpClassStmt;
1398
1399 #define OPCLASS_ITEM_OPERATOR           1
1400 #define OPCLASS_ITEM_FUNCTION           2
1401 #define OPCLASS_ITEM_STORAGETYPE        3
1402
1403 typedef struct CreateOpClassItem
1404 {
1405         NodeTag         type;
1406         int                     itemtype;               /* see codes above */
1407         /* fields used for an operator or function item: */
1408         List       *name;                       /* operator or function name */
1409         List       *args;                       /* argument types */
1410         int                     number;                 /* strategy num or support proc num */
1411         List       *class_args;         /* only used for functions */
1412         /* fields used for a storagetype item: */
1413         TypeName   *storedtype;         /* datatype stored in index */
1414 } CreateOpClassItem;
1415
1416 /* ----------------------
1417  *              Create Operator Family Statement
1418  * ----------------------
1419  */
1420 typedef struct CreateOpFamilyStmt
1421 {
1422         NodeTag         type;
1423         List       *opfamilyname;       /* qualified name (list of Value strings) */
1424         char       *amname;                     /* name of index AM opfamily is for */
1425 } CreateOpFamilyStmt;
1426
1427 /* ----------------------
1428  *              Alter Operator Family Statement
1429  * ----------------------
1430  */
1431 typedef struct AlterOpFamilyStmt
1432 {
1433         NodeTag         type;
1434         List       *opfamilyname;       /* qualified name (list of Value strings) */
1435         char       *amname;                     /* name of index AM opfamily is for */
1436         bool            isDrop;                 /* ADD or DROP the items? */
1437         List       *items;                      /* List of CreateOpClassItem nodes */
1438 } AlterOpFamilyStmt;
1439
1440 /* ----------------------
1441  *              Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
1442  * ----------------------
1443  */
1444
1445 typedef struct DropStmt
1446 {
1447         NodeTag         type;
1448         List       *objects;            /* list of sublists of names (as Values) */
1449         ObjectType      removeType;             /* object type */
1450         DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
1451         bool            missing_ok;             /* skip error if object is missing? */
1452 } DropStmt;
1453
1454 /* ----------------------
1455  *              Drop Rule|Trigger Statement
1456  *
1457  * In general this may be used for dropping any property of a relation;
1458  * for example, someday soon we may have DROP ATTRIBUTE.
1459  * ----------------------
1460  */
1461
1462 typedef struct DropPropertyStmt
1463 {
1464         NodeTag         type;
1465         RangeVar   *relation;           /* owning relation */
1466         char       *property;           /* name of rule, trigger, etc */
1467         ObjectType      removeType;             /* OBJECT_RULE or OBJECT_TRIGGER */
1468         DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
1469         bool            missing_ok;             /* skip error if missing? */
1470 } DropPropertyStmt;
1471
1472 /* ----------------------
1473  *                              Truncate Table Statement
1474  * ----------------------
1475  */
1476 typedef struct TruncateStmt
1477 {
1478         NodeTag         type;
1479         List       *relations;          /* relations (RangeVars) to be truncated */
1480         bool            restart_seqs;   /* restart owned sequences? */
1481         DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
1482 } TruncateStmt;
1483
1484 /* ----------------------
1485  *                              Comment On Statement
1486  * ----------------------
1487  */
1488 typedef struct CommentStmt
1489 {
1490         NodeTag         type;
1491         ObjectType      objtype;                /* Object's type */
1492         List       *objname;            /* Qualified name of the object */
1493         List       *objargs;            /* Arguments if needed (eg, for functions) */
1494         char       *comment;            /* Comment to insert, or NULL to remove */
1495 } CommentStmt;
1496
1497 /* ----------------------
1498  *              Declare Cursor Statement
1499  *
1500  * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar
1501  * output.      After parse analysis it's set to null, and the Query points to the
1502  * DeclareCursorStmt, not vice versa.
1503  * ----------------------
1504  */
1505 #define CURSOR_OPT_BINARY               0x0001  /* BINARY */
1506 #define CURSOR_OPT_SCROLL               0x0002  /* SCROLL explicitly given */
1507 #define CURSOR_OPT_NO_SCROLL    0x0004  /* NO SCROLL explicitly given */
1508 #define CURSOR_OPT_INSENSITIVE  0x0008  /* INSENSITIVE */
1509 #define CURSOR_OPT_HOLD                 0x0010  /* WITH HOLD */
1510 #define CURSOR_OPT_FAST_PLAN    0x0020  /* prefer fast-start plan */
1511
1512 typedef struct DeclareCursorStmt
1513 {
1514         NodeTag         type;
1515         char       *portalname;         /* name of the portal (cursor) */
1516         int                     options;                /* bitmask of options (see above) */
1517         Node       *query;                      /* the raw SELECT query */
1518 } DeclareCursorStmt;
1519
1520 /* ----------------------
1521  *              Close Portal Statement
1522  * ----------------------
1523  */
1524 typedef struct ClosePortalStmt
1525 {
1526         NodeTag         type;
1527         char       *portalname;         /* name of the portal (cursor) */
1528         /* NULL means CLOSE ALL */
1529 } ClosePortalStmt;
1530
1531 /* ----------------------
1532  *              Fetch Statement (also Move)
1533  * ----------------------
1534  */
1535 typedef enum FetchDirection
1536 {
1537         /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1538         FETCH_FORWARD,
1539         FETCH_BACKWARD,
1540         /* for these, howMany indicates a position; only one row is fetched */
1541         FETCH_ABSOLUTE,
1542         FETCH_RELATIVE
1543 } FetchDirection;
1544
1545 #define FETCH_ALL       LONG_MAX
1546
1547 typedef struct FetchStmt
1548 {
1549         NodeTag         type;
1550         FetchDirection direction;       /* see above */
1551         long            howMany;                /* number of rows, or position argument */
1552         char       *portalname;         /* name of portal (cursor) */
1553         bool            ismove;                 /* TRUE if MOVE */
1554 } FetchStmt;
1555
1556 /* ----------------------
1557  *              Create Index Statement
1558  * ----------------------
1559  */
1560 typedef struct IndexStmt
1561 {
1562         NodeTag         type;
1563         char       *idxname;            /* name of new index, or NULL for default */
1564         RangeVar   *relation;           /* relation to build index on */
1565         char       *accessMethod;       /* name of access method (eg. btree) */
1566         char       *tableSpace;         /* tablespace, or NULL for default */
1567         List       *indexParams;        /* a list of IndexElem */
1568         List       *options;            /* options from WITH clause */
1569         Node       *whereClause;        /* qualification (partial-index predicate) */
1570         bool            unique;                 /* is index unique? */
1571         bool            primary;                /* is index on primary key? */
1572         bool            isconstraint;   /* is it from a CONSTRAINT clause? */
1573         bool            concurrent;             /* should this be a concurrent index build? */
1574 } IndexStmt;
1575
1576 /* ----------------------
1577  *              Create Function Statement
1578  * ----------------------
1579  */
1580 typedef struct CreateFunctionStmt
1581 {
1582         NodeTag         type;
1583         bool            replace;                /* T => replace if already exists */
1584         List       *funcname;           /* qualified name of function to create */
1585         List       *parameters;         /* a list of FunctionParameter */
1586         TypeName   *returnType;         /* the return type */
1587         List       *options;            /* a list of DefElem */
1588         List       *withClause;         /* a list of DefElem */
1589 } CreateFunctionStmt;
1590
1591 typedef enum FunctionParameterMode
1592 {
1593         /* the assigned enum values appear in pg_proc, don't change 'em! */
1594         FUNC_PARAM_IN = 'i',            /* input only */
1595         FUNC_PARAM_OUT = 'o',           /* output only */
1596         FUNC_PARAM_INOUT = 'b',         /* both */
1597         FUNC_PARAM_VARIADIC = 'v',      /* variadic */
1598         FUNC_PARAM_TABLE = 't'          /* table function output column */
1599 } FunctionParameterMode;
1600
1601 typedef struct FunctionParameter
1602 {
1603         NodeTag         type;
1604         char       *name;                       /* parameter name, or NULL if not given */
1605         TypeName   *argType;            /* TypeName for parameter type */
1606         FunctionParameterMode mode; /* IN/OUT/INOUT */
1607 } FunctionParameter;
1608
1609 typedef struct AlterFunctionStmt
1610 {
1611         NodeTag         type;
1612         FuncWithArgs *func;                     /* name and args of function */
1613         List       *actions;            /* list of DefElem */
1614 } AlterFunctionStmt;
1615
1616 /* ----------------------
1617  *              Drop {Function|Aggregate|Operator} Statement
1618  * ----------------------
1619  */
1620 typedef struct RemoveFuncStmt
1621 {
1622         NodeTag         type;
1623         ObjectType      kind;                   /* function, aggregate, operator */
1624         List       *name;                       /* qualified name of object to drop */
1625         List       *args;                       /* types of the arguments */
1626         DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
1627         bool            missing_ok;             /* skip error if missing? */
1628 } RemoveFuncStmt;
1629
1630 /* ----------------------
1631  *              Drop Operator Class Statement
1632  * ----------------------
1633  */
1634 typedef struct RemoveOpClassStmt
1635 {
1636         NodeTag         type;
1637         List       *opclassname;        /* qualified name (list of Value strings) */
1638         char       *amname;                     /* name of index AM opclass is for */
1639         DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
1640         bool            missing_ok;             /* skip error if missing? */
1641 } RemoveOpClassStmt;
1642
1643 /* ----------------------
1644  *              Drop Operator Family Statement
1645  * ----------------------
1646  */
1647 typedef struct RemoveOpFamilyStmt
1648 {
1649         NodeTag         type;
1650         List       *opfamilyname;       /* qualified name (list of Value strings) */
1651         char       *amname;                     /* name of index AM opfamily is for */
1652         DropBehavior behavior;          /* RESTRICT or CASCADE behavior */
1653         bool            missing_ok;             /* skip error if missing? */
1654 } RemoveOpFamilyStmt;
1655
1656 /* ----------------------
1657  *              Alter Object Rename Statement
1658  * ----------------------
1659  */
1660 typedef struct RenameStmt
1661 {
1662         NodeTag         type;
1663         ObjectType      renameType;             /* OBJECT_TABLE, OBJECT_COLUMN, etc */
1664         RangeVar   *relation;           /* in case it's a table */
1665         List       *object;                     /* in case it's some other object */
1666         List       *objarg;                     /* argument types, if applicable */
1667         char       *subname;            /* name of contained object (column, rule,
1668                                                                  * trigger, etc) */
1669         char       *newname;            /* the new name */
1670 } RenameStmt;
1671
1672 /* ----------------------
1673  *              ALTER object SET SCHEMA Statement
1674  * ----------------------
1675  */
1676 typedef struct AlterObjectSchemaStmt
1677 {
1678         NodeTag         type;
1679         ObjectType objectType;          /* OBJECT_TABLE, OBJECT_TYPE, etc */
1680         RangeVar   *relation;           /* in case it's a table */
1681         List       *object;                     /* in case it's some other object */
1682         List       *objarg;                     /* argument types, if applicable */
1683         char       *addname;            /* additional name if needed */
1684         char       *newschema;          /* the new schema */
1685 } AlterObjectSchemaStmt;
1686
1687 /* ----------------------
1688  *              Alter Object Owner Statement
1689  * ----------------------
1690  */
1691 typedef struct AlterOwnerStmt
1692 {
1693         NodeTag         type;
1694         ObjectType objectType;          /* OBJECT_TABLE, OBJECT_TYPE, etc */
1695         RangeVar   *relation;           /* in case it's a table */
1696         List       *object;                     /* in case it's some other object */
1697         List       *objarg;                     /* argument types, if applicable */
1698         char       *addname;            /* additional name if needed */
1699         char       *newowner;           /* the new owner */
1700 } AlterOwnerStmt;
1701
1702
1703 /* ----------------------
1704  *              Create Rule Statement
1705  * ----------------------
1706  */
1707 typedef struct RuleStmt
1708 {
1709         NodeTag         type;
1710         RangeVar   *relation;           /* relation the rule is for */
1711         char       *rulename;           /* name of the rule */
1712         Node       *whereClause;        /* qualifications */
1713         CmdType         event;                  /* SELECT, INSERT, etc */
1714         bool            instead;                /* is a 'do instead'? */
1715         List       *actions;            /* the action statements */
1716         bool            replace;                /* OR REPLACE */
1717 } RuleStmt;
1718
1719 /* ----------------------
1720  *              Notify Statement
1721  * ----------------------
1722  */
1723 typedef struct NotifyStmt
1724 {
1725         NodeTag         type;
1726         RangeVar   *relation;           /* qualified name to notify */
1727 } NotifyStmt;
1728
1729 /* ----------------------
1730  *              Listen Statement
1731  * ----------------------
1732  */
1733 typedef struct ListenStmt
1734 {
1735         NodeTag         type;
1736         RangeVar   *relation;           /* qualified name to listen on */
1737 } ListenStmt;
1738
1739 /* ----------------------
1740  *              Unlisten Statement
1741  * ----------------------
1742  */
1743 typedef struct UnlistenStmt
1744 {
1745         NodeTag         type;
1746         RangeVar   *relation;           /* qualified name to unlisten on, or '*' */
1747 } UnlistenStmt;
1748
1749 /* ----------------------
1750  *              {Begin|Commit|Rollback} Transaction Statement
1751  * ----------------------
1752  */
1753 typedef enum TransactionStmtKind
1754 {
1755         TRANS_STMT_BEGIN,
1756         TRANS_STMT_START,                       /* semantically identical to BEGIN */
1757         TRANS_STMT_COMMIT,
1758         TRANS_STMT_ROLLBACK,
1759         TRANS_STMT_SAVEPOINT,
1760         TRANS_STMT_RELEASE,
1761         TRANS_STMT_ROLLBACK_TO,
1762         TRANS_STMT_PREPARE,
1763         TRANS_STMT_COMMIT_PREPARED,
1764         TRANS_STMT_ROLLBACK_PREPARED
1765 } TransactionStmtKind;
1766
1767 typedef struct TransactionStmt
1768 {
1769         NodeTag         type;
1770         TransactionStmtKind kind;       /* see above */
1771         List       *options;            /* for BEGIN/START and savepoint commands */
1772         char       *gid;                        /* for two-phase-commit related commands */
1773 } TransactionStmt;
1774
1775 /* ----------------------
1776  *              Create Type Statement, composite types
1777  * ----------------------
1778  */
1779 typedef struct CompositeTypeStmt
1780 {
1781         NodeTag         type;
1782         RangeVar   *typevar;            /* the composite type to be created */
1783         List       *coldeflist;         /* list of ColumnDef nodes */
1784 } CompositeTypeStmt;
1785
1786 /* ----------------------
1787  *              Create Type Statement, enum types
1788  * ----------------------
1789  */
1790 typedef struct CreateEnumStmt
1791 {
1792         NodeTag         type;
1793         List       *typename;           /* qualified name (list of Value strings) */
1794         List       *vals;                       /* enum values (list of Value strings) */
1795 } CreateEnumStmt;
1796
1797
1798 /* ----------------------
1799  *              Create View Statement
1800  * ----------------------
1801  */
1802 typedef struct ViewStmt
1803 {
1804         NodeTag         type;
1805         RangeVar   *view;                       /* the view to be created */
1806         List       *aliases;            /* target column names */
1807         Node       *query;                      /* the SELECT query */
1808         bool            replace;                /* replace an existing view? */
1809 } ViewStmt;
1810
1811 /* ----------------------
1812  *              Load Statement
1813  * ----------------------
1814  */
1815 typedef struct LoadStmt
1816 {
1817         NodeTag         type;
1818         char       *filename;           /* file to load */
1819 } LoadStmt;
1820
1821 /* ----------------------
1822  *              Createdb Statement
1823  * ----------------------
1824  */
1825 typedef struct CreatedbStmt
1826 {
1827         NodeTag         type;
1828         char       *dbname;                     /* name of database to create */
1829         List       *options;            /* List of DefElem nodes */
1830 } CreatedbStmt;
1831
1832 /* ----------------------
1833  *      Alter Database
1834  * ----------------------
1835  */
1836 typedef struct AlterDatabaseStmt
1837 {
1838         NodeTag         type;
1839         char       *dbname;                     /* name of database to alter */
1840         List       *options;            /* List of DefElem nodes */
1841 } AlterDatabaseStmt;
1842
1843 typedef struct AlterDatabaseSetStmt
1844 {
1845         NodeTag         type;
1846         char       *dbname;                     /* database name */
1847         VariableSetStmt *setstmt;       /* SET or RESET subcommand */
1848 } AlterDatabaseSetStmt;
1849
1850 /* ----------------------
1851  *              Dropdb Statement
1852  * ----------------------
1853  */
1854 typedef struct DropdbStmt
1855 {
1856         NodeTag         type;
1857         char       *dbname;                     /* database to drop */
1858         bool            missing_ok;             /* skip error if db is missing? */
1859 } DropdbStmt;
1860
1861 /* ----------------------
1862  *              Cluster Statement (support pbrown's cluster index implementation)
1863  * ----------------------
1864  */
1865 typedef struct ClusterStmt
1866 {
1867         NodeTag         type;
1868         RangeVar   *relation;           /* relation being indexed, or NULL if all */
1869         char       *indexname;          /* original index defined */
1870 } ClusterStmt;
1871
1872 /* ----------------------
1873  *              Vacuum and Analyze Statements
1874  *
1875  * Even though these are nominally two statements, it's convenient to use
1876  * just one node type for both.
1877  * ----------------------
1878  */
1879 typedef struct VacuumStmt
1880 {
1881         NodeTag         type;
1882         bool            vacuum;                 /* do VACUUM step */
1883         bool            full;                   /* do FULL (non-concurrent) vacuum */
1884         bool            analyze;                /* do ANALYZE step */
1885         bool            verbose;                /* print progress info */
1886         int                     freeze_min_age; /* min freeze age, or -1 to use default */
1887         RangeVar   *relation;           /* single table to process, or NULL */
1888         List       *va_cols;            /* list of column names, or NIL for all */
1889 } VacuumStmt;
1890
1891 /* ----------------------
1892  *              Explain Statement
1893  * ----------------------
1894  */
1895 typedef struct ExplainStmt
1896 {
1897         NodeTag         type;
1898         Node       *query;                      /* the query (as a raw parse tree) */
1899         bool            verbose;                /* print plan info */
1900         bool            analyze;                /* get statistics by executing plan */
1901 } ExplainStmt;
1902
1903 /* ----------------------
1904  * Checkpoint Statement
1905  * ----------------------
1906  */
1907 typedef struct CheckPointStmt
1908 {
1909         NodeTag         type;
1910 } CheckPointStmt;
1911
1912 /* ----------------------
1913  * Discard Statement
1914  * ----------------------
1915  */
1916
1917 typedef enum DiscardMode
1918 {
1919         DISCARD_ALL,
1920         DISCARD_PLANS,
1921         DISCARD_TEMP
1922 } DiscardMode;
1923
1924 typedef struct DiscardStmt
1925 {
1926         NodeTag         type;
1927         DiscardMode target;
1928 } DiscardStmt;
1929
1930 /* ----------------------
1931  *              LOCK Statement
1932  * ----------------------
1933  */
1934 typedef struct LockStmt
1935 {
1936         NodeTag         type;
1937         List       *relations;          /* relations to lock */
1938         int                     mode;                   /* lock mode */
1939         bool            nowait;                 /* no wait mode */
1940 } LockStmt;
1941
1942 /* ----------------------
1943  *              SET CONSTRAINTS Statement
1944  * ----------------------
1945  */
1946 typedef struct ConstraintsSetStmt
1947 {
1948         NodeTag         type;
1949         List       *constraints;        /* List of names as RangeVars */
1950         bool            deferred;
1951 } ConstraintsSetStmt;
1952
1953 /* ----------------------
1954  *              REINDEX Statement
1955  * ----------------------
1956  */
1957 typedef struct ReindexStmt
1958 {
1959         NodeTag         type;
1960         ObjectType      kind;                   /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_DATABASE */
1961         RangeVar   *relation;           /* Table or index to reindex */
1962         const char *name;                       /* name of database to reindex */
1963         bool            do_system;              /* include system tables in database case */
1964         bool            do_user;                /* include user tables in database case */
1965 } ReindexStmt;
1966
1967 /* ----------------------
1968  *              CREATE CONVERSION Statement
1969  * ----------------------
1970  */
1971 typedef struct CreateConversionStmt
1972 {
1973         NodeTag         type;
1974         List       *conversion_name;    /* Name of the conversion */
1975         char       *for_encoding_name;          /* source encoding name */
1976         char       *to_encoding_name;           /* destination encoding name */
1977         List       *func_name;          /* qualified conversion function name */
1978         bool            def;                    /* is this a default conversion? */
1979 } CreateConversionStmt;
1980
1981 /* ----------------------
1982  *      CREATE CAST Statement
1983  * ----------------------
1984  */
1985 typedef struct CreateCastStmt
1986 {
1987         NodeTag         type;
1988         TypeName   *sourcetype;
1989         TypeName   *targettype;
1990         FuncWithArgs *func;
1991         CoercionContext context;
1992 } CreateCastStmt;
1993
1994 /* ----------------------
1995  *      DROP CAST Statement
1996  * ----------------------
1997  */
1998 typedef struct DropCastStmt
1999 {
2000         NodeTag         type;
2001         TypeName   *sourcetype;
2002         TypeName   *targettype;
2003         DropBehavior behavior;
2004         bool            missing_ok;             /* skip error if missing? */
2005 } DropCastStmt;
2006
2007
2008 /* ----------------------
2009  *              PREPARE Statement
2010  * ----------------------
2011  */
2012 typedef struct PrepareStmt
2013 {
2014         NodeTag         type;
2015         char       *name;                       /* Name of plan, arbitrary */
2016         List       *argtypes;           /* Types of parameters (List of TypeName) */
2017         Node       *query;                      /* The query itself (as a raw parsetree) */
2018 } PrepareStmt;
2019
2020
2021 /* ----------------------
2022  *              EXECUTE Statement
2023  * ----------------------
2024  */
2025
2026 typedef struct ExecuteStmt
2027 {
2028         NodeTag         type;
2029         char       *name;                       /* The name of the plan to execute */
2030         IntoClause *into;                       /* Optional table to store results in */
2031         List       *params;                     /* Values to assign to parameters */
2032 } ExecuteStmt;
2033
2034
2035 /* ----------------------
2036  *              DEALLOCATE Statement
2037  * ----------------------
2038  */
2039 typedef struct DeallocateStmt
2040 {
2041         NodeTag         type;
2042         char       *name;                       /* The name of the plan to remove */
2043         /* NULL means DEALLOCATE ALL */
2044 } DeallocateStmt;
2045
2046 /*
2047  *              DROP OWNED statement
2048  */
2049 typedef struct DropOwnedStmt
2050 {
2051         NodeTag         type;
2052         List       *roles;
2053         DropBehavior behavior;
2054 } DropOwnedStmt;
2055
2056 /*
2057  *              REASSIGN OWNED statement
2058  */
2059 typedef struct ReassignOwnedStmt
2060 {
2061         NodeTag         type;
2062         List       *roles;
2063         char       *newrole;
2064 } ReassignOwnedStmt;
2065
2066 /*
2067  * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
2068  */
2069 typedef struct AlterTSDictionaryStmt
2070 {
2071         NodeTag         type;
2072         List       *dictname;           /* qualified name (list of Value strings) */
2073         List       *options;            /* List of DefElem nodes */
2074 } AlterTSDictionaryStmt;
2075
2076 /*
2077  * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
2078  */
2079 typedef struct AlterTSConfigurationStmt
2080 {
2081         NodeTag         type;
2082         List       *cfgname;            /* qualified name (list of Value strings) */
2083
2084         /*
2085          * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is
2086          * NIL, but tokentype isn't, DROP MAPPING was specified.
2087          */
2088         List       *tokentype;          /* list of Value strings */
2089         List       *dicts;                      /* list of list of Value strings */
2090         bool            override;               /* if true - remove old variant */
2091         bool            replace;                /* if true - replace dictionary by another */
2092         bool            missing_ok;             /* for DROP - skip error if missing? */
2093 } AlterTSConfigurationStmt;
2094
2095 #endif   /* PARSENODES_H */