1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
7 * Portions Copyright (c) 1996-2006, 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.320 2006/08/02 01:59:47 joe 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 */
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 /* What to do at commit time for temporary relations */
31 typedef enum OnCommitAction
33 ONCOMMIT_NOOP, /* No ON COMMIT clause (do nothing) */
34 ONCOMMIT_PRESERVE_ROWS, /* ON COMMIT PRESERVE ROWS (do nothing) */
35 ONCOMMIT_DELETE_ROWS, /* ON COMMIT DELETE ROWS */
36 ONCOMMIT_DROP /* ON COMMIT DROP */
41 * Grantable rights are encoded so that we can OR them together in a bitmask.
42 * The present representation of AclItem limits us to 16 distinct rights,
43 * even though AclMode is defined as uint32. See utils/acl.h.
45 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
47 typedef uint32 AclMode; /* a bitmask of privilege bits */
49 #define ACL_INSERT (1<<0) /* for relations */
50 #define ACL_SELECT (1<<1)
51 #define ACL_UPDATE (1<<2)
52 #define ACL_DELETE (1<<3)
53 #define ACL_RULE (1<<4)
54 #define ACL_REFERENCES (1<<5)
55 #define ACL_TRIGGER (1<<6)
56 #define ACL_EXECUTE (1<<7) /* for functions */
57 #define ACL_USAGE (1<<8) /* for languages and namespaces */
58 #define ACL_CREATE (1<<9) /* for namespaces and databases */
59 #define ACL_CREATE_TEMP (1<<10) /* for databases */
60 #define ACL_CONNECT (1<<11) /* for databases */
61 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */
62 #define ACL_NO_RIGHTS 0
63 /* Currently, SELECT ... FOR UPDATE/FOR SHARE requires UPDATE privileges */
64 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE
67 /*****************************************************************************
69 *****************************************************************************/
73 * all statements are turned into a Query tree (via transformStmt)
74 * for further processing by the optimizer
76 * utility statements (i.e. non-optimizable statements) have the
77 * utilityStmt field set, and the Query itself is mostly dummy.
83 CmdType commandType; /* select|insert|update|delete|utility */
85 QuerySource querySource; /* where did I come from? */
87 bool canSetTag; /* do I set the command result tag? */
89 Node *utilityStmt; /* non-null if this is a non-optimizable
92 int resultRelation; /* target relation (index into rtable) */
94 RangeVar *into; /* target relation for SELECT INTO */
95 List *intoOptions; /* options from WITH clause */
96 OnCommitAction intoOnCommit; /* what do we do at COMMIT? */
97 char *intoTableSpaceName; /* table space to use, or NULL */
99 bool hasAggs; /* has aggregates in tlist or havingQual */
100 bool hasSubLinks; /* has subquery SubLink */
102 List *rtable; /* list of range table entries */
103 FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */
105 List *targetList; /* target list (of TargetEntry) */
107 List *groupClause; /* a list of GroupClause's */
109 Node *havingQual; /* qualifications applied to groups */
111 List *distinctClause; /* a list of SortClause's */
113 List *sortClause; /* a list of SortClause's */
115 Node *limitOffset; /* # of result tuples to skip (int8 expr) */
116 Node *limitCount; /* # of result tuples to return (int8 expr) */
118 List *rowMarks; /* a list of RowMarkClause's */
120 Node *setOperations; /* set-operation tree if this is top level of
121 * a UNION/INTERSECT/EXCEPT query */
124 * If the resultRelation turns out to be the parent of an inheritance
125 * tree, the planner will add all the child tables to the rtable and store
126 * a list of the rtindexes of all the result relations here. This is done
127 * at plan time, not parse time, since we don't want to commit to the
128 * exact set of child tables at parse time. This field ought to go in
129 * some sort of TopPlan plan node, not in the Query.
131 List *resultRelations; /* integer list of RT indexes, or NIL */
135 /****************************************************************************
136 * Supporting data structures for Parse Trees
138 * Most of these node types appear in raw parsetrees output by the grammar,
139 * and get transformed to something else by the analyzer. A few of them
140 * are used as-is in transformed querytrees.
142 * Many of the node types used in raw parsetrees include a "location" field.
143 * This is a byte (not character) offset in the original source text, to be
144 * used for positioning an error cursor when there is an analysis-time
145 * error related to the node.
146 ****************************************************************************/
149 * TypeName - specifies a type in definitions
151 * For TypeName structures generated internally, it is often easier to
152 * specify the type by OID than by name. If "names" is NIL then the
153 * actual type OID is given by typeid, otherwise typeid is unused.
155 * If pct_type is TRUE, then names is actually a field name and we look up
156 * the type of that field. Otherwise (the normal case), names is a type
157 * name possibly qualified with schema and database name.
159 typedef struct TypeName
162 List *names; /* qualified name (list of Value strings) */
163 Oid typeid; /* type identified by OID */
164 bool timezone; /* timezone specified? */
165 bool setof; /* is a set? */
166 bool pct_type; /* %TYPE specified? */
167 int32 typmod; /* type modifier */
168 List *arrayBounds; /* array bounds */
169 int location; /* token location, or -1 if unknown */
173 * ColumnRef - specifies a reference to a column, or possibly a whole tuple
175 * The "fields" list must be nonempty; its last component may be "*"
176 * instead of a regular field name.
178 * Note: any array subscripting or selection of fields from composite columns
179 * is represented by an A_Indirection node above the ColumnRef. However,
180 * for simplicity in the normal case, initial field selection from a table
181 * name is represented within ColumnRef and not by adding A_Indirection.
183 typedef struct ColumnRef
186 List *fields; /* field names (list of Value strings) */
187 int location; /* token location, or -1 if unknown */
191 * ParamRef - specifies a $n parameter reference
193 typedef struct ParamRef
196 int number; /* the number of the parameter */
200 * A_Expr - infix, prefix, and postfix expressions
202 typedef enum A_Expr_Kind
204 AEXPR_OP, /* normal operator */
205 AEXPR_AND, /* booleans - name field is unused */
208 AEXPR_OP_ANY, /* scalar op ANY (array) */
209 AEXPR_OP_ALL, /* scalar op ALL (array) */
210 AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */
211 AEXPR_NULLIF, /* NULLIF - name must be "=" */
212 AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */
213 AEXPR_IN /* [NOT] IN - name must be "=" or "<>" */
216 typedef struct A_Expr
219 A_Expr_Kind kind; /* see above */
220 List *name; /* possibly-qualified name of operator */
221 Node *lexpr; /* left argument, or NULL if none */
222 Node *rexpr; /* right argument, or NULL if none */
223 int location; /* token location, or -1 if unknown */
227 * A_Const - a constant expression
229 typedef struct A_Const
232 Value val; /* the value (with the tag) */
233 TypeName *typename; /* typecast, or NULL if none */
237 * TypeCast - a CAST expression
239 * NOTE: for mostly historical reasons, A_Const parsenodes contain
240 * room for a TypeName; we only generate a separate TypeCast node if the
241 * argument to be casted is not a constant. In theory either representation
242 * would work, but the combined representation saves a bit of code in many
243 * productions in gram.y.
245 typedef struct TypeCast
248 Node *arg; /* the expression being casted */
249 TypeName *typename; /* the target type */
253 * FuncCall - a function or aggregate invocation
255 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
256 * indicates we saw 'foo(DISTINCT ...)'. In either case, the construct
257 * *must* be an aggregate call. Otherwise, it might be either an
258 * aggregate or some other kind of function.
260 typedef struct FuncCall
263 List *funcname; /* qualified name of function */
264 List *args; /* the arguments (list of exprs) */
265 bool agg_star; /* argument was really '*' */
266 bool agg_distinct; /* arguments were labeled DISTINCT */
267 int location; /* token location, or -1 if unknown */
271 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
273 typedef struct A_Indices
276 Node *lidx; /* could be NULL */
281 * A_Indirection - select a field and/or array element from an expression
283 * The indirection list can contain both A_Indices nodes (representing
284 * subscripting) and string Value nodes (representing field selection
285 * --- the string value is the name of the field to select). For example,
286 * a complex selection operation like
287 * (foo).field1[42][7].field2
288 * would be represented with a single A_Indirection node having a 4-element
291 * Note: as of Postgres 8.0, we don't support arrays of composite values,
292 * so cases in which a field select follows a subscript aren't actually
293 * semantically legal. However the parser is prepared to handle such.
295 typedef struct A_Indirection
298 Node *arg; /* the thing being selected from */
299 List *indirection; /* subscripts and/or field names */
304 * result target (used in target list of pre-transformed parse trees)
306 * In a SELECT target list, 'name' is the column label from an
307 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
308 * value expression itself. The 'indirection' field is not used.
310 * INSERT uses ResTarget in its target-column-names list. Here, 'name' is
311 * the name of the destination column, 'indirection' stores any subscripts
312 * attached to the destination, and 'val' is not used.
314 * In an UPDATE target list, 'name' is the name of the destination column,
315 * 'indirection' stores any subscripts attached to the destination, and
316 * 'val' is the expression to assign.
318 * See A_Indirection for more info about what can appear in 'indirection'.
320 typedef struct ResTarget
323 char *name; /* column name or NULL */
324 List *indirection; /* subscripts and field names, or NIL */
325 Node *val; /* the value expression to compute or assign */
326 int location; /* token location, or -1 if unknown */
330 * SortBy - for ORDER BY clause
333 #define SORTBY_DESC 2
334 #define SORTBY_USING 3
336 typedef struct SortBy
339 int sortby_kind; /* see codes above */
340 List *useOp; /* name of op to use, if SORTBY_USING */
341 Node *node; /* expression to sort on */
345 * RangeSubselect - subquery appearing in a FROM clause
347 typedef struct RangeSubselect
350 Node *subquery; /* the untransformed sub-select clause */
351 Alias *alias; /* table alias & optional column aliases */
355 * RangeFunction - function call appearing in a FROM clause
357 typedef struct RangeFunction
360 Node *funccallnode; /* untransformed function call tree */
361 Alias *alias; /* table alias & optional column aliases */
362 List *coldeflist; /* list of ColumnDef nodes to describe
363 * result of function returning RECORD */
367 * ColumnDef - column definition (used in various creates)
369 * If the column has a default value, we may have the value expression
370 * in either "raw" form (an untransformed parse tree) or "cooked" form
371 * (the nodeToString representation of an executable expression tree),
372 * depending on how this ColumnDef node was created (by parsing, or by
373 * inheritance from an existing relation). We should never have both
376 * The constraints list may contain a CONSTR_DEFAULT item in a raw
377 * parsetree produced by gram.y, but transformCreateStmt will remove
378 * the item and set raw_default instead. CONSTR_DEFAULT items
379 * should not appear in any subsequent processing.
381 * The "support" field, if not null, denotes a supporting relation that
382 * should be linked by an internal dependency to the column. Currently
383 * this is only used to link a SERIAL column's sequence to the column.
385 typedef struct ColumnDef
388 char *colname; /* name of column */
389 TypeName *typename; /* type of column */
390 int inhcount; /* number of times column is inherited */
391 bool is_local; /* column has local (non-inherited) def'n */
392 bool is_not_null; /* NOT NULL constraint specified? */
393 Node *raw_default; /* default value (untransformed parse tree) */
394 char *cooked_default; /* nodeToString representation */
395 List *constraints; /* other constraints on column */
396 RangeVar *support; /* supporting relation, if any */
400 * inhRelation - Relations a CREATE TABLE is to inherit attributes of
402 typedef struct InhRelation
410 * IndexElem - index parameters (used in CREATE INDEX)
412 * For a plain index attribute, 'name' is the name of the table column to
413 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and
414 * 'expr' is the expression tree.
416 typedef struct IndexElem
419 char *name; /* name of attribute to index, or NULL */
420 Node *expr; /* expression to index, or NULL */
421 List *opclass; /* name of desired opclass; NIL = default */
426 * a definition (used in definition lists in the form of defname = arg)
428 typedef struct DefElem
432 Node *arg; /* a (Value *) or a (TypeName *) */
436 * LockingClause - raw representation of FOR UPDATE/SHARE options
438 * Note: lockedRels == NIL means "all relations in query". Otherwise it
439 * is a list of String nodes giving relation eref names.
441 typedef struct LockingClause
444 List *lockedRels; /* FOR UPDATE or FOR SHARE relations */
445 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
446 bool noWait; /* NOWAIT option */
450 /****************************************************************************
451 * Nodes for a Query tree
452 ****************************************************************************/
454 /*--------------------
456 * A range table is a List of RangeTblEntry nodes.
458 * A range table entry may represent a plain relation, a sub-select in
459 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax
460 * produces an RTE, not the implicit join resulting from multiple FROM
461 * items. This is because we only need the RTE to deal with SQL features
462 * like outer joins and join-output-column aliasing.) Other special
463 * RTE types also exist, as indicated by RTEKind.
465 * alias is an Alias node representing the AS alias-clause attached to the
466 * FROM expression, or NULL if no clause.
468 * eref is the table reference name and column reference names (either
469 * real or aliases). Note that system columns (OID etc) are not included
470 * in the column list.
471 * eref->aliasname is required to be present, and should generally be used
472 * to identify the RTE for error messages etc.
474 * In RELATION RTEs, the colnames in both alias and eref are indexed by
475 * physical attribute number; this means there must be colname entries for
476 * dropped columns. When building an RTE we insert empty strings ("") for
477 * dropped columns. Note however that a stored rule may have nonempty
478 * colnames for columns dropped since the rule was created (and for that
479 * matter the colnames might be out of date due to column renamings).
480 * The same comments apply to FUNCTION RTEs when the function's return type
481 * is a named composite type.
483 * In JOIN RTEs, the colnames in both alias and eref are one-to-one with
484 * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when
485 * those columns are known to be dropped at parse time. Again, however,
486 * a stored rule might contain entries for columns dropped since the rule
487 * was created. (This is only possible for columns not actually referenced
488 * in the rule.) When loading a stored rule, we replace the joinaliasvars
489 * items for any such columns with NULL Consts. (We can't simply delete
490 * them from the joinaliasvars list, because that would affect the attnums
491 * of Vars referencing the rest of the list.)
493 * inh is TRUE for relation references that should be expanded to include
494 * inheritance children, if the rel has any. This *must* be FALSE for
495 * RTEs other than RTE_RELATION entries.
497 * inFromCl marks those range variables that are listed in the FROM clause.
498 * It's false for RTEs that are added to a query behind the scenes, such
499 * as the NEW and OLD variables for a rule, or the subqueries of a UNION.
500 * This flag is not used anymore during parsing, since the parser now uses
501 * a separate "namespace" data structure to control visibility, but it is
502 * needed by ruleutils.c to determine whether RTEs should be shown in
503 * decompiled queries.
505 * requiredPerms and checkAsUser specify run-time access permissions
506 * checks to be performed at query startup. The user must have *all*
507 * of the permissions that are OR'd together in requiredPerms (zero
508 * indicates no permissions checking). If checkAsUser is not zero,
509 * then do the permissions checks using the access rights of that user,
510 * not the current effective user ID. (This allows rules to act as
512 *--------------------
516 RTE_RELATION, /* ordinary relation reference */
517 RTE_SUBQUERY, /* subquery in FROM */
519 RTE_SPECIAL, /* special rule relation (NEW or OLD) */
520 RTE_FUNCTION, /* function in FROM */
521 RTE_VALUES /* VALUES (<exprlist>), (<exprlist>), ... */
524 typedef struct RangeTblEntry
528 RTEKind rtekind; /* see above */
531 * XXX the fields applicable to only some rte kinds should be merged into
532 * a union. I didn't do this yet because the diffs would impact a lot of
533 * code that is being actively worked on. FIXME later.
537 * Fields valid for a plain relation RTE (else zero):
539 Oid relid; /* OID of the relation */
542 * Fields valid for a subquery RTE (else NULL):
544 Query *subquery; /* the sub-query */
547 * Fields valid for a function RTE (else NULL):
549 * If the function returns RECORD, funccoltypes lists the column types
550 * declared in the RTE's column type specification, and funccoltypmods
551 * lists their declared typmods. Otherwise, both fields are NIL.
553 Node *funcexpr; /* expression tree for func call */
554 List *funccoltypes; /* OID list of column type OIDs */
555 List *funccoltypmods; /* integer list of column typmods */
558 * Fields valid for a values RTE (else NIL):
560 List *values_lists; /* list of expression lists */
563 * Fields valid for a join RTE (else NULL/zero):
565 * joinaliasvars is a list of Vars or COALESCE expressions corresponding
566 * to the columns of the join result. An alias Var referencing column K
567 * of the join result can be replaced by the K'th element of joinaliasvars
568 * --- but to simplify the task of reverse-listing aliases correctly, we
569 * do not do that until planning time. In a Query loaded from a stored
570 * rule, it is also possible for joinaliasvars items to be NULL Consts,
571 * denoting columns dropped since the rule was made.
573 JoinType jointype; /* type of join */
574 List *joinaliasvars; /* list of alias-var expansions */
577 * Fields valid in all RTEs:
579 Alias *alias; /* user-written alias clause, if any */
580 Alias *eref; /* expanded reference names */
581 bool inh; /* inheritance requested? */
582 bool inFromCl; /* present in FROM clause? */
583 AclMode requiredPerms; /* bitmask of required access permissions */
584 Oid checkAsUser; /* if valid, check access as this role */
589 * representation of ORDER BY clauses
591 * tleSortGroupRef must match ressortgroupref of exactly one entry of the
592 * associated targetlist; that is the expression to be sorted (or grouped) by.
593 * sortop is the OID of the ordering operator.
595 * SortClauses are also used to identify targets that we will do a "Unique"
596 * filter step on (for SELECT DISTINCT and SELECT DISTINCT ON). The
597 * distinctClause list is simply a copy of the relevant members of the
598 * sortClause list. Note that distinctClause can be a subset of sortClause,
599 * but cannot have members not present in sortClause; and the members that
600 * do appear must be in the same order as in sortClause.
602 typedef struct SortClause
605 Index tleSortGroupRef; /* reference into targetlist */
606 Oid sortop; /* the sort operator to use */
611 * representation of GROUP BY clauses
613 * GroupClause is exactly like SortClause except for the nodetag value
614 * (it's probably not even really necessary to have two different
615 * nodetags...). We have routines that operate interchangeably on both.
617 typedef SortClause GroupClause;
621 * representation of FOR UPDATE/SHARE clauses
623 * We create a separate RowMarkClause node for each target relation
625 typedef struct RowMarkClause
628 Index rti; /* range table index of target relation */
629 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
630 bool noWait; /* NOWAIT option */
633 /*****************************************************************************
634 * Optimizable Statements
635 *****************************************************************************/
637 /* ----------------------
640 * The source expression is represented by SelectStmt for both the
641 * SELECT and VALUES cases. If selectStmt is NULL, then the query
642 * is INSERT ... DEFAULT VALUES.
643 * ----------------------
645 typedef struct InsertStmt
648 RangeVar *relation; /* relation to insert into */
649 List *cols; /* optional: names of the target columns */
650 Node *selectStmt; /* the source SELECT/VALUES, or NULL */
653 /* ----------------------
655 * ----------------------
657 typedef struct DeleteStmt
660 RangeVar *relation; /* relation to delete from */
661 Node *whereClause; /* qualifications */
662 List *usingClause; /* optional using clause for more tables */
665 /* ----------------------
667 * ----------------------
669 typedef struct UpdateStmt
672 RangeVar *relation; /* relation to update */
673 List *targetList; /* the target list (of ResTarget) */
674 Node *whereClause; /* qualifications */
675 List *fromClause; /* optional from clause for more tables */
678 /* ----------------------
681 * A "simple" SELECT is represented in the output of gram.y by a single
682 * SelectStmt node; so is a VALUES construct. A query containing set
683 * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
684 * nodes, in which the leaf nodes are component SELECTs and the internal nodes
685 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node
686 * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
687 * LIMIT, etc, clause values into a SELECT statement without worrying
688 * whether it is a simple or compound SELECT.
689 * ----------------------
691 typedef enum SetOperation
699 typedef struct SelectStmt
704 * These fields are used only in "leaf" SelectStmts.
706 * into, intoColNames, intoOptions, intoOnCommit, and
707 * intoTableSpaceName are a kluge; they belong somewhere else...
709 List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
710 * lcons(NIL,NIL) for all (SELECT DISTINCT) */
711 RangeVar *into; /* target table (for select into table) */
712 List *intoColNames; /* column names for into table */
713 List *intoOptions; /* options from WITH clause */
714 OnCommitAction intoOnCommit; /* what do we do at COMMIT? */
715 char *intoTableSpaceName; /* table space to use, or NULL */
716 List *targetList; /* the target list (of ResTarget) */
717 List *fromClause; /* the FROM clause */
718 Node *whereClause; /* WHERE qualification */
719 List *groupClause; /* GROUP BY clauses */
720 Node *havingClause; /* HAVING conditional-expression */
723 * In a "leaf" node representing a VALUES list, the above fields are all
724 * null, and instead this field is set. Note that the elements of
725 * the sublists are just expressions, without ResTarget decoration.
726 * Also note that a list element can be DEFAULT (represented as a
727 * SetToDefault node), regardless of the context of the VALUES list.
728 * It's up to parse analysis to reject that where not valid.
730 List *valuesLists; /* untransformed list of expression lists */
733 * These fields are used in both "leaf" SelectStmts and upper-level
736 List *sortClause; /* sort clause (a list of SortBy's) */
737 Node *limitOffset; /* # of result tuples to skip */
738 Node *limitCount; /* # of result tuples to return */
739 List *lockingClause; /* FOR UPDATE (list of LockingClause's) */
742 * These fields are used only in upper-level SelectStmts.
744 SetOperation op; /* type of set op */
745 bool all; /* ALL specified? */
746 struct SelectStmt *larg; /* left child */
747 struct SelectStmt *rarg; /* right child */
748 /* Eventually add fields for CORRESPONDING spec here */
752 /* ----------------------
753 * Set Operation node for post-analysis query trees
755 * After parse analysis, a SELECT with set operations is represented by a
756 * top-level Query node containing the leaf SELECTs as subqueries in its
757 * range table. Its setOperations field shows the tree of set operations,
758 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
759 * nodes replaced by SetOperationStmt nodes.
760 * ----------------------
762 typedef struct SetOperationStmt
765 SetOperation op; /* type of set op */
766 bool all; /* ALL specified? */
767 Node *larg; /* left child */
768 Node *rarg; /* right child */
769 /* Eventually add fields for CORRESPONDING spec here */
771 /* Fields derived during parse analysis: */
772 List *colTypes; /* list of OIDs of output column types */
776 /*****************************************************************************
777 * Other Statements (no optimizations required)
779 * Some of them require a little bit of transformation (which is also
780 * done by transformStmt). The whole structure is then passed on to
781 * ProcessUtility (by-passing the optimization step) as the utilityStmt
783 *****************************************************************************/
786 * When a command can act on several kinds of objects with only one
787 * parse structure required, use these constants to designate the
791 typedef enum ObjectType
817 /* ----------------------
818 * Create Schema Statement
820 * NOTE: the schemaElts list contains raw parsetrees for component statements
821 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
822 * executed after the schema itself is created.
823 * ----------------------
825 typedef struct CreateSchemaStmt
828 char *schemaname; /* the name of the schema to create */
829 char *authid; /* the owner of the created schema */
830 List *schemaElts; /* schema components (list of parsenodes) */
833 typedef enum DropBehavior
835 DROP_RESTRICT, /* drop fails if any dependent objects */
836 DROP_CASCADE /* remove dependent objects too */
839 /* ----------------------
841 * ----------------------
843 typedef struct AlterTableStmt
846 RangeVar *relation; /* table to work on */
847 List *cmds; /* list of subcommands */
848 ObjectType relkind; /* type of object */
851 typedef enum AlterTableType
853 AT_AddColumn, /* add column */
854 AT_ColumnDefault, /* alter column default */
855 AT_DropNotNull, /* alter column drop not null */
856 AT_SetNotNull, /* alter column set not null */
857 AT_SetStatistics, /* alter column statistics */
858 AT_SetStorage, /* alter column storage */
859 AT_DropColumn, /* drop column */
860 AT_DropColumnRecurse, /* internal to commands/tablecmds.c */
861 AT_AddIndex, /* add index */
862 AT_ReAddIndex, /* internal to commands/tablecmds.c */
863 AT_AddConstraint, /* add constraint */
864 AT_ProcessedConstraint, /* pre-processed add constraint (local in
865 * parser/analyze.c) */
866 AT_DropConstraint, /* drop constraint */
867 AT_DropConstraintQuietly, /* drop constraint, no error/warning (local in
868 * commands/tablecmds.c) */
869 AT_AlterColumnType, /* alter column type */
870 AT_ChangeOwner, /* change owner */
871 AT_ClusterOn, /* CLUSTER ON */
872 AT_DropCluster, /* SET WITHOUT CLUSTER */
873 AT_DropOids, /* SET WITHOUT OIDS */
874 AT_SetTableSpace, /* SET TABLESPACE */
875 AT_SetRelOptions, /* SET (...) -- AM specific parameters */
876 AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */
877 AT_EnableTrig, /* ENABLE TRIGGER name */
878 AT_DisableTrig, /* DISABLE TRIGGER name */
879 AT_EnableTrigAll, /* ENABLE TRIGGER ALL */
880 AT_DisableTrigAll, /* DISABLE TRIGGER ALL */
881 AT_EnableTrigUser, /* ENABLE TRIGGER USER */
882 AT_DisableTrigUser, /* DISABLE TRIGGER USER */
883 AT_AddInherits, /* ADD INHERITS parent */
884 AT_DropInherits /* DROP INHERITS parent */
887 typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */
890 AlterTableType subtype; /* Type of table alteration to apply */
891 char *name; /* column, constraint, or trigger to act on,
892 * or new owner or tablespace */
893 RangeVar *parent; /* Parent table for add/drop inherits */
894 Node *def; /* definition of new column, column type,
895 * index, or constraint */
896 Node *transform; /* transformation expr for ALTER TYPE */
897 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
901 /* ----------------------
904 * The fields are used in different ways by the different variants of
906 * ----------------------
908 typedef struct AlterDomainStmt
911 char subtype; /*------------
912 * T = alter column default
913 * N = alter column drop not null
914 * O = alter column set not null
916 * X = drop constraint
919 List *typename; /* domain to work on */
920 char *name; /* column or constraint name to act on */
921 Node *def; /* definition of default or constraint */
922 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
926 /* ----------------------
927 * Grant|Revoke Statement
928 * ----------------------
930 typedef enum GrantObjectType
932 ACL_OBJECT_RELATION, /* table, view */
933 ACL_OBJECT_SEQUENCE, /* sequence */
934 ACL_OBJECT_DATABASE, /* database */
935 ACL_OBJECT_FUNCTION, /* function */
936 ACL_OBJECT_LANGUAGE, /* procedural language */
937 ACL_OBJECT_NAMESPACE, /* namespace */
938 ACL_OBJECT_TABLESPACE /* tablespace */
941 typedef struct GrantStmt
944 bool is_grant; /* true = GRANT, false = REVOKE */
945 GrantObjectType objtype; /* kind of object being operated on */
946 List *objects; /* list of RangeVar nodes, FuncWithArgs nodes,
947 * or plain names (as Value strings) */
948 List *privileges; /* list of privilege names (as Strings) */
949 /* privileges == NIL denotes "all privileges" */
950 List *grantees; /* list of PrivGrantee nodes */
951 bool grant_option; /* grant or revoke grant option */
952 DropBehavior behavior; /* drop behavior (for REVOKE) */
955 typedef struct PrivGrantee
958 char *rolname; /* if NULL then PUBLIC */
962 * Note: FuncWithArgs carries only the types of the input parameters of the
963 * function. So it is sufficient to identify an existing function, but it
964 * is not enough info to define a function nor to call it.
966 typedef struct FuncWithArgs
969 List *funcname; /* qualified name of function */
970 List *funcargs; /* list of Typename nodes */
973 /* This is only used internally in gram.y. */
974 typedef struct PrivTarget
977 GrantObjectType objtype;
981 /* ----------------------
982 * Grant/Revoke Role Statement
984 * Note: the lists of roles are lists of names, as Value strings
985 * ----------------------
987 typedef struct GrantRoleStmt
990 List *granted_roles; /* list of roles to be granted/revoked */
991 List *grantee_roles; /* list of member roles to add/delete */
992 bool is_grant; /* true = GRANT, false = REVOKE */
993 bool admin_opt; /* with admin option */
994 char *grantor; /* set grantor to other than current role */
995 DropBehavior behavior; /* drop behavior (for REVOKE) */
998 /* ----------------------
1000 * ----------------------
1002 typedef struct CopyStmt
1005 RangeVar *relation; /* the relation to copy */
1006 List *attlist; /* List of column names (as Strings), or NIL
1007 * for all columns */
1008 bool is_from; /* TO or FROM */
1009 char *filename; /* if NULL, use stdin/stdout */
1010 List *options; /* List of DefElem nodes */
1013 /* ----------------------
1014 * Create Table Statement
1016 * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
1017 * nodes are intermixed in tableElts, and constraints is NIL. After parse
1018 * analysis, tableElts contains just ColumnDefs, and constraints contains
1019 * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
1021 * ----------------------
1024 typedef struct CreateStmt
1027 RangeVar *relation; /* relation to create */
1028 List *tableElts; /* column definitions (list of ColumnDef) */
1029 List *inhRelations; /* relations to inherit from (list of
1031 List *constraints; /* constraints (list of Constraint nodes) */
1032 List *options; /* options from WITH clause */
1033 OnCommitAction oncommit; /* what do we do at COMMIT? */
1034 char *tablespacename; /* table space to use, or NULL */
1037 typedef enum CreateStmtLikeOption {
1038 CREATE_TABLE_LIKE_INCLUDING_DEFAULTS,
1039 CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS,
1040 CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS,
1041 CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS,
1042 CREATE_TABLE_LIKE_INCLUDING_INDEXES,
1043 CREATE_TABLE_LIKE_EXCLUDING_INDEXES
1044 } CreateStmtLikeOption;
1047 * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
1049 * XXX probably these ought to be unified with FkConstraints at some point?
1050 * To this end we include CONSTR_FOREIGN in the ConstrType enum, even though
1051 * the parser does not generate it.
1053 * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
1054 * we may have the expression in either "raw" form (an untransformed
1055 * parse tree) or "cooked" form (the nodeToString representation of
1056 * an executable expression tree), depending on how this Constraint
1057 * node was created (by parsing, or by inheritance from an existing
1058 * relation). We should never have both in the same node!
1060 * Constraint attributes (DEFERRABLE etc) are initially represented as
1061 * separate Constraint nodes for simplicity of parsing. analyze.c makes
1062 * a pass through the constraints list to attach the info to the appropriate
1063 * FkConstraint node (and, perhaps, someday to other kinds of constraints).
1067 typedef enum ConstrType /* types of constraints */
1069 CONSTR_NULL, /* not SQL92, but a lot of people expect it */
1076 CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
1077 CONSTR_ATTR_NOT_DEFERRABLE,
1078 CONSTR_ATTR_DEFERRED,
1079 CONSTR_ATTR_IMMEDIATE
1082 typedef struct Constraint
1086 char *name; /* name, or NULL if unnamed */
1087 Node *raw_expr; /* expr, as untransformed parse tree */
1088 char *cooked_expr; /* expr, as nodeToString representation */
1089 List *keys; /* String nodes naming referenced column(s) */
1090 List *options; /* options from WITH clause */
1091 char *indexspace; /* index tablespace for PKEY/UNIQUE
1092 * constraints; NULL for default */
1096 * Definitions for FOREIGN KEY constraints in CreateStmt
1098 * Note: FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
1099 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
1100 * stored into pg_constraint.confmatchtype. Changing the code values may
1101 * require an initdb!
1103 * If skip_validation is true then we skip checking that the existing rows
1104 * in the table satisfy the constraint, and just install the catalog entries
1105 * for the constraint. This is currently used only during CREATE TABLE
1106 * (when we know the table must be empty).
1109 #define FKCONSTR_ACTION_NOACTION 'a'
1110 #define FKCONSTR_ACTION_RESTRICT 'r'
1111 #define FKCONSTR_ACTION_CASCADE 'c'
1112 #define FKCONSTR_ACTION_SETNULL 'n'
1113 #define FKCONSTR_ACTION_SETDEFAULT 'd'
1115 #define FKCONSTR_MATCH_FULL 'f'
1116 #define FKCONSTR_MATCH_PARTIAL 'p'
1117 #define FKCONSTR_MATCH_UNSPECIFIED 'u'
1119 typedef struct FkConstraint
1122 char *constr_name; /* Constraint name, or NULL if unnamed */
1123 RangeVar *pktable; /* Primary key table */
1124 List *fk_attrs; /* Attributes of foreign key */
1125 List *pk_attrs; /* Corresponding attrs in PK table */
1126 char fk_matchtype; /* FULL, PARTIAL, UNSPECIFIED */
1127 char fk_upd_action; /* ON UPDATE action */
1128 char fk_del_action; /* ON DELETE action */
1129 bool deferrable; /* DEFERRABLE */
1130 bool initdeferred; /* INITIALLY DEFERRED */
1131 bool skip_validation; /* skip validation of existing rows? */
1135 /* ----------------------
1136 * Create/Drop Table Space Statements
1137 * ----------------------
1140 typedef struct CreateTableSpaceStmt
1143 char *tablespacename;
1146 } CreateTableSpaceStmt;
1148 typedef struct DropTableSpaceStmt
1151 char *tablespacename;
1152 bool missing_ok; /* skip error if a missing? */
1153 } DropTableSpaceStmt;
1155 /* ----------------------
1156 * Create/Drop TRIGGER Statements
1157 * ----------------------
1160 typedef struct CreateTrigStmt
1163 char *trigname; /* TRIGGER's name */
1164 RangeVar *relation; /* relation trigger is on */
1165 List *funcname; /* qual. name of function to call */
1166 List *args; /* list of (T_String) Values or NIL */
1167 bool before; /* BEFORE/AFTER */
1168 bool row; /* ROW/STATEMENT */
1169 char actions[4]; /* 1 to 3 of 'i', 'u', 'd', + trailing \0 */
1171 /* The following are used for referential */
1172 /* integrity constraint triggers */
1173 bool isconstraint; /* This is an RI trigger */
1174 bool deferrable; /* [NOT] DEFERRABLE */
1175 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
1176 RangeVar *constrrel; /* opposite relation */
1179 /* ----------------------
1180 * Create/Drop PROCEDURAL LANGUAGE Statement
1181 * ----------------------
1183 typedef struct CreatePLangStmt
1186 char *plname; /* PL name */
1187 List *plhandler; /* PL call handler function (qual. name) */
1188 List *plvalidator; /* optional validator function (qual. name) */
1189 bool pltrusted; /* PL is trusted */
1192 typedef struct DropPLangStmt
1195 char *plname; /* PL name */
1196 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1197 bool missing_ok; /* skip error if missing? */
1200 /* ----------------------
1201 * Create/Alter/Drop Role Statements
1203 * Note: these node types are also used for the backwards-compatible
1204 * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases
1205 * there's really no need to distinguish what the original spelling was,
1206 * but for CREATE we mark the type because the defaults vary.
1207 * ----------------------
1209 typedef enum RoleStmtType
1216 typedef struct CreateRoleStmt
1219 RoleStmtType stmt_type; /* ROLE/USER/GROUP */
1220 char *role; /* role name */
1221 List *options; /* List of DefElem nodes */
1224 typedef struct AlterRoleStmt
1227 char *role; /* role name */
1228 List *options; /* List of DefElem nodes */
1229 int action; /* +1 = add members, -1 = drop members */
1232 typedef struct AlterRoleSetStmt
1235 char *role; /* role name */
1236 char *variable; /* GUC variable name */
1237 List *value; /* value for variable, or NIL for Reset */
1240 typedef struct DropRoleStmt
1243 List *roles; /* List of roles to remove */
1244 bool missing_ok; /* skip error if a role is missing? */
1247 /* ----------------------
1248 * {Create|Alter} SEQUENCE Statement
1249 * ----------------------
1252 typedef struct CreateSeqStmt
1255 RangeVar *sequence; /* the sequence to create */
1259 typedef struct AlterSeqStmt
1262 RangeVar *sequence; /* the sequence to alter */
1266 /* ----------------------
1267 * Create {Aggregate|Operator|Type} Statement
1268 * ----------------------
1270 typedef struct DefineStmt
1273 ObjectType kind; /* aggregate, operator, type */
1274 bool oldstyle; /* hack to signal old CREATE AGG syntax */
1275 List *defnames; /* qualified name (list of Value strings) */
1276 List *args; /* a list of TypeName (if needed) */
1277 List *definition; /* a list of DefElem */
1280 /* ----------------------
1281 * Create Domain Statement
1282 * ----------------------
1284 typedef struct CreateDomainStmt
1287 List *domainname; /* qualified name (list of Value strings) */
1288 TypeName *typename; /* the base type */
1289 List *constraints; /* constraints (list of Constraint nodes) */
1292 /* ----------------------
1293 * Create Operator Class Statement
1294 * ----------------------
1296 typedef struct CreateOpClassStmt
1299 List *opclassname; /* qualified name (list of Value strings) */
1300 char *amname; /* name of index AM opclass is for */
1301 TypeName *datatype; /* datatype of indexed column */
1302 List *items; /* List of CreateOpClassItem nodes */
1303 bool isDefault; /* Should be marked as default for type? */
1304 } CreateOpClassStmt;
1306 #define OPCLASS_ITEM_OPERATOR 1
1307 #define OPCLASS_ITEM_FUNCTION 2
1308 #define OPCLASS_ITEM_STORAGETYPE 3
1310 typedef struct CreateOpClassItem
1313 int itemtype; /* see codes above */
1314 /* fields used for an operator or function item: */
1315 List *name; /* operator or function name */
1316 List *args; /* argument types */
1317 int number; /* strategy num or support proc num */
1318 bool recheck; /* only used for operators */
1319 /* fields used for a storagetype item: */
1320 TypeName *storedtype; /* datatype stored in index */
1321 } CreateOpClassItem;
1323 /* ----------------------
1324 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
1325 * ----------------------
1328 typedef struct DropStmt
1331 List *objects; /* list of sublists of names (as Values) */
1332 ObjectType removeType; /* object type */
1333 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1334 bool missing_ok; /* skip error if object is missing? */
1337 /* ----------------------
1338 * Drop Rule|Trigger Statement
1340 * In general this may be used for dropping any property of a relation;
1341 * for example, someday soon we may have DROP ATTRIBUTE.
1342 * ----------------------
1345 typedef struct DropPropertyStmt
1348 RangeVar *relation; /* owning relation */
1349 char *property; /* name of rule, trigger, etc */
1350 ObjectType removeType; /* OBJECT_RULE or OBJECT_TRIGGER */
1351 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1352 bool missing_ok; /* skip error if a missing? */
1355 /* ----------------------
1356 * Truncate Table Statement
1357 * ----------------------
1359 typedef struct TruncateStmt
1362 List *relations; /* relations (RangeVars) to be truncated */
1363 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1366 /* ----------------------
1367 * Comment On Statement
1368 * ----------------------
1370 typedef struct CommentStmt
1373 ObjectType objtype; /* Object's type */
1374 List *objname; /* Qualified name of the object */
1375 List *objargs; /* Arguments if needed (eg, for functions) */
1376 char *comment; /* Comment to insert, or NULL to remove */
1379 /* ----------------------
1380 * Declare Cursor Statement
1381 * ----------------------
1383 #define CURSOR_OPT_BINARY 0x0001
1384 #define CURSOR_OPT_SCROLL 0x0002
1385 #define CURSOR_OPT_NO_SCROLL 0x0004
1386 #define CURSOR_OPT_INSENSITIVE 0x0008
1387 #define CURSOR_OPT_HOLD 0x0010
1389 typedef struct DeclareCursorStmt
1392 char *portalname; /* name of the portal (cursor) */
1393 int options; /* bitmask of options (see above) */
1394 Node *query; /* the SELECT query */
1395 } DeclareCursorStmt;
1397 /* ----------------------
1398 * Close Portal Statement
1399 * ----------------------
1401 typedef struct ClosePortalStmt
1404 char *portalname; /* name of the portal (cursor) */
1407 /* ----------------------
1408 * Fetch Statement (also Move)
1409 * ----------------------
1411 typedef enum FetchDirection
1413 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1416 /* for these, howMany indicates a position; only one row is fetched */
1421 #define FETCH_ALL LONG_MAX
1423 typedef struct FetchStmt
1426 FetchDirection direction; /* see above */
1427 long howMany; /* number of rows, or position argument */
1428 char *portalname; /* name of portal (cursor) */
1429 bool ismove; /* TRUE if MOVE */
1432 /* ----------------------
1433 * Create Index Statement
1434 * ----------------------
1436 typedef struct IndexStmt
1439 char *idxname; /* name of new index, or NULL for default */
1440 RangeVar *relation; /* relation to build index on */
1441 char *accessMethod; /* name of access method (eg. btree) */
1442 char *tableSpace; /* tablespace, or NULL to use parent's */
1443 List *indexParams; /* a list of IndexElem */
1444 List *options; /* options from WITH clause */
1445 Node *whereClause; /* qualification (partial-index predicate) */
1446 List *rangetable; /* range table for qual and/or expressions,
1447 * filled in by transformStmt() */
1448 bool unique; /* is index unique? */
1449 bool primary; /* is index on primary key? */
1450 bool isconstraint; /* is it from a CONSTRAINT clause? */
1453 /* ----------------------
1454 * Create Function Statement
1455 * ----------------------
1457 typedef struct CreateFunctionStmt
1460 bool replace; /* T => replace if already exists */
1461 List *funcname; /* qualified name of function to create */
1462 List *parameters; /* a list of FunctionParameter */
1463 TypeName *returnType; /* the return type */
1464 List *options; /* a list of DefElem */
1465 List *withClause; /* a list of DefElem */
1466 } CreateFunctionStmt;
1468 typedef enum FunctionParameterMode
1470 /* the assigned enum values appear in pg_proc, don't change 'em! */
1471 FUNC_PARAM_IN = 'i', /* input only */
1472 FUNC_PARAM_OUT = 'o', /* output only */
1473 FUNC_PARAM_INOUT = 'b' /* both */
1474 } FunctionParameterMode;
1476 typedef struct FunctionParameter
1479 char *name; /* parameter name, or NULL if not given */
1480 TypeName *argType; /* TypeName for parameter type */
1481 FunctionParameterMode mode; /* IN/OUT/INOUT */
1482 } FunctionParameter;
1484 typedef struct AlterFunctionStmt
1487 FuncWithArgs *func; /* name and args of function */
1488 List *actions; /* list of DefElem */
1489 } AlterFunctionStmt;
1491 /* ----------------------
1492 * Drop {Function|Aggregate|Operator} Statement
1493 * ----------------------
1495 typedef struct RemoveFuncStmt
1498 ObjectType kind; /* function, aggregate, operator */
1499 List *name; /* qualified name of object to drop */
1500 List *args; /* types of the arguments */
1501 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1502 bool missing_ok; /* skip error if a missing? */
1505 /* ----------------------
1506 * Drop Operator Class Statement
1507 * ----------------------
1509 typedef struct RemoveOpClassStmt
1512 List *opclassname; /* qualified name (list of Value strings) */
1513 char *amname; /* name of index AM opclass is for */
1514 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1515 bool missing_ok; /* skip error if a missing? */
1516 } RemoveOpClassStmt;
1518 /* ----------------------
1519 * Alter Object Rename Statement
1520 * ----------------------
1522 typedef struct RenameStmt
1525 ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
1526 RangeVar *relation; /* in case it's a table */
1527 List *object; /* in case it's some other object */
1528 List *objarg; /* argument types, if applicable */
1529 char *subname; /* name of contained object (column, rule,
1531 char *newname; /* the new name */
1534 /* ----------------------
1535 * ALTER object SET SCHEMA Statement
1536 * ----------------------
1538 typedef struct AlterObjectSchemaStmt
1541 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1542 RangeVar *relation; /* in case it's a table */
1543 List *object; /* in case it's some other object */
1544 List *objarg; /* argument types, if applicable */
1545 char *addname; /* additional name if needed */
1546 char *newschema; /* the new schema */
1547 } AlterObjectSchemaStmt;
1549 /* ----------------------
1550 * Alter Object Owner Statement
1551 * ----------------------
1553 typedef struct AlterOwnerStmt
1556 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1557 RangeVar *relation; /* in case it's a table */
1558 List *object; /* in case it's some other object */
1559 List *objarg; /* argument types, if applicable */
1560 char *addname; /* additional name if needed */
1561 char *newowner; /* the new owner */
1565 /* ----------------------
1566 * Create Rule Statement
1567 * ----------------------
1569 typedef struct RuleStmt
1572 RangeVar *relation; /* relation the rule is for */
1573 char *rulename; /* name of the rule */
1574 Node *whereClause; /* qualifications */
1575 CmdType event; /* SELECT, INSERT, etc */
1576 bool instead; /* is a 'do instead'? */
1577 List *actions; /* the action statements */
1578 bool replace; /* OR REPLACE */
1581 /* ----------------------
1583 * ----------------------
1585 typedef struct NotifyStmt
1588 RangeVar *relation; /* qualified name to notify */
1591 /* ----------------------
1593 * ----------------------
1595 typedef struct ListenStmt
1598 RangeVar *relation; /* qualified name to listen on */
1601 /* ----------------------
1602 * Unlisten Statement
1603 * ----------------------
1605 typedef struct UnlistenStmt
1608 RangeVar *relation; /* qualified name to unlisten on, or '*' */
1611 /* ----------------------
1612 * {Begin|Commit|Rollback} Transaction Statement
1613 * ----------------------
1615 typedef enum TransactionStmtKind
1618 TRANS_STMT_START, /* semantically identical to BEGIN */
1620 TRANS_STMT_ROLLBACK,
1621 TRANS_STMT_SAVEPOINT,
1623 TRANS_STMT_ROLLBACK_TO,
1625 TRANS_STMT_COMMIT_PREPARED,
1626 TRANS_STMT_ROLLBACK_PREPARED
1627 } TransactionStmtKind;
1629 typedef struct TransactionStmt
1632 TransactionStmtKind kind; /* see above */
1633 List *options; /* for BEGIN/START and savepoint commands */
1634 char *gid; /* for two-phase-commit related commands */
1637 /* ----------------------
1638 * Create Type Statement, composite types
1639 * ----------------------
1641 typedef struct CompositeTypeStmt
1644 RangeVar *typevar; /* the composite type to be created */
1645 List *coldeflist; /* list of ColumnDef nodes */
1646 } CompositeTypeStmt;
1649 /* ----------------------
1650 * Create View Statement
1651 * ----------------------
1653 typedef struct ViewStmt
1656 RangeVar *view; /* the view to be created */
1657 List *aliases; /* target column names */
1658 Query *query; /* the SQL statement */
1659 bool replace; /* replace an existing view? */
1662 /* ----------------------
1664 * ----------------------
1666 typedef struct LoadStmt
1669 char *filename; /* file to load */
1672 /* ----------------------
1673 * Createdb Statement
1674 * ----------------------
1676 typedef struct CreatedbStmt
1679 char *dbname; /* name of database to create */
1680 List *options; /* List of DefElem nodes */
1683 /* ----------------------
1685 * ----------------------
1687 typedef struct AlterDatabaseStmt
1690 char *dbname; /* name of database to alter */
1691 List *options; /* List of DefElem nodes */
1692 } AlterDatabaseStmt;
1694 typedef struct AlterDatabaseSetStmt
1700 } AlterDatabaseSetStmt;
1702 /* ----------------------
1704 * ----------------------
1706 typedef struct DropdbStmt
1709 char *dbname; /* database to drop */
1710 bool missing_ok; /* skip error if db is missing? */
1713 /* ----------------------
1714 * Cluster Statement (support pbrown's cluster index implementation)
1715 * ----------------------
1717 typedef struct ClusterStmt
1720 RangeVar *relation; /* relation being indexed, or NULL if all */
1721 char *indexname; /* original index defined */
1724 /* ----------------------
1725 * Vacuum and Analyze Statements
1727 * Even though these are nominally two statements, it's convenient to use
1728 * just one node type for both.
1729 * ----------------------
1731 typedef struct VacuumStmt
1734 bool vacuum; /* do VACUUM step */
1735 bool full; /* do FULL (non-concurrent) vacuum */
1736 bool analyze; /* do ANALYZE step */
1737 bool freeze; /* early-freeze option */
1738 bool verbose; /* print progress info */
1739 RangeVar *relation; /* single table to process, or NULL */
1740 List *va_cols; /* list of column names, or NIL for all */
1743 /* ----------------------
1745 * ----------------------
1747 typedef struct ExplainStmt
1750 Query *query; /* the query */
1751 bool verbose; /* print plan info */
1752 bool analyze; /* get statistics by executing plan */
1755 /* ----------------------
1756 * Checkpoint Statement
1757 * ----------------------
1759 typedef struct CheckPointStmt
1764 /* ----------------------
1766 * ----------------------
1769 typedef struct VariableSetStmt
1774 bool is_local; /* SET LOCAL */
1777 /* ----------------------
1779 * ----------------------
1782 typedef struct VariableShowStmt
1788 /* ----------------------
1790 * ----------------------
1793 typedef struct VariableResetStmt
1797 } VariableResetStmt;
1799 /* ----------------------
1801 * ----------------------
1803 typedef struct LockStmt
1806 List *relations; /* relations to lock */
1807 int mode; /* lock mode */
1808 bool nowait; /* no wait mode */
1811 /* ----------------------
1812 * SET CONSTRAINTS Statement
1813 * ----------------------
1815 typedef struct ConstraintsSetStmt
1818 List *constraints; /* List of names as RangeVars */
1820 } ConstraintsSetStmt;
1822 /* ----------------------
1824 * ----------------------
1826 typedef struct ReindexStmt
1829 ObjectType kind; /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_DATABASE */
1830 RangeVar *relation; /* Table or index to reindex */
1831 const char *name; /* name of database to reindex */
1832 bool do_system; /* include system tables in database case */
1833 bool do_user; /* include user tables in database case */
1836 /* ----------------------
1837 * CREATE CONVERSION Statement
1838 * ----------------------
1840 typedef struct CreateConversionStmt
1843 List *conversion_name; /* Name of the conversion */
1844 char *for_encoding_name; /* source encoding name */
1845 char *to_encoding_name; /* destination encoding name */
1846 List *func_name; /* qualified conversion function name */
1847 bool def; /* is this a default conversion? */
1848 } CreateConversionStmt;
1850 /* ----------------------
1851 * CREATE CAST Statement
1852 * ----------------------
1854 typedef struct CreateCastStmt
1857 TypeName *sourcetype;
1858 TypeName *targettype;
1860 CoercionContext context;
1863 /* ----------------------
1864 * DROP CAST Statement
1865 * ----------------------
1867 typedef struct DropCastStmt
1870 TypeName *sourcetype;
1871 TypeName *targettype;
1872 DropBehavior behavior;
1873 bool missing_ok; /* skip error if a missing? */
1877 /* ----------------------
1879 * ----------------------
1881 typedef struct PrepareStmt
1884 char *name; /* Name of plan, arbitrary */
1885 List *argtypes; /* Types of parameters (TypeNames) */
1886 List *argtype_oids; /* Types of parameters (OIDs) */
1887 Query *query; /* The query itself */
1891 /* ----------------------
1893 * ----------------------
1896 typedef struct ExecuteStmt
1899 char *name; /* The name of the plan to execute */
1900 RangeVar *into; /* Optional table to store results in */
1901 List *intoOptions; /* Options from WITH clause */
1902 OnCommitAction into_on_commit; /* What do we do at COMMIT? */
1903 char *into_tbl_space; /* Tablespace to use, or NULL */
1904 List *params; /* Values to assign to parameters */
1908 /* ----------------------
1909 * DEALLOCATE Statement
1910 * ----------------------
1912 typedef struct DeallocateStmt
1915 char *name; /* The name of the plan to remove */
1919 * DROP OWNED statement
1921 typedef struct DropOwnedStmt
1925 DropBehavior behavior;
1929 * REASSIGN OWNED statement
1931 typedef struct ReassignOwnedStmt
1936 } ReassignOwnedStmt;
1938 #endif /* PARSENODES_H */