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