OSDN Git Service

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