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