1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.371 2008/08/07 01:11:51 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "nodes/primnodes.h"
18 #include "nodes/value.h"
20 /* Possible sources of a Query */
21 typedef enum QuerySource
23 QSRC_ORIGINAL, /* original parsetree (explicit query) */
24 QSRC_PARSER, /* added by parse analysis (now unused) */
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 */
30 /* Sort ordering options for ORDER BY and CREATE INDEX */
31 typedef enum SortByDir
36 SORTBY_USING /* not allowed in CREATE INDEX ... */
39 typedef enum SortByNulls
48 * Grantable rights are encoded so that we can OR them together in a bitmask.
49 * The present representation of AclItem limits us to 16 distinct rights,
50 * even though AclMode is defined as uint32. See utils/acl.h.
52 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
54 typedef uint32 AclMode; /* a bitmask of privilege bits */
56 #define ACL_INSERT (1<<0) /* for relations */
57 #define ACL_SELECT (1<<1)
58 #define ACL_UPDATE (1<<2)
59 #define ACL_DELETE (1<<3)
60 /* #define ACL_RULE (1<<4) unused, available */
61 #define ACL_REFERENCES (1<<5)
62 #define ACL_TRIGGER (1<<6)
63 #define ACL_EXECUTE (1<<7) /* for functions */
64 #define ACL_USAGE (1<<8) /* for languages and namespaces */
65 #define ACL_CREATE (1<<9) /* for namespaces and databases */
66 #define ACL_CREATE_TEMP (1<<10) /* for databases */
67 #define ACL_CONNECT (1<<11) /* for databases */
68 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */
69 #define ACL_NO_RIGHTS 0
70 /* Currently, SELECT ... FOR UPDATE/FOR SHARE requires UPDATE privileges */
71 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE
74 /*****************************************************************************
76 *****************************************************************************/
80 * Parse analysis turns all statements into a Query tree (via transformStmt)
81 * for further processing by the rewriter and planner.
83 * Utility statements (i.e. non-optimizable statements) have the
84 * utilityStmt field set, and the Query itself is mostly dummy.
85 * DECLARE CURSOR is a special case: it is represented like a SELECT,
86 * but the original DeclareCursorStmt is stored in utilityStmt.
88 * Planning converts a Query tree into a Plan tree headed by a PlannedStmt
89 * node --- the Query structure is not used by the executor.
95 CmdType commandType; /* select|insert|update|delete|utility */
97 QuerySource querySource; /* where did I come from? */
99 bool canSetTag; /* do I set the command result tag? */
101 Node *utilityStmt; /* non-null if this is DECLARE CURSOR or a
102 * non-optimizable statement */
104 int resultRelation; /* rtable index of target relation for
105 * INSERT/UPDATE/DELETE; 0 for SELECT */
107 IntoClause *intoClause; /* target for SELECT INTO / CREATE TABLE AS */
109 bool hasAggs; /* has aggregates in tlist or havingQual */
110 bool hasSubLinks; /* has subquery SubLink */
111 bool hasDistinctOn; /* distinctClause is from DISTINCT ON */
113 List *rtable; /* list of range table entries */
114 FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */
116 List *targetList; /* target list (of TargetEntry) */
118 List *returningList; /* return-values list (of TargetEntry) */
120 List *groupClause; /* a list of SortGroupClause's */
122 Node *havingQual; /* qualifications applied to groups */
124 List *distinctClause; /* a list of SortGroupClause's */
126 List *sortClause; /* a list of SortGroupClause's */
128 Node *limitOffset; /* # of result tuples to skip (int8 expr) */
129 Node *limitCount; /* # of result tuples to return (int8 expr) */
131 List *rowMarks; /* a list of RowMarkClause's */
133 Node *setOperations; /* set-operation tree if this is top level of
134 * a UNION/INTERSECT/EXCEPT query */
138 /****************************************************************************
139 * Supporting data structures for Parse Trees
141 * Most of these node types appear in raw parsetrees output by the grammar,
142 * and get transformed to something else by the analyzer. A few of them
143 * are used as-is in transformed querytrees.
145 * Many of the node types used in raw parsetrees include a "location" field.
146 * This is a byte (not character) offset in the original source text, to be
147 * used for positioning an error cursor when there is an analysis-time
148 * error related to the node.
149 ****************************************************************************/
152 * TypeName - specifies a type in definitions
154 * For TypeName structures generated internally, it is often easier to
155 * specify the type by OID than by name. If "names" is NIL then the
156 * actual type OID is given by typeid, otherwise typeid is unused.
157 * Similarly, if "typmods" is NIL then the actual typmod is expected to
158 * be prespecified in typemod, otherwise typemod is unused.
160 * If pct_type is TRUE, then names is actually a field name and we look up
161 * the type of that field. Otherwise (the normal case), names is a type
162 * name possibly qualified with schema and database name.
164 typedef struct TypeName
167 List *names; /* qualified name (list of Value strings) */
168 Oid typeid; /* type identified by OID */
169 bool setof; /* is a set? */
170 bool pct_type; /* %TYPE specified? */
171 List *typmods; /* type modifier expression(s) */
172 int32 typemod; /* prespecified type modifier */
173 List *arrayBounds; /* array bounds */
174 int location; /* token location, or -1 if unknown */
178 * ColumnRef - specifies a reference to a column, or possibly a whole tuple
180 * The "fields" list must be nonempty; its last component may be "*"
181 * instead of a regular field name.
183 * Note: any array subscripting or selection of fields from composite columns
184 * is represented by an A_Indirection node above the ColumnRef. However,
185 * for simplicity in the normal case, initial field selection from a table
186 * name is represented within ColumnRef and not by adding A_Indirection.
188 typedef struct ColumnRef
191 List *fields; /* field names (list of Value strings) */
192 int location; /* token location, or -1 if unknown */
196 * ParamRef - specifies a $n parameter reference
198 typedef struct ParamRef
201 int number; /* the number of the parameter */
205 * A_Expr - infix, prefix, and postfix expressions
207 typedef enum A_Expr_Kind
209 AEXPR_OP, /* normal operator */
210 AEXPR_AND, /* booleans - name field is unused */
213 AEXPR_OP_ANY, /* scalar op ANY (array) */
214 AEXPR_OP_ALL, /* scalar op ALL (array) */
215 AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */
216 AEXPR_NULLIF, /* NULLIF - name must be "=" */
217 AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */
218 AEXPR_IN /* [NOT] IN - name must be "=" or "<>" */
221 typedef struct A_Expr
224 A_Expr_Kind kind; /* see above */
225 List *name; /* possibly-qualified name of operator */
226 Node *lexpr; /* left argument, or NULL if none */
227 Node *rexpr; /* right argument, or NULL if none */
228 int location; /* token location, or -1 if unknown */
232 * A_Const - a literal constant
234 typedef struct A_Const
237 Value val; /* value (includes type info, see value.h) */
241 * TypeCast - a CAST expression
243 typedef struct TypeCast
246 Node *arg; /* the expression being casted */
247 TypeName *typename; /* the target type */
251 * FuncCall - a function or aggregate invocation
253 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
254 * indicates we saw 'foo(DISTINCT ...)'. In either case, the construct
255 * *must* be an aggregate call. Otherwise, it might be either an
256 * aggregate or some other kind of function.
258 typedef struct FuncCall
261 List *funcname; /* qualified name of function */
262 List *args; /* the arguments (list of exprs) */
263 bool agg_star; /* argument was really '*' */
264 bool agg_distinct; /* arguments were labeled DISTINCT */
265 bool func_variadic; /* last argument was labeled VARIADIC */
266 int location; /* token location, or -1 if unknown */
270 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
272 typedef struct A_Indices
275 Node *lidx; /* could be NULL */
280 * A_Indirection - select a field and/or array element from an expression
282 * The indirection list can contain both A_Indices nodes (representing
283 * subscripting) and string Value nodes (representing field selection
284 * --- the string value is the name of the field to select). For example,
285 * a complex selection operation like
286 * (foo).field1[42][7].field2
287 * would be represented with a single A_Indirection node having a 4-element
290 * Note: as of Postgres 8.0, we don't support arrays of composite values,
291 * so cases in which a field select follows a subscript aren't actually
292 * semantically legal. However the parser is prepared to handle such.
294 typedef struct A_Indirection
297 Node *arg; /* the thing being selected from */
298 List *indirection; /* subscripts and/or field names */
302 * A_ArrayExpr - an ARRAY[] construct
304 typedef struct A_ArrayExpr
307 List *elements; /* array element expressions */
312 * result target (used in target list of pre-transformed parse trees)
314 * In a SELECT target list, 'name' is the column label from an
315 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
316 * value expression itself. The 'indirection' field is not used.
318 * INSERT uses ResTarget in its target-column-names list. Here, 'name' is
319 * the name of the destination column, 'indirection' stores any subscripts
320 * attached to the destination, and 'val' is not used.
322 * In an UPDATE target list, 'name' is the name of the destination column,
323 * 'indirection' stores any subscripts attached to the destination, and
324 * 'val' is the expression to assign.
326 * See A_Indirection for more info about what can appear in 'indirection'.
328 typedef struct ResTarget
331 char *name; /* column name or NULL */
332 List *indirection; /* subscripts and field names, or NIL */
333 Node *val; /* the value expression to compute or assign */
334 int location; /* token location, or -1 if unknown */
338 * SortBy - for ORDER BY clause
340 typedef struct SortBy
343 SortByDir sortby_dir; /* ASC/DESC/USING */
344 SortByNulls sortby_nulls; /* NULLS FIRST/LAST */
345 List *useOp; /* name of op to use, if SORTBY_USING */
346 Node *node; /* expression to sort on */
350 * RangeSubselect - subquery appearing in a FROM clause
352 typedef struct RangeSubselect
355 Node *subquery; /* the untransformed sub-select clause */
356 Alias *alias; /* table alias & optional column aliases */
360 * RangeFunction - function call appearing in a FROM clause
362 typedef struct RangeFunction
365 Node *funccallnode; /* untransformed function call tree */
366 Alias *alias; /* table alias & optional column aliases */
367 List *coldeflist; /* list of ColumnDef nodes to describe result
368 * of function returning RECORD */
372 * ColumnDef - column definition (used in various creates)
374 * If the column has a default value, we may have the value expression
375 * in either "raw" form (an untransformed parse tree) or "cooked" form
376 * (the nodeToString representation of an executable expression tree),
377 * depending on how this ColumnDef node was created (by parsing, or by
378 * inheritance from an existing relation). We should never have both
381 * The constraints list may contain a CONSTR_DEFAULT item in a raw
382 * parsetree produced by gram.y, but transformCreateStmt will remove
383 * the item and set raw_default instead. CONSTR_DEFAULT items
384 * should not appear in any subsequent processing.
386 typedef struct ColumnDef
389 char *colname; /* name of column */
390 TypeName *typename; /* type of column */
391 int inhcount; /* number of times column is inherited */
392 bool is_local; /* column has local (non-inherited) def'n */
393 bool is_not_null; /* NOT NULL constraint specified? */
394 Node *raw_default; /* default value (untransformed parse tree) */
395 char *cooked_default; /* nodeToString representation */
396 List *constraints; /* other constraints on column */
400 * inhRelation - Relations a CREATE TABLE is to inherit attributes of
402 typedef struct InhRelation
406 List *options; /* integer List of CreateStmtLikeOption */
409 typedef enum CreateStmtLikeOption
411 CREATE_TABLE_LIKE_INCLUDING_DEFAULTS,
412 CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS,
413 CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS,
414 CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS,
415 CREATE_TABLE_LIKE_INCLUDING_INDEXES,
416 CREATE_TABLE_LIKE_EXCLUDING_INDEXES
417 } CreateStmtLikeOption;
420 * IndexElem - index parameters (used in CREATE INDEX)
422 * For a plain index attribute, 'name' is the name of the table column to
423 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and
424 * 'expr' is the expression tree.
426 typedef struct IndexElem
429 char *name; /* name of attribute to index, or NULL */
430 Node *expr; /* expression to index, or NULL */
431 List *opclass; /* name of desired opclass; NIL = default */
432 SortByDir ordering; /* ASC/DESC/default */
433 SortByNulls nulls_ordering; /* FIRST/LAST/default */
438 * a definition (used in definition lists in the form of defname = arg)
440 typedef struct DefElem
444 Node *arg; /* a (Value *) or a (TypeName *) */
448 * LockingClause - raw representation of FOR UPDATE/SHARE options
450 * Note: lockedRels == NIL means "all relations in query". Otherwise it
451 * is a list of String nodes giving relation eref names.
453 typedef struct LockingClause
456 List *lockedRels; /* FOR UPDATE or FOR SHARE relations */
457 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
458 bool noWait; /* NOWAIT option */
464 typedef struct XmlSerialize
467 XmlOptionType xmloption;
473 /****************************************************************************
474 * Nodes for a Query tree
475 ****************************************************************************/
477 /*--------------------
479 * A range table is a List of RangeTblEntry nodes.
481 * A range table entry may represent a plain relation, a sub-select in
482 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax
483 * produces an RTE, not the implicit join resulting from multiple FROM
484 * items. This is because we only need the RTE to deal with SQL features
485 * like outer joins and join-output-column aliasing.) Other special
486 * RTE types also exist, as indicated by RTEKind.
488 * alias is an Alias node representing the AS alias-clause attached to the
489 * FROM expression, or NULL if no clause.
491 * eref is the table reference name and column reference names (either
492 * real or aliases). Note that system columns (OID etc) are not included
493 * in the column list.
494 * eref->aliasname is required to be present, and should generally be used
495 * to identify the RTE for error messages etc.
497 * In RELATION RTEs, the colnames in both alias and eref are indexed by
498 * physical attribute number; this means there must be colname entries for
499 * dropped columns. When building an RTE we insert empty strings ("") for
500 * dropped columns. Note however that a stored rule may have nonempty
501 * colnames for columns dropped since the rule was created (and for that
502 * matter the colnames might be out of date due to column renamings).
503 * The same comments apply to FUNCTION RTEs when the function's return type
504 * is a named composite type.
506 * In JOIN RTEs, the colnames in both alias and eref are one-to-one with
507 * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when
508 * those columns are known to be dropped at parse time. Again, however,
509 * a stored rule might contain entries for columns dropped since the rule
510 * was created. (This is only possible for columns not actually referenced
511 * in the rule.) When loading a stored rule, we replace the joinaliasvars
512 * items for any such columns with NULL Consts. (We can't simply delete
513 * them from the joinaliasvars list, because that would affect the attnums
514 * of Vars referencing the rest of the list.)
516 * inh is TRUE for relation references that should be expanded to include
517 * inheritance children, if the rel has any. This *must* be FALSE for
518 * RTEs other than RTE_RELATION entries.
520 * inFromCl marks those range variables that are listed in the FROM clause.
521 * It's false for RTEs that are added to a query behind the scenes, such
522 * as the NEW and OLD variables for a rule, or the subqueries of a UNION.
523 * This flag is not used anymore during parsing, since the parser now uses
524 * a separate "namespace" data structure to control visibility, but it is
525 * needed by ruleutils.c to determine whether RTEs should be shown in
526 * decompiled queries.
528 * requiredPerms and checkAsUser specify run-time access permissions
529 * checks to be performed at query startup. The user must have *all*
530 * of the permissions that are OR'd together in requiredPerms (zero
531 * indicates no permissions checking). If checkAsUser is not zero,
532 * then do the permissions checks using the access rights of that user,
533 * not the current effective user ID. (This allows rules to act as
535 *--------------------
539 RTE_RELATION, /* ordinary relation reference */
540 RTE_SUBQUERY, /* subquery in FROM */
542 RTE_SPECIAL, /* special rule relation (NEW or OLD) */
543 RTE_FUNCTION, /* function in FROM */
544 RTE_VALUES /* VALUES (<exprlist>), (<exprlist>), ... */
547 typedef struct RangeTblEntry
551 RTEKind rtekind; /* see above */
554 * XXX the fields applicable to only some rte kinds should be merged into
555 * a union. I didn't do this yet because the diffs would impact a lot of
556 * code that is being actively worked on. FIXME later.
560 * Fields valid for a plain relation RTE (else zero):
562 Oid relid; /* OID of the relation */
565 * Fields valid for a subquery RTE (else NULL):
567 Query *subquery; /* the sub-query */
570 * Fields valid for a function RTE (else NULL):
572 * If the function returns RECORD, funccoltypes lists the column types
573 * declared in the RTE's column type specification, and funccoltypmods
574 * lists their declared typmods. Otherwise, both fields are NIL.
576 Node *funcexpr; /* expression tree for func call */
577 List *funccoltypes; /* OID list of column type OIDs */
578 List *funccoltypmods; /* integer list of column typmods */
581 * Fields valid for a values RTE (else NIL):
583 List *values_lists; /* list of expression lists */
586 * Fields valid for a join RTE (else NULL/zero):
588 * joinaliasvars is a list of Vars or COALESCE expressions corresponding
589 * to the columns of the join result. An alias Var referencing column K
590 * of the join result can be replaced by the K'th element of joinaliasvars
591 * --- but to simplify the task of reverse-listing aliases correctly, we
592 * do not do that until planning time. In a Query loaded from a stored
593 * rule, it is also possible for joinaliasvars items to be NULL Consts,
594 * denoting columns dropped since the rule was made.
596 JoinType jointype; /* type of join */
597 List *joinaliasvars; /* list of alias-var expansions */
600 * Fields valid in all RTEs:
602 Alias *alias; /* user-written alias clause, if any */
603 Alias *eref; /* expanded reference names */
604 bool inh; /* inheritance requested? */
605 bool inFromCl; /* present in FROM clause? */
606 AclMode requiredPerms; /* bitmask of required access permissions */
607 Oid checkAsUser; /* if valid, check access as this role */
612 * representation of ORDER BY, GROUP BY, DISTINCT, DISTINCT ON items
614 * You might think that ORDER BY is only interested in defining ordering,
615 * and GROUP/DISTINCT are only interested in defining equality. However,
616 * one way to implement grouping is to sort and then apply a "uniq"-like
617 * filter. So it's also interesting to keep track of possible sort operators
618 * for GROUP/DISTINCT, and in particular to try to sort for the grouping
619 * in a way that will also yield a requested ORDER BY ordering. So we need
620 * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates
621 * the decision to give them the same representation.
623 * tleSortGroupRef must match ressortgroupref of exactly one entry of the
624 * query's targetlist; that is the expression to be sorted or grouped by.
625 * eqop is the OID of the equality operator.
626 * sortop is the OID of the ordering operator (a "<" or ">" operator),
627 * or InvalidOid if not available.
628 * nulls_first means about what you'd expect. If sortop is InvalidOid
629 * then nulls_first is meaningless and should be set to false.
631 * In an ORDER BY item, all fields must be valid. (The eqop isn't essential
632 * here, but it's cheap to get it along with the sortop, and requiring it
633 * to be valid eases comparisons to grouping items.)
635 * In a grouping item, eqop must be valid. If the eqop is a btree equality
636 * operator, then sortop should be set to a compatible ordering operator.
637 * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that
638 * the query presents for the same tlist item. If there is none, we just
639 * use the default ordering op for the datatype.
641 * If the tlist item's type has a hash opclass but no btree opclass, then
642 * we will set eqop to the hash equality operator, sortop to InvalidOid,
643 * and nulls_first to false. A grouping item of this kind can only be
644 * implemented by hashing, and of course it'll never match an ORDER BY item.
646 * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses.
647 * In SELECT DISTINCT, the distinctClause list is as long or longer than the
648 * sortClause list, while in SELECT DISTINCT ON it's typically shorter.
649 * The two lists must match up to the end of the shorter one --- the parser
650 * rearranges the distinctClause if necessary to make this true. (This
651 * restriction ensures that only one sort step is needed to both satisfy the
652 * ORDER BY and set up for the Unique step. This is semantically necessary
653 * for DISTINCT ON, and presents no real drawback for DISTINCT.)
655 typedef struct SortGroupClause
658 Index tleSortGroupRef; /* reference into targetlist */
659 Oid eqop; /* the equality operator ('=' op) */
660 Oid sortop; /* the ordering operator ('<' op), or 0 */
661 bool nulls_first; /* do NULLs come before normal values? */
666 * representation of FOR UPDATE/SHARE clauses
668 * We create a separate RowMarkClause node for each target relation
670 typedef struct RowMarkClause
673 Index rti; /* range table index of target relation */
674 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
675 bool noWait; /* NOWAIT option */
678 /*****************************************************************************
679 * Optimizable Statements
680 *****************************************************************************/
682 /* ----------------------
685 * The source expression is represented by SelectStmt for both the
686 * SELECT and VALUES cases. If selectStmt is NULL, then the query
687 * is INSERT ... DEFAULT VALUES.
688 * ----------------------
690 typedef struct InsertStmt
693 RangeVar *relation; /* relation to insert into */
694 List *cols; /* optional: names of the target columns */
695 Node *selectStmt; /* the source SELECT/VALUES, or NULL */
696 List *returningList; /* list of expressions to return */
699 /* ----------------------
701 * ----------------------
703 typedef struct DeleteStmt
706 RangeVar *relation; /* relation to delete from */
707 List *usingClause; /* optional using clause for more tables */
708 Node *whereClause; /* qualifications */
709 List *returningList; /* list of expressions to return */
712 /* ----------------------
714 * ----------------------
716 typedef struct UpdateStmt
719 RangeVar *relation; /* relation to update */
720 List *targetList; /* the target list (of ResTarget) */
721 Node *whereClause; /* qualifications */
722 List *fromClause; /* optional from clause for more tables */
723 List *returningList; /* list of expressions to return */
726 /* ----------------------
729 * A "simple" SELECT is represented in the output of gram.y by a single
730 * SelectStmt node; so is a VALUES construct. A query containing set
731 * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
732 * nodes, in which the leaf nodes are component SELECTs and the internal nodes
733 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node
734 * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
735 * LIMIT, etc, clause values into a SELECT statement without worrying
736 * whether it is a simple or compound SELECT.
737 * ----------------------
739 typedef enum SetOperation
747 typedef struct SelectStmt
752 * These fields are used only in "leaf" SelectStmts.
754 List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
755 * lcons(NIL,NIL) for all (SELECT DISTINCT) */
756 IntoClause *intoClause; /* target for SELECT INTO / CREATE TABLE AS */
757 List *targetList; /* the target list (of ResTarget) */
758 List *fromClause; /* the FROM clause */
759 Node *whereClause; /* WHERE qualification */
760 List *groupClause; /* GROUP BY clauses */
761 Node *havingClause; /* HAVING conditional-expression */
764 * In a "leaf" node representing a VALUES list, the above fields are all
765 * null, and instead this field is set. Note that the elements of the
766 * sublists are just expressions, without ResTarget decoration. Also note
767 * that a list element can be DEFAULT (represented as a SetToDefault
768 * node), regardless of the context of the VALUES list. It's up to parse
769 * analysis to reject that where not valid.
771 List *valuesLists; /* untransformed list of expression lists */
774 * These fields are used in both "leaf" SelectStmts and upper-level
777 List *sortClause; /* sort clause (a list of SortBy's) */
778 Node *limitOffset; /* # of result tuples to skip */
779 Node *limitCount; /* # of result tuples to return */
780 List *lockingClause; /* FOR UPDATE (list of LockingClause's) */
783 * These fields are used only in upper-level SelectStmts.
785 SetOperation op; /* type of set op */
786 bool all; /* ALL specified? */
787 struct SelectStmt *larg; /* left child */
788 struct SelectStmt *rarg; /* right child */
789 /* Eventually add fields for CORRESPONDING spec here */
793 /* ----------------------
794 * Set Operation node for post-analysis query trees
796 * After parse analysis, a SELECT with set operations is represented by a
797 * top-level Query node containing the leaf SELECTs as subqueries in its
798 * range table. Its setOperations field shows the tree of set operations,
799 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
800 * nodes replaced by SetOperationStmt nodes. Information about the output
801 * column types is added, too. (Note that the child nodes do not necessarily
802 * produce these types directly, but we've checked that their output types
803 * can be coerced to the output column type.) Also, if it's not UNION ALL,
804 * information about the types' sort/group semantics is provided in the form
805 * of a SortGroupClause list (same representation as, eg, DISTINCT).
806 * ----------------------
808 typedef struct SetOperationStmt
811 SetOperation op; /* type of set op */
812 bool all; /* ALL specified? */
813 Node *larg; /* left child */
814 Node *rarg; /* right child */
815 /* Eventually add fields for CORRESPONDING spec here */
817 /* Fields derived during parse analysis: */
818 List *colTypes; /* OID list of output column type OIDs */
819 List *colTypmods; /* integer list of output column typmods */
820 List *groupClauses; /* a list of SortGroupClause's */
821 /* groupClauses is NIL if UNION ALL, but must be set otherwise */
825 /*****************************************************************************
826 * Other Statements (no optimizations required)
828 * These are not touched by parser/analyze.c except to put them into
829 * the utilityStmt field of a Query. This is eventually passed to
830 * ProcessUtility (by-passing rewriting and planning). Some of the
831 * statements do need attention from parse analysis, and this is
832 * done by routines in parser/parse_utilcmd.c after ProcessUtility
833 * receives the command for execution.
834 *****************************************************************************/
837 * When a command can act on several kinds of objects with only one
838 * parse structure required, use these constants to designate the
842 typedef enum ObjectType
865 OBJECT_TSCONFIGURATION,
873 /* ----------------------
874 * Create Schema Statement
876 * NOTE: the schemaElts list contains raw parsetrees for component statements
877 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
878 * executed after the schema itself is created.
879 * ----------------------
881 typedef struct CreateSchemaStmt
884 char *schemaname; /* the name of the schema to create */
885 char *authid; /* the owner of the created schema */
886 List *schemaElts; /* schema components (list of parsenodes) */
889 typedef enum DropBehavior
891 DROP_RESTRICT, /* drop fails if any dependent objects */
892 DROP_CASCADE /* remove dependent objects too */
895 /* ----------------------
897 * ----------------------
899 typedef struct AlterTableStmt
902 RangeVar *relation; /* table to work on */
903 List *cmds; /* list of subcommands */
904 ObjectType relkind; /* type of object */
907 typedef enum AlterTableType
909 AT_AddColumn, /* add column */
910 AT_ColumnDefault, /* alter column default */
911 AT_DropNotNull, /* alter column drop not null */
912 AT_SetNotNull, /* alter column set not null */
913 AT_SetStatistics, /* alter column statistics */
914 AT_SetStorage, /* alter column storage */
915 AT_DropColumn, /* drop column */
916 AT_DropColumnRecurse, /* internal to commands/tablecmds.c */
917 AT_AddIndex, /* add index */
918 AT_ReAddIndex, /* internal to commands/tablecmds.c */
919 AT_AddConstraint, /* add constraint */
920 AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */
921 AT_ProcessedConstraint, /* pre-processed add constraint (local in
922 * parser/parse_utilcmd.c) */
923 AT_DropConstraint, /* drop constraint */
924 AT_DropConstraintRecurse, /* internal to commands/tablecmds.c */
925 AT_AlterColumnType, /* alter column type */
926 AT_ChangeOwner, /* change owner */
927 AT_ClusterOn, /* CLUSTER ON */
928 AT_DropCluster, /* SET WITHOUT CLUSTER */
929 AT_DropOids, /* SET WITHOUT OIDS */
930 AT_SetTableSpace, /* SET TABLESPACE */
931 AT_SetRelOptions, /* SET (...) -- AM specific parameters */
932 AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */
933 AT_EnableTrig, /* ENABLE TRIGGER name */
934 AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */
935 AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */
936 AT_DisableTrig, /* DISABLE TRIGGER name */
937 AT_EnableTrigAll, /* ENABLE TRIGGER ALL */
938 AT_DisableTrigAll, /* DISABLE TRIGGER ALL */
939 AT_EnableTrigUser, /* ENABLE TRIGGER USER */
940 AT_DisableTrigUser, /* DISABLE TRIGGER USER */
941 AT_EnableRule, /* ENABLE RULE name */
942 AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */
943 AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */
944 AT_DisableRule, /* DISABLE RULE name */
945 AT_AddInherit, /* INHERIT parent */
946 AT_DropInherit /* NO INHERIT parent */
949 typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */
952 AlterTableType subtype; /* Type of table alteration to apply */
953 char *name; /* column, constraint, or trigger to act on,
954 * or new owner or tablespace */
955 Node *def; /* definition of new column, column type,
956 * index, constraint, or parent table */
957 Node *transform; /* transformation expr for ALTER TYPE */
958 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
962 /* ----------------------
965 * The fields are used in different ways by the different variants of
967 * ----------------------
969 typedef struct AlterDomainStmt
972 char subtype; /*------------
973 * T = alter column default
974 * N = alter column drop not null
975 * O = alter column set not null
977 * X = drop constraint
980 List *typename; /* domain to work on */
981 char *name; /* column or constraint name to act on */
982 Node *def; /* definition of default or constraint */
983 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
987 /* ----------------------
988 * Grant|Revoke Statement
989 * ----------------------
991 typedef enum GrantObjectType
993 ACL_OBJECT_RELATION, /* table, view */
994 ACL_OBJECT_SEQUENCE, /* sequence */
995 ACL_OBJECT_DATABASE, /* database */
996 ACL_OBJECT_FUNCTION, /* function */
997 ACL_OBJECT_LANGUAGE, /* procedural language */
998 ACL_OBJECT_NAMESPACE, /* namespace */
999 ACL_OBJECT_TABLESPACE /* tablespace */
1002 typedef struct GrantStmt
1005 bool is_grant; /* true = GRANT, false = REVOKE */
1006 GrantObjectType objtype; /* kind of object being operated on */
1007 List *objects; /* list of RangeVar nodes, FuncWithArgs nodes,
1008 * or plain names (as Value strings) */
1009 List *privileges; /* list of privilege names (as Strings) */
1010 /* privileges == NIL denotes "all privileges" */
1011 List *grantees; /* list of PrivGrantee nodes */
1012 bool grant_option; /* grant or revoke grant option */
1013 DropBehavior behavior; /* drop behavior (for REVOKE) */
1016 typedef struct PrivGrantee
1019 char *rolname; /* if NULL then PUBLIC */
1023 * Note: FuncWithArgs carries only the types of the input parameters of the
1024 * function. So it is sufficient to identify an existing function, but it
1025 * is not enough info to define a function nor to call it.
1027 typedef struct FuncWithArgs
1030 List *funcname; /* qualified name of function */
1031 List *funcargs; /* list of Typename nodes */
1034 /* This is only used internally in gram.y. */
1035 typedef struct PrivTarget
1038 GrantObjectType objtype;
1042 /* ----------------------
1043 * Grant/Revoke Role Statement
1045 * Note: the lists of roles are lists of names, as Value strings
1046 * ----------------------
1048 typedef struct GrantRoleStmt
1051 List *granted_roles; /* list of roles to be granted/revoked */
1052 List *grantee_roles; /* list of member roles to add/delete */
1053 bool is_grant; /* true = GRANT, false = REVOKE */
1054 bool admin_opt; /* with admin option */
1055 char *grantor; /* set grantor to other than current role */
1056 DropBehavior behavior; /* drop behavior (for REVOKE) */
1059 /* ----------------------
1062 * We support "COPY relation FROM file", "COPY relation TO file", and
1063 * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation"
1064 * and "query" must be non-NULL.
1065 * ----------------------
1067 typedef struct CopyStmt
1070 RangeVar *relation; /* the relation to copy */
1071 Node *query; /* the SELECT query to copy */
1072 List *attlist; /* List of column names (as Strings), or NIL
1073 * for all columns */
1074 bool is_from; /* TO or FROM */
1075 char *filename; /* filename, or NULL for STDIN/STDOUT */
1076 List *options; /* List of DefElem nodes */
1079 /* ----------------------
1080 * SET Statement (includes RESET)
1082 * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
1083 * preserve the distinction in VariableSetKind for CreateCommandTag().
1084 * ----------------------
1088 VAR_SET_VALUE, /* SET var = value */
1089 VAR_SET_DEFAULT, /* SET var TO DEFAULT */
1090 VAR_SET_CURRENT, /* SET var FROM CURRENT */
1091 VAR_SET_MULTI, /* special case for SET TRANSACTION ... */
1092 VAR_RESET, /* RESET var */
1093 VAR_RESET_ALL /* RESET ALL */
1096 typedef struct VariableSetStmt
1099 VariableSetKind kind;
1100 char *name; /* variable to be set */
1101 List *args; /* List of A_Const nodes */
1102 bool is_local; /* SET LOCAL? */
1105 /* ----------------------
1107 * ----------------------
1109 typedef struct VariableShowStmt
1115 /* ----------------------
1116 * Create Table Statement
1118 * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
1119 * nodes are intermixed in tableElts, and constraints is NIL. After parse
1120 * analysis, tableElts contains just ColumnDefs, and constraints contains
1121 * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
1123 * ----------------------
1126 typedef struct CreateStmt
1129 RangeVar *relation; /* relation to create */
1130 List *tableElts; /* column definitions (list of ColumnDef) */
1131 List *inhRelations; /* relations to inherit from (list of
1133 List *constraints; /* constraints (list of Constraint nodes) */
1134 List *options; /* options from WITH clause */
1135 OnCommitAction oncommit; /* what do we do at COMMIT? */
1136 char *tablespacename; /* table space to use, or NULL */
1140 * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
1142 * XXX probably these ought to be unified with FkConstraints at some point?
1143 * To this end we include CONSTR_FOREIGN in the ConstrType enum, even though
1144 * the parser does not generate it.
1146 * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
1147 * we may have the expression in either "raw" form (an untransformed
1148 * parse tree) or "cooked" form (the nodeToString representation of
1149 * an executable expression tree), depending on how this Constraint
1150 * node was created (by parsing, or by inheritance from an existing
1151 * relation). We should never have both in the same node!
1153 * Constraint attributes (DEFERRABLE etc) are initially represented as
1154 * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes
1155 * a pass through the constraints list to attach the info to the appropriate
1156 * FkConstraint node (and, perhaps, someday to other kinds of constraints).
1160 typedef enum ConstrType /* types of constraints */
1162 CONSTR_NULL, /* not SQL92, but a lot of people expect it */
1169 CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
1170 CONSTR_ATTR_NOT_DEFERRABLE,
1171 CONSTR_ATTR_DEFERRED,
1172 CONSTR_ATTR_IMMEDIATE
1175 typedef struct Constraint
1179 char *name; /* name, or NULL if unnamed */
1180 Node *raw_expr; /* expr, as untransformed parse tree */
1181 char *cooked_expr; /* expr, as nodeToString representation */
1182 List *keys; /* String nodes naming referenced column(s) */
1183 List *options; /* options from WITH clause */
1184 char *indexspace; /* index tablespace for PKEY/UNIQUE
1185 * constraints; NULL for default */
1189 * Definitions for FOREIGN KEY constraints in CreateStmt
1191 * Note: FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
1192 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
1193 * stored into pg_constraint.confmatchtype. Changing the code values may
1194 * require an initdb!
1196 * If skip_validation is true then we skip checking that the existing rows
1197 * in the table satisfy the constraint, and just install the catalog entries
1198 * for the constraint. This is currently used only during CREATE TABLE
1199 * (when we know the table must be empty).
1202 #define FKCONSTR_ACTION_NOACTION 'a'
1203 #define FKCONSTR_ACTION_RESTRICT 'r'
1204 #define FKCONSTR_ACTION_CASCADE 'c'
1205 #define FKCONSTR_ACTION_SETNULL 'n'
1206 #define FKCONSTR_ACTION_SETDEFAULT 'd'
1208 #define FKCONSTR_MATCH_FULL 'f'
1209 #define FKCONSTR_MATCH_PARTIAL 'p'
1210 #define FKCONSTR_MATCH_UNSPECIFIED 'u'
1212 typedef struct FkConstraint
1215 char *constr_name; /* Constraint name, or NULL if unnamed */
1216 RangeVar *pktable; /* Primary key table */
1217 List *fk_attrs; /* Attributes of foreign key */
1218 List *pk_attrs; /* Corresponding attrs in PK table */
1219 char fk_matchtype; /* FULL, PARTIAL, UNSPECIFIED */
1220 char fk_upd_action; /* ON UPDATE action */
1221 char fk_del_action; /* ON DELETE action */
1222 bool deferrable; /* DEFERRABLE */
1223 bool initdeferred; /* INITIALLY DEFERRED */
1224 bool skip_validation; /* skip validation of existing rows? */
1228 /* ----------------------
1229 * Create/Drop Table Space Statements
1230 * ----------------------
1233 typedef struct CreateTableSpaceStmt
1236 char *tablespacename;
1239 } CreateTableSpaceStmt;
1241 typedef struct DropTableSpaceStmt
1244 char *tablespacename;
1245 bool missing_ok; /* skip error if missing? */
1246 } DropTableSpaceStmt;
1248 /* ----------------------
1249 * Create/Drop TRIGGER Statements
1250 * ----------------------
1253 typedef struct CreateTrigStmt
1256 char *trigname; /* TRIGGER's name */
1257 RangeVar *relation; /* relation trigger is on */
1258 List *funcname; /* qual. name of function to call */
1259 List *args; /* list of (T_String) Values or NIL */
1260 bool before; /* BEFORE/AFTER */
1261 bool row; /* ROW/STATEMENT */
1262 char actions[4]; /* 1 to 3 of 'i', 'u', 'd', + trailing \0 */
1264 /* The following are used for referential */
1265 /* integrity constraint triggers */
1266 bool isconstraint; /* This is an RI trigger */
1267 bool deferrable; /* [NOT] DEFERRABLE */
1268 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
1269 RangeVar *constrrel; /* opposite relation */
1272 /* ----------------------
1273 * Create/Drop PROCEDURAL LANGUAGE Statement
1274 * ----------------------
1276 typedef struct CreatePLangStmt
1279 char *plname; /* PL name */
1280 List *plhandler; /* PL call handler function (qual. name) */
1281 List *plvalidator; /* optional validator function (qual. name) */
1282 bool pltrusted; /* PL is trusted */
1285 typedef struct DropPLangStmt
1288 char *plname; /* PL name */
1289 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1290 bool missing_ok; /* skip error if missing? */
1293 /* ----------------------
1294 * Create/Alter/Drop Role Statements
1296 * Note: these node types are also used for the backwards-compatible
1297 * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases
1298 * there's really no need to distinguish what the original spelling was,
1299 * but for CREATE we mark the type because the defaults vary.
1300 * ----------------------
1302 typedef enum RoleStmtType
1309 typedef struct CreateRoleStmt
1312 RoleStmtType stmt_type; /* ROLE/USER/GROUP */
1313 char *role; /* role name */
1314 List *options; /* List of DefElem nodes */
1317 typedef struct AlterRoleStmt
1320 char *role; /* role name */
1321 List *options; /* List of DefElem nodes */
1322 int action; /* +1 = add members, -1 = drop members */
1325 typedef struct AlterRoleSetStmt
1328 char *role; /* role name */
1329 VariableSetStmt *setstmt; /* SET or RESET subcommand */
1332 typedef struct DropRoleStmt
1335 List *roles; /* List of roles to remove */
1336 bool missing_ok; /* skip error if a role is missing? */
1339 /* ----------------------
1340 * {Create|Alter} SEQUENCE Statement
1341 * ----------------------
1344 typedef struct CreateSeqStmt
1347 RangeVar *sequence; /* the sequence to create */
1351 typedef struct AlterSeqStmt
1354 RangeVar *sequence; /* the sequence to alter */
1358 /* ----------------------
1359 * Create {Aggregate|Operator|Type} Statement
1360 * ----------------------
1362 typedef struct DefineStmt
1365 ObjectType kind; /* aggregate, operator, type */
1366 bool oldstyle; /* hack to signal old CREATE AGG syntax */
1367 List *defnames; /* qualified name (list of Value strings) */
1368 List *args; /* a list of TypeName (if needed) */
1369 List *definition; /* a list of DefElem */
1372 /* ----------------------
1373 * Create Domain Statement
1374 * ----------------------
1376 typedef struct CreateDomainStmt
1379 List *domainname; /* qualified name (list of Value strings) */
1380 TypeName *typename; /* the base type */
1381 List *constraints; /* constraints (list of Constraint nodes) */
1384 /* ----------------------
1385 * Create Operator Class Statement
1386 * ----------------------
1388 typedef struct CreateOpClassStmt
1391 List *opclassname; /* qualified name (list of Value strings) */
1392 List *opfamilyname; /* qualified name (ditto); NIL if omitted */
1393 char *amname; /* name of index AM opclass is for */
1394 TypeName *datatype; /* datatype of indexed column */
1395 List *items; /* List of CreateOpClassItem nodes */
1396 bool isDefault; /* Should be marked as default for type? */
1397 } CreateOpClassStmt;
1399 #define OPCLASS_ITEM_OPERATOR 1
1400 #define OPCLASS_ITEM_FUNCTION 2
1401 #define OPCLASS_ITEM_STORAGETYPE 3
1403 typedef struct CreateOpClassItem
1406 int itemtype; /* see codes above */
1407 /* fields used for an operator or function item: */
1408 List *name; /* operator or function name */
1409 List *args; /* argument types */
1410 int number; /* strategy num or support proc num */
1411 List *class_args; /* only used for functions */
1412 /* fields used for a storagetype item: */
1413 TypeName *storedtype; /* datatype stored in index */
1414 } CreateOpClassItem;
1416 /* ----------------------
1417 * Create Operator Family Statement
1418 * ----------------------
1420 typedef struct CreateOpFamilyStmt
1423 List *opfamilyname; /* qualified name (list of Value strings) */
1424 char *amname; /* name of index AM opfamily is for */
1425 } CreateOpFamilyStmt;
1427 /* ----------------------
1428 * Alter Operator Family Statement
1429 * ----------------------
1431 typedef struct AlterOpFamilyStmt
1434 List *opfamilyname; /* qualified name (list of Value strings) */
1435 char *amname; /* name of index AM opfamily is for */
1436 bool isDrop; /* ADD or DROP the items? */
1437 List *items; /* List of CreateOpClassItem nodes */
1438 } AlterOpFamilyStmt;
1440 /* ----------------------
1441 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
1442 * ----------------------
1445 typedef struct DropStmt
1448 List *objects; /* list of sublists of names (as Values) */
1449 ObjectType removeType; /* object type */
1450 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1451 bool missing_ok; /* skip error if object is missing? */
1454 /* ----------------------
1455 * Drop Rule|Trigger Statement
1457 * In general this may be used for dropping any property of a relation;
1458 * for example, someday soon we may have DROP ATTRIBUTE.
1459 * ----------------------
1462 typedef struct DropPropertyStmt
1465 RangeVar *relation; /* owning relation */
1466 char *property; /* name of rule, trigger, etc */
1467 ObjectType removeType; /* OBJECT_RULE or OBJECT_TRIGGER */
1468 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1469 bool missing_ok; /* skip error if missing? */
1472 /* ----------------------
1473 * Truncate Table Statement
1474 * ----------------------
1476 typedef struct TruncateStmt
1479 List *relations; /* relations (RangeVars) to be truncated */
1480 bool restart_seqs; /* restart owned sequences? */
1481 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1484 /* ----------------------
1485 * Comment On Statement
1486 * ----------------------
1488 typedef struct CommentStmt
1491 ObjectType objtype; /* Object's type */
1492 List *objname; /* Qualified name of the object */
1493 List *objargs; /* Arguments if needed (eg, for functions) */
1494 char *comment; /* Comment to insert, or NULL to remove */
1497 /* ----------------------
1498 * Declare Cursor Statement
1500 * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar
1501 * output. After parse analysis it's set to null, and the Query points to the
1502 * DeclareCursorStmt, not vice versa.
1503 * ----------------------
1505 #define CURSOR_OPT_BINARY 0x0001 /* BINARY */
1506 #define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */
1507 #define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */
1508 #define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */
1509 #define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */
1510 #define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */
1512 typedef struct DeclareCursorStmt
1515 char *portalname; /* name of the portal (cursor) */
1516 int options; /* bitmask of options (see above) */
1517 Node *query; /* the raw SELECT query */
1518 } DeclareCursorStmt;
1520 /* ----------------------
1521 * Close Portal Statement
1522 * ----------------------
1524 typedef struct ClosePortalStmt
1527 char *portalname; /* name of the portal (cursor) */
1528 /* NULL means CLOSE ALL */
1531 /* ----------------------
1532 * Fetch Statement (also Move)
1533 * ----------------------
1535 typedef enum FetchDirection
1537 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1540 /* for these, howMany indicates a position; only one row is fetched */
1545 #define FETCH_ALL LONG_MAX
1547 typedef struct FetchStmt
1550 FetchDirection direction; /* see above */
1551 long howMany; /* number of rows, or position argument */
1552 char *portalname; /* name of portal (cursor) */
1553 bool ismove; /* TRUE if MOVE */
1556 /* ----------------------
1557 * Create Index Statement
1558 * ----------------------
1560 typedef struct IndexStmt
1563 char *idxname; /* name of new index, or NULL for default */
1564 RangeVar *relation; /* relation to build index on */
1565 char *accessMethod; /* name of access method (eg. btree) */
1566 char *tableSpace; /* tablespace, or NULL for default */
1567 List *indexParams; /* a list of IndexElem */
1568 List *options; /* options from WITH clause */
1569 Node *whereClause; /* qualification (partial-index predicate) */
1570 bool unique; /* is index unique? */
1571 bool primary; /* is index on primary key? */
1572 bool isconstraint; /* is it from a CONSTRAINT clause? */
1573 bool concurrent; /* should this be a concurrent index build? */
1576 /* ----------------------
1577 * Create Function Statement
1578 * ----------------------
1580 typedef struct CreateFunctionStmt
1583 bool replace; /* T => replace if already exists */
1584 List *funcname; /* qualified name of function to create */
1585 List *parameters; /* a list of FunctionParameter */
1586 TypeName *returnType; /* the return type */
1587 List *options; /* a list of DefElem */
1588 List *withClause; /* a list of DefElem */
1589 } CreateFunctionStmt;
1591 typedef enum FunctionParameterMode
1593 /* the assigned enum values appear in pg_proc, don't change 'em! */
1594 FUNC_PARAM_IN = 'i', /* input only */
1595 FUNC_PARAM_OUT = 'o', /* output only */
1596 FUNC_PARAM_INOUT = 'b', /* both */
1597 FUNC_PARAM_VARIADIC = 'v', /* variadic */
1598 FUNC_PARAM_TABLE = 't' /* table function output column */
1599 } FunctionParameterMode;
1601 typedef struct FunctionParameter
1604 char *name; /* parameter name, or NULL if not given */
1605 TypeName *argType; /* TypeName for parameter type */
1606 FunctionParameterMode mode; /* IN/OUT/INOUT */
1607 } FunctionParameter;
1609 typedef struct AlterFunctionStmt
1612 FuncWithArgs *func; /* name and args of function */
1613 List *actions; /* list of DefElem */
1614 } AlterFunctionStmt;
1616 /* ----------------------
1617 * Drop {Function|Aggregate|Operator} Statement
1618 * ----------------------
1620 typedef struct RemoveFuncStmt
1623 ObjectType kind; /* function, aggregate, operator */
1624 List *name; /* qualified name of object to drop */
1625 List *args; /* types of the arguments */
1626 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1627 bool missing_ok; /* skip error if missing? */
1630 /* ----------------------
1631 * Drop Operator Class Statement
1632 * ----------------------
1634 typedef struct RemoveOpClassStmt
1637 List *opclassname; /* qualified name (list of Value strings) */
1638 char *amname; /* name of index AM opclass is for */
1639 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1640 bool missing_ok; /* skip error if missing? */
1641 } RemoveOpClassStmt;
1643 /* ----------------------
1644 * Drop Operator Family Statement
1645 * ----------------------
1647 typedef struct RemoveOpFamilyStmt
1650 List *opfamilyname; /* qualified name (list of Value strings) */
1651 char *amname; /* name of index AM opfamily is for */
1652 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1653 bool missing_ok; /* skip error if missing? */
1654 } RemoveOpFamilyStmt;
1656 /* ----------------------
1657 * Alter Object Rename Statement
1658 * ----------------------
1660 typedef struct RenameStmt
1663 ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
1664 RangeVar *relation; /* in case it's a table */
1665 List *object; /* in case it's some other object */
1666 List *objarg; /* argument types, if applicable */
1667 char *subname; /* name of contained object (column, rule,
1669 char *newname; /* the new name */
1672 /* ----------------------
1673 * ALTER object SET SCHEMA Statement
1674 * ----------------------
1676 typedef struct AlterObjectSchemaStmt
1679 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1680 RangeVar *relation; /* in case it's a table */
1681 List *object; /* in case it's some other object */
1682 List *objarg; /* argument types, if applicable */
1683 char *addname; /* additional name if needed */
1684 char *newschema; /* the new schema */
1685 } AlterObjectSchemaStmt;
1687 /* ----------------------
1688 * Alter Object Owner Statement
1689 * ----------------------
1691 typedef struct AlterOwnerStmt
1694 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1695 RangeVar *relation; /* in case it's a table */
1696 List *object; /* in case it's some other object */
1697 List *objarg; /* argument types, if applicable */
1698 char *addname; /* additional name if needed */
1699 char *newowner; /* the new owner */
1703 /* ----------------------
1704 * Create Rule Statement
1705 * ----------------------
1707 typedef struct RuleStmt
1710 RangeVar *relation; /* relation the rule is for */
1711 char *rulename; /* name of the rule */
1712 Node *whereClause; /* qualifications */
1713 CmdType event; /* SELECT, INSERT, etc */
1714 bool instead; /* is a 'do instead'? */
1715 List *actions; /* the action statements */
1716 bool replace; /* OR REPLACE */
1719 /* ----------------------
1721 * ----------------------
1723 typedef struct NotifyStmt
1726 RangeVar *relation; /* qualified name to notify */
1729 /* ----------------------
1731 * ----------------------
1733 typedef struct ListenStmt
1736 RangeVar *relation; /* qualified name to listen on */
1739 /* ----------------------
1740 * Unlisten Statement
1741 * ----------------------
1743 typedef struct UnlistenStmt
1746 RangeVar *relation; /* qualified name to unlisten on, or '*' */
1749 /* ----------------------
1750 * {Begin|Commit|Rollback} Transaction Statement
1751 * ----------------------
1753 typedef enum TransactionStmtKind
1756 TRANS_STMT_START, /* semantically identical to BEGIN */
1758 TRANS_STMT_ROLLBACK,
1759 TRANS_STMT_SAVEPOINT,
1761 TRANS_STMT_ROLLBACK_TO,
1763 TRANS_STMT_COMMIT_PREPARED,
1764 TRANS_STMT_ROLLBACK_PREPARED
1765 } TransactionStmtKind;
1767 typedef struct TransactionStmt
1770 TransactionStmtKind kind; /* see above */
1771 List *options; /* for BEGIN/START and savepoint commands */
1772 char *gid; /* for two-phase-commit related commands */
1775 /* ----------------------
1776 * Create Type Statement, composite types
1777 * ----------------------
1779 typedef struct CompositeTypeStmt
1782 RangeVar *typevar; /* the composite type to be created */
1783 List *coldeflist; /* list of ColumnDef nodes */
1784 } CompositeTypeStmt;
1786 /* ----------------------
1787 * Create Type Statement, enum types
1788 * ----------------------
1790 typedef struct CreateEnumStmt
1793 List *typename; /* qualified name (list of Value strings) */
1794 List *vals; /* enum values (list of Value strings) */
1798 /* ----------------------
1799 * Create View Statement
1800 * ----------------------
1802 typedef struct ViewStmt
1805 RangeVar *view; /* the view to be created */
1806 List *aliases; /* target column names */
1807 Node *query; /* the SELECT query */
1808 bool replace; /* replace an existing view? */
1811 /* ----------------------
1813 * ----------------------
1815 typedef struct LoadStmt
1818 char *filename; /* file to load */
1821 /* ----------------------
1822 * Createdb Statement
1823 * ----------------------
1825 typedef struct CreatedbStmt
1828 char *dbname; /* name of database to create */
1829 List *options; /* List of DefElem nodes */
1832 /* ----------------------
1834 * ----------------------
1836 typedef struct AlterDatabaseStmt
1839 char *dbname; /* name of database to alter */
1840 List *options; /* List of DefElem nodes */
1841 } AlterDatabaseStmt;
1843 typedef struct AlterDatabaseSetStmt
1846 char *dbname; /* database name */
1847 VariableSetStmt *setstmt; /* SET or RESET subcommand */
1848 } AlterDatabaseSetStmt;
1850 /* ----------------------
1852 * ----------------------
1854 typedef struct DropdbStmt
1857 char *dbname; /* database to drop */
1858 bool missing_ok; /* skip error if db is missing? */
1861 /* ----------------------
1862 * Cluster Statement (support pbrown's cluster index implementation)
1863 * ----------------------
1865 typedef struct ClusterStmt
1868 RangeVar *relation; /* relation being indexed, or NULL if all */
1869 char *indexname; /* original index defined */
1872 /* ----------------------
1873 * Vacuum and Analyze Statements
1875 * Even though these are nominally two statements, it's convenient to use
1876 * just one node type for both.
1877 * ----------------------
1879 typedef struct VacuumStmt
1882 bool vacuum; /* do VACUUM step */
1883 bool full; /* do FULL (non-concurrent) vacuum */
1884 bool analyze; /* do ANALYZE step */
1885 bool verbose; /* print progress info */
1886 int freeze_min_age; /* min freeze age, or -1 to use default */
1887 RangeVar *relation; /* single table to process, or NULL */
1888 List *va_cols; /* list of column names, or NIL for all */
1891 /* ----------------------
1893 * ----------------------
1895 typedef struct ExplainStmt
1898 Node *query; /* the query (as a raw parse tree) */
1899 bool verbose; /* print plan info */
1900 bool analyze; /* get statistics by executing plan */
1903 /* ----------------------
1904 * Checkpoint Statement
1905 * ----------------------
1907 typedef struct CheckPointStmt
1912 /* ----------------------
1914 * ----------------------
1917 typedef enum DiscardMode
1924 typedef struct DiscardStmt
1930 /* ----------------------
1932 * ----------------------
1934 typedef struct LockStmt
1937 List *relations; /* relations to lock */
1938 int mode; /* lock mode */
1939 bool nowait; /* no wait mode */
1942 /* ----------------------
1943 * SET CONSTRAINTS Statement
1944 * ----------------------
1946 typedef struct ConstraintsSetStmt
1949 List *constraints; /* List of names as RangeVars */
1951 } ConstraintsSetStmt;
1953 /* ----------------------
1955 * ----------------------
1957 typedef struct ReindexStmt
1960 ObjectType kind; /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_DATABASE */
1961 RangeVar *relation; /* Table or index to reindex */
1962 const char *name; /* name of database to reindex */
1963 bool do_system; /* include system tables in database case */
1964 bool do_user; /* include user tables in database case */
1967 /* ----------------------
1968 * CREATE CONVERSION Statement
1969 * ----------------------
1971 typedef struct CreateConversionStmt
1974 List *conversion_name; /* Name of the conversion */
1975 char *for_encoding_name; /* source encoding name */
1976 char *to_encoding_name; /* destination encoding name */
1977 List *func_name; /* qualified conversion function name */
1978 bool def; /* is this a default conversion? */
1979 } CreateConversionStmt;
1981 /* ----------------------
1982 * CREATE CAST Statement
1983 * ----------------------
1985 typedef struct CreateCastStmt
1988 TypeName *sourcetype;
1989 TypeName *targettype;
1991 CoercionContext context;
1994 /* ----------------------
1995 * DROP CAST Statement
1996 * ----------------------
1998 typedef struct DropCastStmt
2001 TypeName *sourcetype;
2002 TypeName *targettype;
2003 DropBehavior behavior;
2004 bool missing_ok; /* skip error if missing? */
2008 /* ----------------------
2010 * ----------------------
2012 typedef struct PrepareStmt
2015 char *name; /* Name of plan, arbitrary */
2016 List *argtypes; /* Types of parameters (List of TypeName) */
2017 Node *query; /* The query itself (as a raw parsetree) */
2021 /* ----------------------
2023 * ----------------------
2026 typedef struct ExecuteStmt
2029 char *name; /* The name of the plan to execute */
2030 IntoClause *into; /* Optional table to store results in */
2031 List *params; /* Values to assign to parameters */
2035 /* ----------------------
2036 * DEALLOCATE Statement
2037 * ----------------------
2039 typedef struct DeallocateStmt
2042 char *name; /* The name of the plan to remove */
2043 /* NULL means DEALLOCATE ALL */
2047 * DROP OWNED statement
2049 typedef struct DropOwnedStmt
2053 DropBehavior behavior;
2057 * REASSIGN OWNED statement
2059 typedef struct ReassignOwnedStmt
2064 } ReassignOwnedStmt;
2067 * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
2069 typedef struct AlterTSDictionaryStmt
2072 List *dictname; /* qualified name (list of Value strings) */
2073 List *options; /* List of DefElem nodes */
2074 } AlterTSDictionaryStmt;
2077 * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
2079 typedef struct AlterTSConfigurationStmt
2082 List *cfgname; /* qualified name (list of Value strings) */
2085 * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is
2086 * NIL, but tokentype isn't, DROP MAPPING was specified.
2088 List *tokentype; /* list of Value strings */
2089 List *dicts; /* list of list of Value strings */
2090 bool override; /* if true - remove old variant */
2091 bool replace; /* if true - replace dictionary by another */
2092 bool missing_ok; /* for DROP - skip error if missing? */
2093 } AlterTSConfigurationStmt;
2095 #endif /* PARSENODES_H */