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