1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
6 * Many of the node types used in parsetrees include a "location" field.
7 * This is a byte (not character) offset in the original source text, to be
8 * used for positioning an error cursor when there is an error related to
9 * the node. Access to the original source text is needed to make use of
13 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
14 * Portions Copyright (c) 1994, Regents of the University of California
16 * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.376 2008/10/04 21:56:55 tgl Exp $
18 *-------------------------------------------------------------------------
23 #include "nodes/primnodes.h"
24 #include "nodes/value.h"
26 /* Possible sources of a Query */
27 typedef enum QuerySource
29 QSRC_ORIGINAL, /* original parsetree (explicit query) */
30 QSRC_PARSER, /* added by parse analysis (now unused) */
31 QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */
32 QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */
33 QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */
36 /* Sort ordering options for ORDER BY and CREATE INDEX */
37 typedef enum SortByDir
42 SORTBY_USING /* not allowed in CREATE INDEX ... */
45 typedef enum SortByNulls
54 * Grantable rights are encoded so that we can OR them together in a bitmask.
55 * The present representation of AclItem limits us to 16 distinct rights,
56 * even though AclMode is defined as uint32. See utils/acl.h.
58 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
60 typedef uint32 AclMode; /* a bitmask of privilege bits */
62 #define ACL_INSERT (1<<0) /* for relations */
63 #define ACL_SELECT (1<<1)
64 #define ACL_UPDATE (1<<2)
65 #define ACL_DELETE (1<<3)
66 #define ACL_TRUNCATE (1<<4)
67 #define ACL_REFERENCES (1<<5)
68 #define ACL_TRIGGER (1<<6)
69 #define ACL_EXECUTE (1<<7) /* for functions */
70 #define ACL_USAGE (1<<8) /* for languages and namespaces */
71 #define ACL_CREATE (1<<9) /* for namespaces and databases */
72 #define ACL_CREATE_TEMP (1<<10) /* for databases */
73 #define ACL_CONNECT (1<<11) /* for databases */
74 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */
75 #define ACL_NO_RIGHTS 0
76 /* Currently, SELECT ... FOR UPDATE/FOR SHARE requires UPDATE privileges */
77 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE
80 /*****************************************************************************
82 *****************************************************************************/
86 * Parse analysis turns all statements into a Query tree (via transformStmt)
87 * for further processing by the rewriter and planner.
89 * Utility statements (i.e. non-optimizable statements) have the
90 * utilityStmt field set, and the Query itself is mostly dummy.
91 * DECLARE CURSOR is a special case: it is represented like a SELECT,
92 * but the original DeclareCursorStmt is stored in utilityStmt.
94 * Planning converts a Query tree into a Plan tree headed by a PlannedStmt
95 * node --- the Query structure is not used by the executor.
101 CmdType commandType; /* select|insert|update|delete|utility */
103 QuerySource querySource; /* where did I come from? */
105 bool canSetTag; /* do I set the command result tag? */
107 Node *utilityStmt; /* non-null if this is DECLARE CURSOR or a
108 * non-optimizable statement */
110 int resultRelation; /* rtable index of target relation for
111 * INSERT/UPDATE/DELETE; 0 for SELECT */
113 IntoClause *intoClause; /* target for SELECT INTO / CREATE TABLE AS */
115 bool hasAggs; /* has aggregates in tlist or havingQual */
116 bool hasSubLinks; /* has subquery SubLink */
117 bool hasDistinctOn; /* distinctClause is from DISTINCT ON */
118 bool hasRecursive; /* WITH RECURSIVE was specified */
120 List *cteList; /* WITH list (of CommonTableExpr's) */
122 List *rtable; /* list of range table entries */
123 FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */
125 List *targetList; /* target list (of TargetEntry) */
127 List *returningList; /* return-values list (of TargetEntry) */
129 List *groupClause; /* a list of SortGroupClause's */
131 Node *havingQual; /* qualifications applied to groups */
133 List *distinctClause; /* a list of SortGroupClause's */
135 List *sortClause; /* a list of SortGroupClause's */
137 Node *limitOffset; /* # of result tuples to skip (int8 expr) */
138 Node *limitCount; /* # of result tuples to return (int8 expr) */
140 List *rowMarks; /* a list of RowMarkClause's */
142 Node *setOperations; /* set-operation tree if this is top level of
143 * a UNION/INTERSECT/EXCEPT query */
147 /****************************************************************************
148 * Supporting data structures for Parse Trees
150 * Most of these node types appear in raw parsetrees output by the grammar,
151 * and get transformed to something else by the analyzer. A few of them
152 * are used as-is in transformed querytrees.
153 ****************************************************************************/
156 * TypeName - specifies a type in definitions
158 * For TypeName structures generated internally, it is often easier to
159 * specify the type by OID than by name. If "names" is NIL then the
160 * actual type OID is given by typeid, otherwise typeid is unused.
161 * Similarly, if "typmods" is NIL then the actual typmod is expected to
162 * be prespecified in typemod, otherwise typemod is unused.
164 * If pct_type is TRUE, then names is actually a field name and we look up
165 * the type of that field. Otherwise (the normal case), names is a type
166 * name possibly qualified with schema and database name.
168 typedef struct TypeName
171 List *names; /* qualified name (list of Value strings) */
172 Oid typeid; /* type identified by OID */
173 bool setof; /* is a set? */
174 bool pct_type; /* %TYPE specified? */
175 List *typmods; /* type modifier expression(s) */
176 int32 typemod; /* prespecified type modifier */
177 List *arrayBounds; /* array bounds */
178 int location; /* token location, or -1 if unknown */
182 * ColumnRef - specifies a reference to a column, or possibly a whole tuple
184 * The "fields" list must be nonempty. It can contain string Value nodes
185 * (representing names) and A_Star nodes (representing occurrence of a '*').
186 * Currently, A_Star must appear only as the last list element --- the grammar
187 * is responsible for enforcing this!
189 * Note: any array subscripting or selection of fields from composite columns
190 * is represented by an A_Indirection node above the ColumnRef. However,
191 * for simplicity in the normal case, initial field selection from a table
192 * name is represented within ColumnRef and not by adding A_Indirection.
194 typedef struct ColumnRef
197 List *fields; /* field names (Value strings) or A_Star */
198 int location; /* token location, or -1 if unknown */
202 * ParamRef - specifies a $n parameter reference
204 typedef struct ParamRef
207 int number; /* the number of the parameter */
208 int location; /* token location, or -1 if unknown */
212 * A_Expr - infix, prefix, and postfix expressions
214 typedef enum A_Expr_Kind
216 AEXPR_OP, /* normal operator */
217 AEXPR_AND, /* booleans - name field is unused */
220 AEXPR_OP_ANY, /* scalar op ANY (array) */
221 AEXPR_OP_ALL, /* scalar op ALL (array) */
222 AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */
223 AEXPR_NULLIF, /* NULLIF - name must be "=" */
224 AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */
225 AEXPR_IN /* [NOT] IN - name must be "=" or "<>" */
228 typedef struct A_Expr
231 A_Expr_Kind kind; /* see above */
232 List *name; /* possibly-qualified name of operator */
233 Node *lexpr; /* left argument, or NULL if none */
234 Node *rexpr; /* right argument, or NULL if none */
235 int location; /* token location, or -1 if unknown */
239 * A_Const - a literal constant
241 typedef struct A_Const
244 Value val; /* value (includes type info, see value.h) */
245 int location; /* token location, or -1 if unknown */
249 * TypeCast - a CAST expression
251 typedef struct TypeCast
254 Node *arg; /* the expression being casted */
255 TypeName *typename; /* the target type */
256 int location; /* token location, or -1 if unknown */
260 * FuncCall - a function or aggregate invocation
262 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
263 * indicates we saw 'foo(DISTINCT ...)'. In either case, the construct
264 * *must* be an aggregate call. Otherwise, it might be either an
265 * aggregate or some other kind of function.
267 typedef struct FuncCall
270 List *funcname; /* qualified name of function */
271 List *args; /* the arguments (list of exprs) */
272 bool agg_star; /* argument was really '*' */
273 bool agg_distinct; /* arguments were labeled DISTINCT */
274 bool func_variadic; /* last argument was labeled VARIADIC */
275 int location; /* token location, or -1 if unknown */
279 * A_Star - '*' representing all columns of a table or compound field
281 * This can appear within ColumnRef.fields, A_Indirection.indirection, and
282 * ResTarget.indirection lists.
284 typedef struct A_Star
290 * A_Indices - array subscript or slice bounds ([lidx:uidx] or [uidx])
292 typedef struct A_Indices
295 Node *lidx; /* NULL if it's a single subscript */
300 * A_Indirection - select a field and/or array element from an expression
302 * The indirection list can contain A_Indices nodes (representing
303 * subscripting), string Value nodes (representing field selection --- the
304 * string value is the name of the field to select), and A_Star nodes
305 * (representing selection of all fields of a composite type).
306 * For example, a complex selection operation like
307 * (foo).field1[42][7].field2
308 * would be represented with a single A_Indirection node having a 4-element
311 * Currently, A_Star must appear only as the last list element --- the grammar
312 * is responsible for enforcing this!
314 typedef struct A_Indirection
317 Node *arg; /* the thing being selected from */
318 List *indirection; /* subscripts and/or field names and/or * */
322 * A_ArrayExpr - an ARRAY[] construct
324 typedef struct A_ArrayExpr
327 List *elements; /* array element expressions */
328 int location; /* token location, or -1 if unknown */
333 * result target (used in target list of pre-transformed parse trees)
335 * In a SELECT target list, 'name' is the column label from an
336 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
337 * value expression itself. The 'indirection' field is not used.
339 * INSERT uses ResTarget in its target-column-names list. Here, 'name' is
340 * the name of the destination column, 'indirection' stores any subscripts
341 * attached to the destination, and 'val' is not used.
343 * In an UPDATE target list, 'name' is the name of the destination column,
344 * 'indirection' stores any subscripts attached to the destination, and
345 * 'val' is the expression to assign.
347 * See A_Indirection for more info about what can appear in 'indirection'.
349 typedef struct ResTarget
352 char *name; /* column name or NULL */
353 List *indirection; /* subscripts, field names, and '*', or NIL */
354 Node *val; /* the value expression to compute or assign */
355 int location; /* token location, or -1 if unknown */
359 * SortBy - for ORDER BY clause
361 typedef struct SortBy
364 Node *node; /* expression to sort on */
365 SortByDir sortby_dir; /* ASC/DESC/USING/default */
366 SortByNulls sortby_nulls; /* NULLS FIRST/LAST */
367 List *useOp; /* name of op to use, if SORTBY_USING */
368 int location; /* operator location, or -1 if none/unknown */
372 * RangeSubselect - subquery appearing in a FROM clause
374 typedef struct RangeSubselect
377 Node *subquery; /* the untransformed sub-select clause */
378 Alias *alias; /* table alias & optional column aliases */
382 * RangeFunction - function call appearing in a FROM clause
384 typedef struct RangeFunction
387 Node *funccallnode; /* untransformed function call tree */
388 Alias *alias; /* table alias & optional column aliases */
389 List *coldeflist; /* list of ColumnDef nodes to describe result
390 * of function returning RECORD */
394 * ColumnDef - column definition (used in various creates)
396 * If the column has a default value, we may have the value expression
397 * in either "raw" form (an untransformed parse tree) or "cooked" form
398 * (the nodeToString representation of an executable expression tree),
399 * depending on how this ColumnDef node was created (by parsing, or by
400 * inheritance from an existing relation). We should never have both
403 * The constraints list may contain a CONSTR_DEFAULT item in a raw
404 * parsetree produced by gram.y, but transformCreateStmt will remove
405 * the item and set raw_default instead. CONSTR_DEFAULT items
406 * should not appear in any subsequent processing.
408 typedef struct ColumnDef
411 char *colname; /* name of column */
412 TypeName *typename; /* type of column */
413 int inhcount; /* number of times column is inherited */
414 bool is_local; /* column has local (non-inherited) def'n */
415 bool is_not_null; /* NOT NULL constraint specified? */
416 Node *raw_default; /* default value (untransformed parse tree) */
417 char *cooked_default; /* nodeToString representation */
418 List *constraints; /* other constraints on column */
422 * inhRelation - Relations a CREATE TABLE is to inherit attributes of
424 typedef struct InhRelation
428 List *options; /* integer List of CreateStmtLikeOption */
431 typedef enum CreateStmtLikeOption
433 CREATE_TABLE_LIKE_INCLUDING_DEFAULTS,
434 CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS,
435 CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS,
436 CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS,
437 CREATE_TABLE_LIKE_INCLUDING_INDEXES,
438 CREATE_TABLE_LIKE_EXCLUDING_INDEXES
439 } CreateStmtLikeOption;
442 * IndexElem - index parameters (used in CREATE INDEX)
444 * For a plain index attribute, 'name' is the name of the table column to
445 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and
446 * 'expr' is the expression tree.
448 typedef struct IndexElem
451 char *name; /* name of attribute to index, or NULL */
452 Node *expr; /* expression to index, or NULL */
453 List *opclass; /* name of desired opclass; NIL = default */
454 SortByDir ordering; /* ASC/DESC/default */
455 SortByNulls nulls_ordering; /* FIRST/LAST/default */
460 * a definition (used in definition lists in the form of defname = arg)
462 typedef struct DefElem
466 Node *arg; /* a (Value *) or a (TypeName *) */
470 * LockingClause - raw representation of FOR UPDATE/SHARE options
472 * Note: lockedRels == NIL means "all relations in query". Otherwise it
473 * is a list of RangeVar nodes. (We use RangeVar mainly because it carries
474 * a location field --- currently, parse analysis insists on unqualified
475 * names in LockingClause.)
477 typedef struct LockingClause
480 List *lockedRels; /* FOR UPDATE or FOR SHARE relations */
481 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
482 bool noWait; /* NOWAIT option */
486 * XMLSERIALIZE (in raw parse tree only)
488 typedef struct XmlSerialize
491 XmlOptionType xmloption; /* DOCUMENT or CONTENT */
494 int location; /* token location, or -1 if unknown */
498 /****************************************************************************
499 * Nodes for a Query tree
500 ****************************************************************************/
502 /*--------------------
504 * A range table is a List of RangeTblEntry nodes.
506 * A range table entry may represent a plain relation, a sub-select in
507 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax
508 * produces an RTE, not the implicit join resulting from multiple FROM
509 * items. This is because we only need the RTE to deal with SQL features
510 * like outer joins and join-output-column aliasing.) Other special
511 * RTE types also exist, as indicated by RTEKind.
513 * alias is an Alias node representing the AS alias-clause attached to the
514 * FROM expression, or NULL if no clause.
516 * eref is the table reference name and column reference names (either
517 * real or aliases). Note that system columns (OID etc) are not included
518 * in the column list.
519 * eref->aliasname is required to be present, and should generally be used
520 * to identify the RTE for error messages etc.
522 * In RELATION RTEs, the colnames in both alias and eref are indexed by
523 * physical attribute number; this means there must be colname entries for
524 * dropped columns. When building an RTE we insert empty strings ("") for
525 * dropped columns. Note however that a stored rule may have nonempty
526 * colnames for columns dropped since the rule was created (and for that
527 * matter the colnames might be out of date due to column renamings).
528 * The same comments apply to FUNCTION RTEs when the function's return type
529 * is a named composite type.
531 * In JOIN RTEs, the colnames in both alias and eref are one-to-one with
532 * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when
533 * those columns are known to be dropped at parse time. Again, however,
534 * a stored rule might contain entries for columns dropped since the rule
535 * was created. (This is only possible for columns not actually referenced
536 * in the rule.) When loading a stored rule, we replace the joinaliasvars
537 * items for any such columns with NULL Consts. (We can't simply delete
538 * them from the joinaliasvars list, because that would affect the attnums
539 * of Vars referencing the rest of the list.)
541 * inh is TRUE for relation references that should be expanded to include
542 * inheritance children, if the rel has any. This *must* be FALSE for
543 * RTEs other than RTE_RELATION entries.
545 * inFromCl marks those range variables that are listed in the FROM clause.
546 * It's false for RTEs that are added to a query behind the scenes, such
547 * as the NEW and OLD variables for a rule, or the subqueries of a UNION.
548 * This flag is not used anymore during parsing, since the parser now uses
549 * a separate "namespace" data structure to control visibility, but it is
550 * needed by ruleutils.c to determine whether RTEs should be shown in
551 * decompiled queries.
553 * requiredPerms and checkAsUser specify run-time access permissions
554 * checks to be performed at query startup. The user must have *all*
555 * of the permissions that are OR'd together in requiredPerms (zero
556 * indicates no permissions checking). If checkAsUser is not zero,
557 * then do the permissions checks using the access rights of that user,
558 * not the current effective user ID. (This allows rules to act as
560 *--------------------
564 RTE_RELATION, /* ordinary relation reference */
565 RTE_SUBQUERY, /* subquery in FROM */
567 RTE_SPECIAL, /* special rule relation (NEW or OLD) */
568 RTE_FUNCTION, /* function in FROM */
569 RTE_VALUES, /* VALUES (<exprlist>), (<exprlist>), ... */
570 RTE_CTE /* common table expr (WITH list element) */
573 typedef struct RangeTblEntry
577 RTEKind rtekind; /* see above */
580 * XXX the fields applicable to only some rte kinds should be merged into
581 * a union. I didn't do this yet because the diffs would impact a lot of
582 * code that is being actively worked on. FIXME later.
586 * Fields valid for a plain relation RTE (else zero):
588 Oid relid; /* OID of the relation */
591 * Fields valid for a subquery RTE (else NULL):
593 Query *subquery; /* the sub-query */
596 * Fields valid for a join RTE (else NULL/zero):
598 * joinaliasvars is a list of Vars or COALESCE expressions corresponding
599 * to the columns of the join result. An alias Var referencing column K
600 * of the join result can be replaced by the K'th element of joinaliasvars
601 * --- but to simplify the task of reverse-listing aliases correctly, we
602 * do not do that until planning time. In a Query loaded from a stored
603 * rule, it is also possible for joinaliasvars items to be NULL Consts,
604 * denoting columns dropped since the rule was made.
606 JoinType jointype; /* type of join */
607 List *joinaliasvars; /* list of alias-var expansions */
610 * Fields valid for a function RTE (else NULL):
612 * If the function returns RECORD, funccoltypes lists the column types
613 * declared in the RTE's column type specification, and funccoltypmods
614 * lists their declared typmods. Otherwise, both fields are NIL.
616 Node *funcexpr; /* expression tree for func call */
617 List *funccoltypes; /* OID list of column type OIDs */
618 List *funccoltypmods; /* integer list of column typmods */
621 * Fields valid for a values RTE (else NIL):
623 List *values_lists; /* list of expression lists */
626 * Fields valid for a CTE RTE (else NULL/zero):
628 char *ctename; /* name of the WITH list item */
629 Index ctelevelsup; /* number of query levels up */
630 bool self_reference; /* is this a recursive self-reference? */
631 List *ctecoltypes; /* OID list of column type OIDs */
632 List *ctecoltypmods; /* integer list of column typmods */
635 * Fields valid in all RTEs:
637 Alias *alias; /* user-written alias clause, if any */
638 Alias *eref; /* expanded reference names */
639 bool inh; /* inheritance requested? */
640 bool inFromCl; /* present in FROM clause? */
641 AclMode requiredPerms; /* bitmask of required access permissions */
642 Oid checkAsUser; /* if valid, check access as this role */
647 * representation of ORDER BY, GROUP BY, DISTINCT, DISTINCT ON items
649 * You might think that ORDER BY is only interested in defining ordering,
650 * and GROUP/DISTINCT are only interested in defining equality. However,
651 * one way to implement grouping is to sort and then apply a "uniq"-like
652 * filter. So it's also interesting to keep track of possible sort operators
653 * for GROUP/DISTINCT, and in particular to try to sort for the grouping
654 * in a way that will also yield a requested ORDER BY ordering. So we need
655 * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates
656 * the decision to give them the same representation.
658 * tleSortGroupRef must match ressortgroupref of exactly one entry of the
659 * query's targetlist; that is the expression to be sorted or grouped by.
660 * eqop is the OID of the equality operator.
661 * sortop is the OID of the ordering operator (a "<" or ">" operator),
662 * or InvalidOid if not available.
663 * nulls_first means about what you'd expect. If sortop is InvalidOid
664 * then nulls_first is meaningless and should be set to false.
666 * In an ORDER BY item, all fields must be valid. (The eqop isn't essential
667 * here, but it's cheap to get it along with the sortop, and requiring it
668 * to be valid eases comparisons to grouping items.)
670 * In a grouping item, eqop must be valid. If the eqop is a btree equality
671 * operator, then sortop should be set to a compatible ordering operator.
672 * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that
673 * the query presents for the same tlist item. If there is none, we just
674 * use the default ordering op for the datatype.
676 * If the tlist item's type has a hash opclass but no btree opclass, then
677 * we will set eqop to the hash equality operator, sortop to InvalidOid,
678 * and nulls_first to false. A grouping item of this kind can only be
679 * implemented by hashing, and of course it'll never match an ORDER BY item.
681 * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses.
682 * In SELECT DISTINCT, the distinctClause list is as long or longer than the
683 * sortClause list, while in SELECT DISTINCT ON it's typically shorter.
684 * The two lists must match up to the end of the shorter one --- the parser
685 * rearranges the distinctClause if necessary to make this true. (This
686 * restriction ensures that only one sort step is needed to both satisfy the
687 * ORDER BY and set up for the Unique step. This is semantically necessary
688 * for DISTINCT ON, and presents no real drawback for DISTINCT.)
690 typedef struct SortGroupClause
693 Index tleSortGroupRef; /* reference into targetlist */
694 Oid eqop; /* the equality operator ('=' op) */
695 Oid sortop; /* the ordering operator ('<' op), or 0 */
696 bool nulls_first; /* do NULLs come before normal values? */
701 * representation of FOR UPDATE/SHARE clauses
703 * We create a separate RowMarkClause node for each target relation
705 typedef struct RowMarkClause
708 Index rti; /* range table index of target relation */
709 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
710 bool noWait; /* NOWAIT option */
715 * representation of WITH clause
717 * Note: WithClause does not propagate into the Query representation;
718 * but CommonTableExpr does.
720 typedef struct WithClause
723 List *ctes; /* list of CommonTableExprs */
724 bool recursive; /* true = WITH RECURSIVE */
725 int location; /* token location, or -1 if unknown */
730 * representation of WITH list element
732 * We don't currently support the SEARCH or CYCLE clause.
734 typedef struct CommonTableExpr
737 char *ctename; /* query name (never qualified) */
738 List *aliascolnames; /* optional list of column names */
739 Node *ctequery; /* subquery (SelectStmt or Query) */
740 int location; /* token location, or -1 if unknown */
741 /* These fields are set during parse analysis: */
742 bool cterecursive; /* is this CTE actually recursive? */
743 int cterefcount; /* number of RTEs referencing this CTE
744 * (excluding internal self-references) */
745 List *ctecolnames; /* list of output column names */
746 List *ctecoltypes; /* OID list of output column type OIDs */
747 List *ctecoltypmods; /* integer list of output column typmods */
750 /*****************************************************************************
751 * Optimizable Statements
752 *****************************************************************************/
754 /* ----------------------
757 * The source expression is represented by SelectStmt for both the
758 * SELECT and VALUES cases. If selectStmt is NULL, then the query
759 * is INSERT ... DEFAULT VALUES.
760 * ----------------------
762 typedef struct InsertStmt
765 RangeVar *relation; /* relation to insert into */
766 List *cols; /* optional: names of the target columns */
767 Node *selectStmt; /* the source SELECT/VALUES, or NULL */
768 List *returningList; /* list of expressions to return */
771 /* ----------------------
773 * ----------------------
775 typedef struct DeleteStmt
778 RangeVar *relation; /* relation to delete from */
779 List *usingClause; /* optional using clause for more tables */
780 Node *whereClause; /* qualifications */
781 List *returningList; /* list of expressions to return */
784 /* ----------------------
786 * ----------------------
788 typedef struct UpdateStmt
791 RangeVar *relation; /* relation to update */
792 List *targetList; /* the target list (of ResTarget) */
793 Node *whereClause; /* qualifications */
794 List *fromClause; /* optional from clause for more tables */
795 List *returningList; /* list of expressions to return */
798 /* ----------------------
801 * A "simple" SELECT is represented in the output of gram.y by a single
802 * SelectStmt node; so is a VALUES construct. A query containing set
803 * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
804 * nodes, in which the leaf nodes are component SELECTs and the internal nodes
805 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node
806 * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
807 * LIMIT, etc, clause values into a SELECT statement without worrying
808 * whether it is a simple or compound SELECT.
809 * ----------------------
811 typedef enum SetOperation
819 typedef struct SelectStmt
824 * These fields are used only in "leaf" SelectStmts.
826 List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
827 * lcons(NIL,NIL) for all (SELECT DISTINCT) */
828 IntoClause *intoClause; /* target for SELECT INTO / CREATE TABLE AS */
829 List *targetList; /* the target list (of ResTarget) */
830 List *fromClause; /* the FROM clause */
831 Node *whereClause; /* WHERE qualification */
832 List *groupClause; /* GROUP BY clauses */
833 Node *havingClause; /* HAVING conditional-expression */
834 WithClause *withClause; /* WITH clause */
837 * In a "leaf" node representing a VALUES list, the above fields are all
838 * null, and instead this field is set. Note that the elements of the
839 * sublists are just expressions, without ResTarget decoration. Also note
840 * that a list element can be DEFAULT (represented as a SetToDefault
841 * node), regardless of the context of the VALUES list. It's up to parse
842 * analysis to reject that where not valid.
844 List *valuesLists; /* untransformed list of expression lists */
847 * These fields are used in both "leaf" SelectStmts and upper-level
850 List *sortClause; /* sort clause (a list of SortBy's) */
851 Node *limitOffset; /* # of result tuples to skip */
852 Node *limitCount; /* # of result tuples to return */
853 List *lockingClause; /* FOR UPDATE (list of LockingClause's) */
856 * These fields are used only in upper-level SelectStmts.
858 SetOperation op; /* type of set op */
859 bool all; /* ALL specified? */
860 struct SelectStmt *larg; /* left child */
861 struct SelectStmt *rarg; /* right child */
862 /* Eventually add fields for CORRESPONDING spec here */
866 /* ----------------------
867 * Set Operation node for post-analysis query trees
869 * After parse analysis, a SELECT with set operations is represented by a
870 * top-level Query node containing the leaf SELECTs as subqueries in its
871 * range table. Its setOperations field shows the tree of set operations,
872 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
873 * nodes replaced by SetOperationStmt nodes. Information about the output
874 * column types is added, too. (Note that the child nodes do not necessarily
875 * produce these types directly, but we've checked that their output types
876 * can be coerced to the output column type.) Also, if it's not UNION ALL,
877 * information about the types' sort/group semantics is provided in the form
878 * of a SortGroupClause list (same representation as, eg, DISTINCT).
879 * ----------------------
881 typedef struct SetOperationStmt
884 SetOperation op; /* type of set op */
885 bool all; /* ALL specified? */
886 Node *larg; /* left child */
887 Node *rarg; /* right child */
888 /* Eventually add fields for CORRESPONDING spec here */
890 /* Fields derived during parse analysis: */
891 List *colTypes; /* OID list of output column type OIDs */
892 List *colTypmods; /* integer list of output column typmods */
893 List *groupClauses; /* a list of SortGroupClause's */
894 /* groupClauses is NIL if UNION ALL, but must be set otherwise */
898 /*****************************************************************************
899 * Other Statements (no optimizations required)
901 * These are not touched by parser/analyze.c except to put them into
902 * the utilityStmt field of a Query. This is eventually passed to
903 * ProcessUtility (by-passing rewriting and planning). Some of the
904 * statements do need attention from parse analysis, and this is
905 * done by routines in parser/parse_utilcmd.c after ProcessUtility
906 * receives the command for execution.
907 *****************************************************************************/
910 * When a command can act on several kinds of objects with only one
911 * parse structure required, use these constants to designate the
915 typedef enum ObjectType
938 OBJECT_TSCONFIGURATION,
946 /* ----------------------
947 * Create Schema Statement
949 * NOTE: the schemaElts list contains raw parsetrees for component statements
950 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
951 * executed after the schema itself is created.
952 * ----------------------
954 typedef struct CreateSchemaStmt
957 char *schemaname; /* the name of the schema to create */
958 char *authid; /* the owner of the created schema */
959 List *schemaElts; /* schema components (list of parsenodes) */
962 typedef enum DropBehavior
964 DROP_RESTRICT, /* drop fails if any dependent objects */
965 DROP_CASCADE /* remove dependent objects too */
968 /* ----------------------
970 * ----------------------
972 typedef struct AlterTableStmt
975 RangeVar *relation; /* table to work on */
976 List *cmds; /* list of subcommands */
977 ObjectType relkind; /* type of object */
980 typedef enum AlterTableType
982 AT_AddColumn, /* add column */
983 AT_ColumnDefault, /* alter column default */
984 AT_DropNotNull, /* alter column drop not null */
985 AT_SetNotNull, /* alter column set not null */
986 AT_SetStatistics, /* alter column statistics */
987 AT_SetStorage, /* alter column storage */
988 AT_DropColumn, /* drop column */
989 AT_DropColumnRecurse, /* internal to commands/tablecmds.c */
990 AT_AddIndex, /* add index */
991 AT_ReAddIndex, /* internal to commands/tablecmds.c */
992 AT_AddConstraint, /* add constraint */
993 AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */
994 AT_ProcessedConstraint, /* pre-processed add constraint (local in
995 * parser/parse_utilcmd.c) */
996 AT_DropConstraint, /* drop constraint */
997 AT_DropConstraintRecurse, /* internal to commands/tablecmds.c */
998 AT_AlterColumnType, /* alter column type */
999 AT_ChangeOwner, /* change owner */
1000 AT_ClusterOn, /* CLUSTER ON */
1001 AT_DropCluster, /* SET WITHOUT CLUSTER */
1002 AT_DropOids, /* SET WITHOUT OIDS */
1003 AT_SetTableSpace, /* SET TABLESPACE */
1004 AT_SetRelOptions, /* SET (...) -- AM specific parameters */
1005 AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */
1006 AT_EnableTrig, /* ENABLE TRIGGER name */
1007 AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */
1008 AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */
1009 AT_DisableTrig, /* DISABLE TRIGGER name */
1010 AT_EnableTrigAll, /* ENABLE TRIGGER ALL */
1011 AT_DisableTrigAll, /* DISABLE TRIGGER ALL */
1012 AT_EnableTrigUser, /* ENABLE TRIGGER USER */
1013 AT_DisableTrigUser, /* DISABLE TRIGGER USER */
1014 AT_EnableRule, /* ENABLE RULE name */
1015 AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */
1016 AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */
1017 AT_DisableRule, /* DISABLE RULE name */
1018 AT_AddInherit, /* INHERIT parent */
1019 AT_DropInherit /* NO INHERIT parent */
1022 typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */
1025 AlterTableType subtype; /* Type of table alteration to apply */
1026 char *name; /* column, constraint, or trigger to act on,
1027 * or new owner or tablespace */
1028 Node *def; /* definition of new column, column type,
1029 * index, constraint, or parent table */
1030 Node *transform; /* transformation expr for ALTER TYPE */
1031 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
1035 /* ----------------------
1038 * The fields are used in different ways by the different variants of
1040 * ----------------------
1042 typedef struct AlterDomainStmt
1045 char subtype; /*------------
1046 * T = alter column default
1047 * N = alter column drop not null
1048 * O = alter column set not null
1049 * C = add constraint
1050 * X = drop constraint
1053 List *typename; /* domain to work on */
1054 char *name; /* column or constraint name to act on */
1055 Node *def; /* definition of default or constraint */
1056 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
1060 /* ----------------------
1061 * Grant|Revoke Statement
1062 * ----------------------
1064 typedef enum GrantObjectType
1066 ACL_OBJECT_RELATION, /* table, view */
1067 ACL_OBJECT_SEQUENCE, /* sequence */
1068 ACL_OBJECT_DATABASE, /* database */
1069 ACL_OBJECT_FUNCTION, /* function */
1070 ACL_OBJECT_LANGUAGE, /* procedural language */
1071 ACL_OBJECT_NAMESPACE, /* namespace */
1072 ACL_OBJECT_TABLESPACE /* tablespace */
1075 typedef struct GrantStmt
1078 bool is_grant; /* true = GRANT, false = REVOKE */
1079 GrantObjectType objtype; /* kind of object being operated on */
1080 List *objects; /* list of RangeVar nodes, FuncWithArgs nodes,
1081 * or plain names (as Value strings) */
1082 List *privileges; /* list of privilege names (as Strings) */
1083 /* privileges == NIL denotes "all privileges" */
1084 List *grantees; /* list of PrivGrantee nodes */
1085 bool grant_option; /* grant or revoke grant option */
1086 DropBehavior behavior; /* drop behavior (for REVOKE) */
1089 typedef struct PrivGrantee
1092 char *rolname; /* if NULL then PUBLIC */
1096 * Note: FuncWithArgs carries only the types of the input parameters of the
1097 * function. So it is sufficient to identify an existing function, but it
1098 * is not enough info to define a function nor to call it.
1100 typedef struct FuncWithArgs
1103 List *funcname; /* qualified name of function */
1104 List *funcargs; /* list of Typename nodes */
1107 /* This is only used internally in gram.y. */
1108 typedef struct PrivTarget
1111 GrantObjectType objtype;
1115 /* ----------------------
1116 * Grant/Revoke Role Statement
1118 * Note: the lists of roles are lists of names, as Value strings
1119 * ----------------------
1121 typedef struct GrantRoleStmt
1124 List *granted_roles; /* list of roles to be granted/revoked */
1125 List *grantee_roles; /* list of member roles to add/delete */
1126 bool is_grant; /* true = GRANT, false = REVOKE */
1127 bool admin_opt; /* with admin option */
1128 char *grantor; /* set grantor to other than current role */
1129 DropBehavior behavior; /* drop behavior (for REVOKE) */
1132 /* ----------------------
1135 * We support "COPY relation FROM file", "COPY relation TO file", and
1136 * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation"
1137 * and "query" must be non-NULL.
1138 * ----------------------
1140 typedef struct CopyStmt
1143 RangeVar *relation; /* the relation to copy */
1144 Node *query; /* the SELECT query to copy */
1145 List *attlist; /* List of column names (as Strings), or NIL
1146 * for all columns */
1147 bool is_from; /* TO or FROM */
1148 char *filename; /* filename, or NULL for STDIN/STDOUT */
1149 List *options; /* List of DefElem nodes */
1152 /* ----------------------
1153 * SET Statement (includes RESET)
1155 * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
1156 * preserve the distinction in VariableSetKind for CreateCommandTag().
1157 * ----------------------
1161 VAR_SET_VALUE, /* SET var = value */
1162 VAR_SET_DEFAULT, /* SET var TO DEFAULT */
1163 VAR_SET_CURRENT, /* SET var FROM CURRENT */
1164 VAR_SET_MULTI, /* special case for SET TRANSACTION ... */
1165 VAR_RESET, /* RESET var */
1166 VAR_RESET_ALL /* RESET ALL */
1169 typedef struct VariableSetStmt
1172 VariableSetKind kind;
1173 char *name; /* variable to be set */
1174 List *args; /* List of A_Const nodes */
1175 bool is_local; /* SET LOCAL? */
1178 /* ----------------------
1180 * ----------------------
1182 typedef struct VariableShowStmt
1188 /* ----------------------
1189 * Create Table Statement
1191 * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
1192 * nodes are intermixed in tableElts, and constraints is NIL. After parse
1193 * analysis, tableElts contains just ColumnDefs, and constraints contains
1194 * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
1196 * ----------------------
1199 typedef struct CreateStmt
1202 RangeVar *relation; /* relation to create */
1203 List *tableElts; /* column definitions (list of ColumnDef) */
1204 List *inhRelations; /* relations to inherit from (list of
1206 List *constraints; /* constraints (list of Constraint nodes) */
1207 List *options; /* options from WITH clause */
1208 OnCommitAction oncommit; /* what do we do at COMMIT? */
1209 char *tablespacename; /* table space to use, or NULL */
1213 * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
1215 * XXX probably these ought to be unified with FkConstraints at some point?
1216 * To this end we include CONSTR_FOREIGN in the ConstrType enum, even though
1217 * the parser does not generate it.
1219 * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
1220 * we may have the expression in either "raw" form (an untransformed
1221 * parse tree) or "cooked" form (the nodeToString representation of
1222 * an executable expression tree), depending on how this Constraint
1223 * node was created (by parsing, or by inheritance from an existing
1224 * relation). We should never have both in the same node!
1226 * Constraint attributes (DEFERRABLE etc) are initially represented as
1227 * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes
1228 * a pass through the constraints list to attach the info to the appropriate
1229 * FkConstraint node (and, perhaps, someday to other kinds of constraints).
1233 typedef enum ConstrType /* types of constraints */
1235 CONSTR_NULL, /* not SQL92, but a lot of people expect it */
1242 CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
1243 CONSTR_ATTR_NOT_DEFERRABLE,
1244 CONSTR_ATTR_DEFERRED,
1245 CONSTR_ATTR_IMMEDIATE
1248 typedef struct Constraint
1252 char *name; /* name, or NULL if unnamed */
1253 Node *raw_expr; /* expr, as untransformed parse tree */
1254 char *cooked_expr; /* expr, as nodeToString representation */
1255 List *keys; /* String nodes naming referenced column(s) */
1256 List *options; /* options from WITH clause */
1257 char *indexspace; /* index tablespace for PKEY/UNIQUE
1258 * constraints; NULL for default */
1262 * Definitions for FOREIGN KEY constraints in CreateStmt
1264 * Note: FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
1265 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
1266 * stored into pg_constraint.confmatchtype. Changing the code values may
1267 * require an initdb!
1269 * If skip_validation is true then we skip checking that the existing rows
1270 * in the table satisfy the constraint, and just install the catalog entries
1271 * for the constraint. This is currently used only during CREATE TABLE
1272 * (when we know the table must be empty).
1275 #define FKCONSTR_ACTION_NOACTION 'a'
1276 #define FKCONSTR_ACTION_RESTRICT 'r'
1277 #define FKCONSTR_ACTION_CASCADE 'c'
1278 #define FKCONSTR_ACTION_SETNULL 'n'
1279 #define FKCONSTR_ACTION_SETDEFAULT 'd'
1281 #define FKCONSTR_MATCH_FULL 'f'
1282 #define FKCONSTR_MATCH_PARTIAL 'p'
1283 #define FKCONSTR_MATCH_UNSPECIFIED 'u'
1285 typedef struct FkConstraint
1288 char *constr_name; /* Constraint name, or NULL if unnamed */
1289 RangeVar *pktable; /* Primary key table */
1290 List *fk_attrs; /* Attributes of foreign key */
1291 List *pk_attrs; /* Corresponding attrs in PK table */
1292 char fk_matchtype; /* FULL, PARTIAL, UNSPECIFIED */
1293 char fk_upd_action; /* ON UPDATE action */
1294 char fk_del_action; /* ON DELETE action */
1295 bool deferrable; /* DEFERRABLE */
1296 bool initdeferred; /* INITIALLY DEFERRED */
1297 bool skip_validation; /* skip validation of existing rows? */
1301 /* ----------------------
1302 * Create/Drop Table Space Statements
1303 * ----------------------
1306 typedef struct CreateTableSpaceStmt
1309 char *tablespacename;
1312 } CreateTableSpaceStmt;
1314 typedef struct DropTableSpaceStmt
1317 char *tablespacename;
1318 bool missing_ok; /* skip error if missing? */
1319 } DropTableSpaceStmt;
1321 /* ----------------------
1322 * Create/Drop TRIGGER Statements
1323 * ----------------------
1326 typedef struct CreateTrigStmt
1329 char *trigname; /* TRIGGER's name */
1330 RangeVar *relation; /* relation trigger is on */
1331 List *funcname; /* qual. name of function to call */
1332 List *args; /* list of (T_String) Values or NIL */
1333 bool before; /* BEFORE/AFTER */
1334 bool row; /* ROW/STATEMENT */
1335 char actions[4]; /* 1 to 3 of 'i', 'u', 'd', + trailing \0 */
1337 /* The following are used for referential */
1338 /* integrity constraint triggers */
1339 bool isconstraint; /* This is an RI trigger */
1340 bool deferrable; /* [NOT] DEFERRABLE */
1341 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
1342 RangeVar *constrrel; /* opposite relation */
1345 /* ----------------------
1346 * Create/Drop PROCEDURAL LANGUAGE Statement
1347 * ----------------------
1349 typedef struct CreatePLangStmt
1352 char *plname; /* PL name */
1353 List *plhandler; /* PL call handler function (qual. name) */
1354 List *plvalidator; /* optional validator function (qual. name) */
1355 bool pltrusted; /* PL is trusted */
1358 typedef struct DropPLangStmt
1361 char *plname; /* PL name */
1362 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1363 bool missing_ok; /* skip error if missing? */
1366 /* ----------------------
1367 * Create/Alter/Drop Role Statements
1369 * Note: these node types are also used for the backwards-compatible
1370 * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases
1371 * there's really no need to distinguish what the original spelling was,
1372 * but for CREATE we mark the type because the defaults vary.
1373 * ----------------------
1375 typedef enum RoleStmtType
1382 typedef struct CreateRoleStmt
1385 RoleStmtType stmt_type; /* ROLE/USER/GROUP */
1386 char *role; /* role name */
1387 List *options; /* List of DefElem nodes */
1390 typedef struct AlterRoleStmt
1393 char *role; /* role name */
1394 List *options; /* List of DefElem nodes */
1395 int action; /* +1 = add members, -1 = drop members */
1398 typedef struct AlterRoleSetStmt
1401 char *role; /* role name */
1402 VariableSetStmt *setstmt; /* SET or RESET subcommand */
1405 typedef struct DropRoleStmt
1408 List *roles; /* List of roles to remove */
1409 bool missing_ok; /* skip error if a role is missing? */
1412 /* ----------------------
1413 * {Create|Alter} SEQUENCE Statement
1414 * ----------------------
1417 typedef struct CreateSeqStmt
1420 RangeVar *sequence; /* the sequence to create */
1424 typedef struct AlterSeqStmt
1427 RangeVar *sequence; /* the sequence to alter */
1431 /* ----------------------
1432 * Create {Aggregate|Operator|Type} Statement
1433 * ----------------------
1435 typedef struct DefineStmt
1438 ObjectType kind; /* aggregate, operator, type */
1439 bool oldstyle; /* hack to signal old CREATE AGG syntax */
1440 List *defnames; /* qualified name (list of Value strings) */
1441 List *args; /* a list of TypeName (if needed) */
1442 List *definition; /* a list of DefElem */
1445 /* ----------------------
1446 * Create Domain Statement
1447 * ----------------------
1449 typedef struct CreateDomainStmt
1452 List *domainname; /* qualified name (list of Value strings) */
1453 TypeName *typename; /* the base type */
1454 List *constraints; /* constraints (list of Constraint nodes) */
1457 /* ----------------------
1458 * Create Operator Class Statement
1459 * ----------------------
1461 typedef struct CreateOpClassStmt
1464 List *opclassname; /* qualified name (list of Value strings) */
1465 List *opfamilyname; /* qualified name (ditto); NIL if omitted */
1466 char *amname; /* name of index AM opclass is for */
1467 TypeName *datatype; /* datatype of indexed column */
1468 List *items; /* List of CreateOpClassItem nodes */
1469 bool isDefault; /* Should be marked as default for type? */
1470 } CreateOpClassStmt;
1472 #define OPCLASS_ITEM_OPERATOR 1
1473 #define OPCLASS_ITEM_FUNCTION 2
1474 #define OPCLASS_ITEM_STORAGETYPE 3
1476 typedef struct CreateOpClassItem
1479 int itemtype; /* see codes above */
1480 /* fields used for an operator or function item: */
1481 List *name; /* operator or function name */
1482 List *args; /* argument types */
1483 int number; /* strategy num or support proc num */
1484 List *class_args; /* only used for functions */
1485 /* fields used for a storagetype item: */
1486 TypeName *storedtype; /* datatype stored in index */
1487 } CreateOpClassItem;
1489 /* ----------------------
1490 * Create Operator Family Statement
1491 * ----------------------
1493 typedef struct CreateOpFamilyStmt
1496 List *opfamilyname; /* qualified name (list of Value strings) */
1497 char *amname; /* name of index AM opfamily is for */
1498 } CreateOpFamilyStmt;
1500 /* ----------------------
1501 * Alter Operator Family Statement
1502 * ----------------------
1504 typedef struct AlterOpFamilyStmt
1507 List *opfamilyname; /* qualified name (list of Value strings) */
1508 char *amname; /* name of index AM opfamily is for */
1509 bool isDrop; /* ADD or DROP the items? */
1510 List *items; /* List of CreateOpClassItem nodes */
1511 } AlterOpFamilyStmt;
1513 /* ----------------------
1514 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
1515 * ----------------------
1518 typedef struct DropStmt
1521 List *objects; /* list of sublists of names (as Values) */
1522 ObjectType removeType; /* object type */
1523 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1524 bool missing_ok; /* skip error if object is missing? */
1527 /* ----------------------
1528 * Drop Rule|Trigger Statement
1530 * In general this may be used for dropping any property of a relation;
1531 * for example, someday soon we may have DROP ATTRIBUTE.
1532 * ----------------------
1535 typedef struct DropPropertyStmt
1538 RangeVar *relation; /* owning relation */
1539 char *property; /* name of rule, trigger, etc */
1540 ObjectType removeType; /* OBJECT_RULE or OBJECT_TRIGGER */
1541 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1542 bool missing_ok; /* skip error if missing? */
1545 /* ----------------------
1546 * Truncate Table Statement
1547 * ----------------------
1549 typedef struct TruncateStmt
1552 List *relations; /* relations (RangeVars) to be truncated */
1553 bool restart_seqs; /* restart owned sequences? */
1554 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1557 /* ----------------------
1558 * Comment On Statement
1559 * ----------------------
1561 typedef struct CommentStmt
1564 ObjectType objtype; /* Object's type */
1565 List *objname; /* Qualified name of the object */
1566 List *objargs; /* Arguments if needed (eg, for functions) */
1567 char *comment; /* Comment to insert, or NULL to remove */
1570 /* ----------------------
1571 * Declare Cursor Statement
1573 * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar
1574 * output. After parse analysis it's set to null, and the Query points to the
1575 * DeclareCursorStmt, not vice versa.
1576 * ----------------------
1578 #define CURSOR_OPT_BINARY 0x0001 /* BINARY */
1579 #define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */
1580 #define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */
1581 #define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */
1582 #define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */
1583 #define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */
1585 typedef struct DeclareCursorStmt
1588 char *portalname; /* name of the portal (cursor) */
1589 int options; /* bitmask of options (see above) */
1590 Node *query; /* the raw SELECT query */
1591 } DeclareCursorStmt;
1593 /* ----------------------
1594 * Close Portal Statement
1595 * ----------------------
1597 typedef struct ClosePortalStmt
1600 char *portalname; /* name of the portal (cursor) */
1601 /* NULL means CLOSE ALL */
1604 /* ----------------------
1605 * Fetch Statement (also Move)
1606 * ----------------------
1608 typedef enum FetchDirection
1610 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1613 /* for these, howMany indicates a position; only one row is fetched */
1618 #define FETCH_ALL LONG_MAX
1620 typedef struct FetchStmt
1623 FetchDirection direction; /* see above */
1624 long howMany; /* number of rows, or position argument */
1625 char *portalname; /* name of portal (cursor) */
1626 bool ismove; /* TRUE if MOVE */
1629 /* ----------------------
1630 * Create Index Statement
1631 * ----------------------
1633 typedef struct IndexStmt
1636 char *idxname; /* name of new index, or NULL for default */
1637 RangeVar *relation; /* relation to build index on */
1638 char *accessMethod; /* name of access method (eg. btree) */
1639 char *tableSpace; /* tablespace, or NULL for default */
1640 List *indexParams; /* a list of IndexElem */
1641 List *options; /* options from WITH clause */
1642 Node *whereClause; /* qualification (partial-index predicate) */
1643 bool unique; /* is index unique? */
1644 bool primary; /* is index on primary key? */
1645 bool isconstraint; /* is it from a CONSTRAINT clause? */
1646 bool concurrent; /* should this be a concurrent index build? */
1649 /* ----------------------
1650 * Create Function Statement
1651 * ----------------------
1653 typedef struct CreateFunctionStmt
1656 bool replace; /* T => replace if already exists */
1657 List *funcname; /* qualified name of function to create */
1658 List *parameters; /* a list of FunctionParameter */
1659 TypeName *returnType; /* the return type */
1660 List *options; /* a list of DefElem */
1661 List *withClause; /* a list of DefElem */
1662 } CreateFunctionStmt;
1664 typedef enum FunctionParameterMode
1666 /* the assigned enum values appear in pg_proc, don't change 'em! */
1667 FUNC_PARAM_IN = 'i', /* input only */
1668 FUNC_PARAM_OUT = 'o', /* output only */
1669 FUNC_PARAM_INOUT = 'b', /* both */
1670 FUNC_PARAM_VARIADIC = 'v', /* variadic */
1671 FUNC_PARAM_TABLE = 't' /* table function output column */
1672 } FunctionParameterMode;
1674 typedef struct FunctionParameter
1677 char *name; /* parameter name, or NULL if not given */
1678 TypeName *argType; /* TypeName for parameter type */
1679 FunctionParameterMode mode; /* IN/OUT/INOUT */
1680 } FunctionParameter;
1682 typedef struct AlterFunctionStmt
1685 FuncWithArgs *func; /* name and args of function */
1686 List *actions; /* list of DefElem */
1687 } AlterFunctionStmt;
1689 /* ----------------------
1690 * Drop {Function|Aggregate|Operator} Statement
1691 * ----------------------
1693 typedef struct RemoveFuncStmt
1696 ObjectType kind; /* function, aggregate, operator */
1697 List *name; /* qualified name of object to drop */
1698 List *args; /* types of the arguments */
1699 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1700 bool missing_ok; /* skip error if missing? */
1703 /* ----------------------
1704 * Drop Operator Class Statement
1705 * ----------------------
1707 typedef struct RemoveOpClassStmt
1710 List *opclassname; /* qualified name (list of Value strings) */
1711 char *amname; /* name of index AM opclass is for */
1712 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1713 bool missing_ok; /* skip error if missing? */
1714 } RemoveOpClassStmt;
1716 /* ----------------------
1717 * Drop Operator Family Statement
1718 * ----------------------
1720 typedef struct RemoveOpFamilyStmt
1723 List *opfamilyname; /* qualified name (list of Value strings) */
1724 char *amname; /* name of index AM opfamily is for */
1725 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1726 bool missing_ok; /* skip error if missing? */
1727 } RemoveOpFamilyStmt;
1729 /* ----------------------
1730 * Alter Object Rename Statement
1731 * ----------------------
1733 typedef struct RenameStmt
1736 ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
1737 RangeVar *relation; /* in case it's a table */
1738 List *object; /* in case it's some other object */
1739 List *objarg; /* argument types, if applicable */
1740 char *subname; /* name of contained object (column, rule,
1742 char *newname; /* the new name */
1745 /* ----------------------
1746 * ALTER object SET SCHEMA Statement
1747 * ----------------------
1749 typedef struct AlterObjectSchemaStmt
1752 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1753 RangeVar *relation; /* in case it's a table */
1754 List *object; /* in case it's some other object */
1755 List *objarg; /* argument types, if applicable */
1756 char *addname; /* additional name if needed */
1757 char *newschema; /* the new schema */
1758 } AlterObjectSchemaStmt;
1760 /* ----------------------
1761 * Alter Object Owner Statement
1762 * ----------------------
1764 typedef struct AlterOwnerStmt
1767 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1768 RangeVar *relation; /* in case it's a table */
1769 List *object; /* in case it's some other object */
1770 List *objarg; /* argument types, if applicable */
1771 char *addname; /* additional name if needed */
1772 char *newowner; /* the new owner */
1776 /* ----------------------
1777 * Create Rule Statement
1778 * ----------------------
1780 typedef struct RuleStmt
1783 RangeVar *relation; /* relation the rule is for */
1784 char *rulename; /* name of the rule */
1785 Node *whereClause; /* qualifications */
1786 CmdType event; /* SELECT, INSERT, etc */
1787 bool instead; /* is a 'do instead'? */
1788 List *actions; /* the action statements */
1789 bool replace; /* OR REPLACE */
1792 /* ----------------------
1794 * ----------------------
1796 typedef struct NotifyStmt
1799 char *conditionname; /* condition name to notify */
1802 /* ----------------------
1804 * ----------------------
1806 typedef struct ListenStmt
1809 char *conditionname; /* condition name to listen on */
1812 /* ----------------------
1813 * Unlisten Statement
1814 * ----------------------
1816 typedef struct UnlistenStmt
1819 char *conditionname; /* name to unlisten on, or NULL for all */
1822 /* ----------------------
1823 * {Begin|Commit|Rollback} Transaction Statement
1824 * ----------------------
1826 typedef enum TransactionStmtKind
1829 TRANS_STMT_START, /* semantically identical to BEGIN */
1831 TRANS_STMT_ROLLBACK,
1832 TRANS_STMT_SAVEPOINT,
1834 TRANS_STMT_ROLLBACK_TO,
1836 TRANS_STMT_COMMIT_PREPARED,
1837 TRANS_STMT_ROLLBACK_PREPARED
1838 } TransactionStmtKind;
1840 typedef struct TransactionStmt
1843 TransactionStmtKind kind; /* see above */
1844 List *options; /* for BEGIN/START and savepoint commands */
1845 char *gid; /* for two-phase-commit related commands */
1848 /* ----------------------
1849 * Create Type Statement, composite types
1850 * ----------------------
1852 typedef struct CompositeTypeStmt
1855 RangeVar *typevar; /* the composite type to be created */
1856 List *coldeflist; /* list of ColumnDef nodes */
1857 } CompositeTypeStmt;
1859 /* ----------------------
1860 * Create Type Statement, enum types
1861 * ----------------------
1863 typedef struct CreateEnumStmt
1866 List *typename; /* qualified name (list of Value strings) */
1867 List *vals; /* enum values (list of Value strings) */
1871 /* ----------------------
1872 * Create View Statement
1873 * ----------------------
1875 typedef struct ViewStmt
1878 RangeVar *view; /* the view to be created */
1879 List *aliases; /* target column names */
1880 Node *query; /* the SELECT query */
1881 bool replace; /* replace an existing view? */
1884 /* ----------------------
1886 * ----------------------
1888 typedef struct LoadStmt
1891 char *filename; /* file to load */
1894 /* ----------------------
1895 * Createdb Statement
1896 * ----------------------
1898 typedef struct CreatedbStmt
1901 char *dbname; /* name of database to create */
1902 List *options; /* List of DefElem nodes */
1905 /* ----------------------
1907 * ----------------------
1909 typedef struct AlterDatabaseStmt
1912 char *dbname; /* name of database to alter */
1913 List *options; /* List of DefElem nodes */
1914 } AlterDatabaseStmt;
1916 typedef struct AlterDatabaseSetStmt
1919 char *dbname; /* database name */
1920 VariableSetStmt *setstmt; /* SET or RESET subcommand */
1921 } AlterDatabaseSetStmt;
1923 /* ----------------------
1925 * ----------------------
1927 typedef struct DropdbStmt
1930 char *dbname; /* database to drop */
1931 bool missing_ok; /* skip error if db is missing? */
1934 /* ----------------------
1935 * Cluster Statement (support pbrown's cluster index implementation)
1936 * ----------------------
1938 typedef struct ClusterStmt
1941 RangeVar *relation; /* relation being indexed, or NULL if all */
1942 char *indexname; /* original index defined */
1945 /* ----------------------
1946 * Vacuum and Analyze Statements
1948 * Even though these are nominally two statements, it's convenient to use
1949 * just one node type for both.
1950 * ----------------------
1952 typedef struct VacuumStmt
1955 bool vacuum; /* do VACUUM step */
1956 bool full; /* do FULL (non-concurrent) vacuum */
1957 bool analyze; /* do ANALYZE step */
1958 bool verbose; /* print progress info */
1959 int freeze_min_age; /* min freeze age, or -1 to use default */
1960 RangeVar *relation; /* single table to process, or NULL */
1961 List *va_cols; /* list of column names, or NIL for all */
1964 /* ----------------------
1966 * ----------------------
1968 typedef struct ExplainStmt
1971 Node *query; /* the query (as a raw parse tree) */
1972 bool verbose; /* print plan info */
1973 bool analyze; /* get statistics by executing plan */
1976 /* ----------------------
1977 * Checkpoint Statement
1978 * ----------------------
1980 typedef struct CheckPointStmt
1985 /* ----------------------
1987 * ----------------------
1990 typedef enum DiscardMode
1997 typedef struct DiscardStmt
2003 /* ----------------------
2005 * ----------------------
2007 typedef struct LockStmt
2010 List *relations; /* relations to lock */
2011 int mode; /* lock mode */
2012 bool nowait; /* no wait mode */
2015 /* ----------------------
2016 * SET CONSTRAINTS Statement
2017 * ----------------------
2019 typedef struct ConstraintsSetStmt
2022 List *constraints; /* List of names as RangeVars */
2024 } ConstraintsSetStmt;
2026 /* ----------------------
2028 * ----------------------
2030 typedef struct ReindexStmt
2033 ObjectType kind; /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_DATABASE */
2034 RangeVar *relation; /* Table or index to reindex */
2035 const char *name; /* name of database to reindex */
2036 bool do_system; /* include system tables in database case */
2037 bool do_user; /* include user tables in database case */
2040 /* ----------------------
2041 * CREATE CONVERSION Statement
2042 * ----------------------
2044 typedef struct CreateConversionStmt
2047 List *conversion_name; /* Name of the conversion */
2048 char *for_encoding_name; /* source encoding name */
2049 char *to_encoding_name; /* destination encoding name */
2050 List *func_name; /* qualified conversion function name */
2051 bool def; /* is this a default conversion? */
2052 } CreateConversionStmt;
2054 /* ----------------------
2055 * CREATE CAST Statement
2056 * ----------------------
2058 typedef struct CreateCastStmt
2061 TypeName *sourcetype;
2062 TypeName *targettype;
2064 CoercionContext context;
2067 /* ----------------------
2068 * DROP CAST Statement
2069 * ----------------------
2071 typedef struct DropCastStmt
2074 TypeName *sourcetype;
2075 TypeName *targettype;
2076 DropBehavior behavior;
2077 bool missing_ok; /* skip error if missing? */
2081 /* ----------------------
2083 * ----------------------
2085 typedef struct PrepareStmt
2088 char *name; /* Name of plan, arbitrary */
2089 List *argtypes; /* Types of parameters (List of TypeName) */
2090 Node *query; /* The query itself (as a raw parsetree) */
2094 /* ----------------------
2096 * ----------------------
2099 typedef struct ExecuteStmt
2102 char *name; /* The name of the plan to execute */
2103 IntoClause *into; /* Optional table to store results in */
2104 List *params; /* Values to assign to parameters */
2108 /* ----------------------
2109 * DEALLOCATE Statement
2110 * ----------------------
2112 typedef struct DeallocateStmt
2115 char *name; /* The name of the plan to remove */
2116 /* NULL means DEALLOCATE ALL */
2120 * DROP OWNED statement
2122 typedef struct DropOwnedStmt
2126 DropBehavior behavior;
2130 * REASSIGN OWNED statement
2132 typedef struct ReassignOwnedStmt
2137 } ReassignOwnedStmt;
2140 * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
2142 typedef struct AlterTSDictionaryStmt
2145 List *dictname; /* qualified name (list of Value strings) */
2146 List *options; /* List of DefElem nodes */
2147 } AlterTSDictionaryStmt;
2150 * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
2152 typedef struct AlterTSConfigurationStmt
2155 List *cfgname; /* qualified name (list of Value strings) */
2158 * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is
2159 * NIL, but tokentype isn't, DROP MAPPING was specified.
2161 List *tokentype; /* list of Value strings */
2162 List *dicts; /* list of list of Value strings */
2163 bool override; /* if true - remove old variant */
2164 bool replace; /* if true - replace dictionary by another */
2165 bool missing_ok; /* for DROP - skip error if missing? */
2166 } AlterTSConfigurationStmt;
2168 #endif /* PARSENODES_H */