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