OSDN Git Service

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