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