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