1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.358 2008/01/01 19:45:58 momjian Exp $
12 *-------------------------------------------------------------------------
17 #include "nodes/primnodes.h"
18 #include "nodes/value.h"
20 /* Possible sources of a Query */
21 typedef enum QuerySource
23 QSRC_ORIGINAL, /* original parsetree (explicit query) */
24 QSRC_PARSER, /* added by parse analysis (now unused) */
25 QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */
26 QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */
27 QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */
30 /* Sort ordering options for ORDER BY and CREATE INDEX */
31 typedef enum SortByDir
36 SORTBY_USING /* not allowed in CREATE INDEX ... */
39 typedef enum SortByNulls
48 * Grantable rights are encoded so that we can OR them together in a bitmask.
49 * The present representation of AclItem limits us to 16 distinct rights,
50 * even though AclMode is defined as uint32. See utils/acl.h.
52 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
54 typedef uint32 AclMode; /* a bitmask of privilege bits */
56 #define ACL_INSERT (1<<0) /* for relations */
57 #define ACL_SELECT (1<<1)
58 #define ACL_UPDATE (1<<2)
59 #define ACL_DELETE (1<<3)
60 /* #define ACL_RULE (1<<4) unused, available */
61 #define ACL_REFERENCES (1<<5)
62 #define ACL_TRIGGER (1<<6)
63 #define ACL_EXECUTE (1<<7) /* for functions */
64 #define ACL_USAGE (1<<8) /* for languages and namespaces */
65 #define ACL_CREATE (1<<9) /* for namespaces and databases */
66 #define ACL_CREATE_TEMP (1<<10) /* for databases */
67 #define ACL_CONNECT (1<<11) /* for databases */
68 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */
69 #define ACL_NO_RIGHTS 0
70 /* Currently, SELECT ... FOR UPDATE/FOR SHARE requires UPDATE privileges */
71 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE
74 /*****************************************************************************
76 *****************************************************************************/
80 * Parse analysis turns all statements into a Query tree (via transformStmt)
81 * for further processing by the rewriter and planner.
83 * Utility statements (i.e. non-optimizable statements) have the
84 * utilityStmt field set, and the Query itself is mostly dummy.
85 * DECLARE CURSOR is a special case: it is represented like a SELECT,
86 * but the original DeclareCursorStmt is stored in utilityStmt.
88 * Planning converts a Query tree into a Plan tree headed by a PlannedStmt
89 * node --- the Query structure is not used by the executor.
95 CmdType commandType; /* select|insert|update|delete|utility */
97 QuerySource querySource; /* where did I come from? */
99 bool canSetTag; /* do I set the command result tag? */
101 Node *utilityStmt; /* non-null if this is DECLARE CURSOR or a
102 * non-optimizable statement */
104 int resultRelation; /* rtable index of target relation for
105 * INSERT/UPDATE/DELETE; 0 for SELECT */
107 IntoClause *intoClause; /* target for SELECT INTO / CREATE TABLE AS */
109 bool hasAggs; /* has aggregates in tlist or havingQual */
110 bool hasSubLinks; /* has subquery SubLink */
112 List *rtable; /* list of range table entries */
113 FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */
115 List *targetList; /* target list (of TargetEntry) */
117 List *returningList; /* return-values list (of TargetEntry) */
119 List *groupClause; /* a list of GroupClause's */
121 Node *havingQual; /* qualifications applied to groups */
123 List *distinctClause; /* a list of SortClause's */
125 List *sortClause; /* a list of SortClause's */
127 Node *limitOffset; /* # of result tuples to skip (int8 expr) */
128 Node *limitCount; /* # of result tuples to return (int8 expr) */
130 List *rowMarks; /* a list of RowMarkClause's */
132 Node *setOperations; /* set-operation tree if this is top level of
133 * a UNION/INTERSECT/EXCEPT query */
137 /****************************************************************************
138 * Supporting data structures for Parse Trees
140 * Most of these node types appear in raw parsetrees output by the grammar,
141 * and get transformed to something else by the analyzer. A few of them
142 * are used as-is in transformed querytrees.
144 * Many of the node types used in raw parsetrees include a "location" field.
145 * This is a byte (not character) offset in the original source text, to be
146 * used for positioning an error cursor when there is an analysis-time
147 * error related to the node.
148 ****************************************************************************/
151 * TypeName - specifies a type in definitions
153 * For TypeName structures generated internally, it is often easier to
154 * specify the type by OID than by name. If "names" is NIL then the
155 * actual type OID is given by typeid, otherwise typeid is unused.
156 * Similarly, if "typmods" is NIL then the actual typmod is expected to
157 * be prespecified in typemod, otherwise typemod is unused.
159 * If pct_type is TRUE, then names is actually a field name and we look up
160 * the type of that field. Otherwise (the normal case), names is a type
161 * name possibly qualified with schema and database name.
163 typedef struct TypeName
166 List *names; /* qualified name (list of Value strings) */
167 Oid typeid; /* type identified by OID */
168 bool timezone; /* timezone specified? */
169 bool setof; /* is a set? */
170 bool pct_type; /* %TYPE specified? */
171 List *typmods; /* type modifier expression(s) */
172 int32 typemod; /* prespecified type modifier */
173 List *arrayBounds; /* array bounds */
174 int location; /* token location, or -1 if unknown */
178 * ColumnRef - specifies a reference to a column, or possibly a whole tuple
180 * The "fields" list must be nonempty; its last component may be "*"
181 * instead of a regular field name.
183 * Note: any array subscripting or selection of fields from composite columns
184 * is represented by an A_Indirection node above the ColumnRef. However,
185 * for simplicity in the normal case, initial field selection from a table
186 * name is represented within ColumnRef and not by adding A_Indirection.
188 typedef struct ColumnRef
191 List *fields; /* field names (list of Value strings) */
192 int location; /* token location, or -1 if unknown */
196 * ParamRef - specifies a $n parameter reference
198 typedef struct ParamRef
201 int number; /* the number of the parameter */
205 * A_Expr - infix, prefix, and postfix expressions
207 typedef enum A_Expr_Kind
209 AEXPR_OP, /* normal operator */
210 AEXPR_AND, /* booleans - name field is unused */
213 AEXPR_OP_ANY, /* scalar op ANY (array) */
214 AEXPR_OP_ALL, /* scalar op ALL (array) */
215 AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */
216 AEXPR_NULLIF, /* NULLIF - name must be "=" */
217 AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */
218 AEXPR_IN /* [NOT] IN - name must be "=" or "<>" */
221 typedef struct A_Expr
224 A_Expr_Kind kind; /* see above */
225 List *name; /* possibly-qualified name of operator */
226 Node *lexpr; /* left argument, or NULL if none */
227 Node *rexpr; /* right argument, or NULL if none */
228 int location; /* token location, or -1 if unknown */
232 * A_Const - a constant expression
234 typedef struct A_Const
237 Value val; /* the value (with the tag) */
238 TypeName *typename; /* typecast, or NULL if none */
242 * TypeCast - a CAST expression
244 * NOTE: for mostly historical reasons, A_Const parsenodes contain
245 * room for a TypeName; we only generate a separate TypeCast node if the
246 * argument to be casted is not a constant. In theory either representation
247 * would work, but the combined representation saves a bit of code in many
248 * productions in gram.y.
250 typedef struct TypeCast
253 Node *arg; /* the expression being casted */
254 TypeName *typename; /* the target type */
258 * FuncCall - a function or aggregate invocation
260 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
261 * indicates we saw 'foo(DISTINCT ...)'. In either case, the construct
262 * *must* be an aggregate call. Otherwise, it might be either an
263 * aggregate or some other kind of function.
265 typedef struct FuncCall
268 List *funcname; /* qualified name of function */
269 List *args; /* the arguments (list of exprs) */
270 bool agg_star; /* argument was really '*' */
271 bool agg_distinct; /* arguments were labeled DISTINCT */
272 int location; /* token location, or -1 if unknown */
276 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
278 typedef struct A_Indices
281 Node *lidx; /* could be NULL */
286 * A_Indirection - select a field and/or array element from an expression
288 * The indirection list can contain both A_Indices nodes (representing
289 * subscripting) and string Value nodes (representing field selection
290 * --- the string value is the name of the field to select). For example,
291 * a complex selection operation like
292 * (foo).field1[42][7].field2
293 * would be represented with a single A_Indirection node having a 4-element
296 * Note: as of Postgres 8.0, we don't support arrays of composite values,
297 * so cases in which a field select follows a subscript aren't actually
298 * semantically legal. However the parser is prepared to handle such.
300 typedef struct A_Indirection
303 Node *arg; /* the thing being selected from */
304 List *indirection; /* subscripts and/or field names */
309 * result target (used in target list of pre-transformed parse trees)
311 * In a SELECT target list, 'name' is the column label from an
312 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
313 * value expression itself. The 'indirection' field is not used.
315 * INSERT uses ResTarget in its target-column-names list. Here, 'name' is
316 * the name of the destination column, 'indirection' stores any subscripts
317 * attached to the destination, and 'val' is not used.
319 * In an UPDATE target list, 'name' is the name of the destination column,
320 * 'indirection' stores any subscripts attached to the destination, and
321 * 'val' is the expression to assign.
323 * See A_Indirection for more info about what can appear in 'indirection'.
325 typedef struct ResTarget
328 char *name; /* column name or NULL */
329 List *indirection; /* subscripts and field names, or NIL */
330 Node *val; /* the value expression to compute or assign */
331 int location; /* token location, or -1 if unknown */
335 * SortBy - for ORDER BY clause
337 typedef struct SortBy
340 SortByDir sortby_dir; /* ASC/DESC/USING */
341 SortByNulls sortby_nulls; /* NULLS FIRST/LAST */
342 List *useOp; /* name of op to use, if SORTBY_USING */
343 Node *node; /* expression to sort on */
347 * RangeSubselect - subquery appearing in a FROM clause
349 typedef struct RangeSubselect
352 Node *subquery; /* the untransformed sub-select clause */
353 Alias *alias; /* table alias & optional column aliases */
357 * RangeFunction - function call appearing in a FROM clause
359 typedef struct RangeFunction
362 Node *funccallnode; /* untransformed function call tree */
363 Alias *alias; /* table alias & optional column aliases */
364 List *coldeflist; /* list of ColumnDef nodes to describe result
365 * of function returning RECORD */
369 * ColumnDef - column definition (used in various creates)
371 * If the column has a default value, we may have the value expression
372 * in either "raw" form (an untransformed parse tree) or "cooked" form
373 * (the nodeToString representation of an executable expression tree),
374 * depending on how this ColumnDef node was created (by parsing, or by
375 * inheritance from an existing relation). We should never have both
378 * The constraints list may contain a CONSTR_DEFAULT item in a raw
379 * parsetree produced by gram.y, but transformCreateStmt will remove
380 * the item and set raw_default instead. CONSTR_DEFAULT items
381 * should not appear in any subsequent processing.
383 typedef struct ColumnDef
386 char *colname; /* name of column */
387 TypeName *typename; /* type of column */
388 int inhcount; /* number of times column is inherited */
389 bool is_local; /* column has local (non-inherited) def'n */
390 bool is_not_null; /* NOT NULL constraint specified? */
391 Node *raw_default; /* default value (untransformed parse tree) */
392 char *cooked_default; /* nodeToString representation */
393 List *constraints; /* other constraints on column */
397 * inhRelation - Relations a CREATE TABLE is to inherit attributes of
399 typedef struct InhRelation
403 List *options; /* integer List of CreateStmtLikeOption */
406 typedef enum CreateStmtLikeOption
408 CREATE_TABLE_LIKE_INCLUDING_DEFAULTS,
409 CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS,
410 CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS,
411 CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS,
412 CREATE_TABLE_LIKE_INCLUDING_INDEXES,
413 CREATE_TABLE_LIKE_EXCLUDING_INDEXES
414 } CreateStmtLikeOption;
417 * IndexElem - index parameters (used in CREATE INDEX)
419 * For a plain index attribute, 'name' is the name of the table column to
420 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and
421 * 'expr' is the expression tree.
423 typedef struct IndexElem
426 char *name; /* name of attribute to index, or NULL */
427 Node *expr; /* expression to index, or NULL */
428 List *opclass; /* name of desired opclass; NIL = default */
429 SortByDir ordering; /* ASC/DESC/default */
430 SortByNulls nulls_ordering; /* FIRST/LAST/default */
435 * a definition (used in definition lists in the form of defname = arg)
437 typedef struct DefElem
441 Node *arg; /* a (Value *) or a (TypeName *) */
445 * LockingClause - raw representation of FOR UPDATE/SHARE options
447 * Note: lockedRels == NIL means "all relations in query". Otherwise it
448 * is a list of String nodes giving relation eref names.
450 typedef struct LockingClause
453 List *lockedRels; /* FOR UPDATE or FOR SHARE relations */
454 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
455 bool noWait; /* NOWAIT option */
461 typedef struct XmlSerialize
464 XmlOptionType xmloption;
470 /****************************************************************************
471 * Nodes for a Query tree
472 ****************************************************************************/
474 /*--------------------
476 * A range table is a List of RangeTblEntry nodes.
478 * A range table entry may represent a plain relation, a sub-select in
479 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax
480 * produces an RTE, not the implicit join resulting from multiple FROM
481 * items. This is because we only need the RTE to deal with SQL features
482 * like outer joins and join-output-column aliasing.) Other special
483 * RTE types also exist, as indicated by RTEKind.
485 * alias is an Alias node representing the AS alias-clause attached to the
486 * FROM expression, or NULL if no clause.
488 * eref is the table reference name and column reference names (either
489 * real or aliases). Note that system columns (OID etc) are not included
490 * in the column list.
491 * eref->aliasname is required to be present, and should generally be used
492 * to identify the RTE for error messages etc.
494 * In RELATION RTEs, the colnames in both alias and eref are indexed by
495 * physical attribute number; this means there must be colname entries for
496 * dropped columns. When building an RTE we insert empty strings ("") for
497 * dropped columns. Note however that a stored rule may have nonempty
498 * colnames for columns dropped since the rule was created (and for that
499 * matter the colnames might be out of date due to column renamings).
500 * The same comments apply to FUNCTION RTEs when the function's return type
501 * is a named composite type.
503 * In JOIN RTEs, the colnames in both alias and eref are one-to-one with
504 * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when
505 * those columns are known to be dropped at parse time. Again, however,
506 * a stored rule might contain entries for columns dropped since the rule
507 * was created. (This is only possible for columns not actually referenced
508 * in the rule.) When loading a stored rule, we replace the joinaliasvars
509 * items for any such columns with NULL Consts. (We can't simply delete
510 * them from the joinaliasvars list, because that would affect the attnums
511 * of Vars referencing the rest of the list.)
513 * inh is TRUE for relation references that should be expanded to include
514 * inheritance children, if the rel has any. This *must* be FALSE for
515 * RTEs other than RTE_RELATION entries.
517 * inFromCl marks those range variables that are listed in the FROM clause.
518 * It's false for RTEs that are added to a query behind the scenes, such
519 * as the NEW and OLD variables for a rule, or the subqueries of a UNION.
520 * This flag is not used anymore during parsing, since the parser now uses
521 * a separate "namespace" data structure to control visibility, but it is
522 * needed by ruleutils.c to determine whether RTEs should be shown in
523 * decompiled queries.
525 * requiredPerms and checkAsUser specify run-time access permissions
526 * checks to be performed at query startup. The user must have *all*
527 * of the permissions that are OR'd together in requiredPerms (zero
528 * indicates no permissions checking). If checkAsUser is not zero,
529 * then do the permissions checks using the access rights of that user,
530 * not the current effective user ID. (This allows rules to act as
532 *--------------------
536 RTE_RELATION, /* ordinary relation reference */
537 RTE_SUBQUERY, /* subquery in FROM */
539 RTE_SPECIAL, /* special rule relation (NEW or OLD) */
540 RTE_FUNCTION, /* function in FROM */
541 RTE_VALUES /* VALUES (<exprlist>), (<exprlist>), ... */
544 typedef struct RangeTblEntry
548 RTEKind rtekind; /* see above */
551 * XXX the fields applicable to only some rte kinds should be merged into
552 * a union. I didn't do this yet because the diffs would impact a lot of
553 * code that is being actively worked on. FIXME later.
557 * Fields valid for a plain relation RTE (else zero):
559 Oid relid; /* OID of the relation */
562 * Fields valid for a subquery RTE (else NULL):
564 Query *subquery; /* the sub-query */
567 * Fields valid for a function RTE (else NULL):
569 * If the function returns RECORD, funccoltypes lists the column types
570 * declared in the RTE's column type specification, and funccoltypmods
571 * lists their declared typmods. Otherwise, both fields are NIL.
573 Node *funcexpr; /* expression tree for func call */
574 List *funccoltypes; /* OID list of column type OIDs */
575 List *funccoltypmods; /* integer list of column typmods */
578 * Fields valid for a values RTE (else NIL):
580 List *values_lists; /* list of expression lists */
583 * Fields valid for a join RTE (else NULL/zero):
585 * joinaliasvars is a list of Vars or COALESCE expressions corresponding
586 * to the columns of the join result. An alias Var referencing column K
587 * of the join result can be replaced by the K'th element of joinaliasvars
588 * --- but to simplify the task of reverse-listing aliases correctly, we
589 * do not do that until planning time. In a Query loaded from a stored
590 * rule, it is also possible for joinaliasvars items to be NULL Consts,
591 * denoting columns dropped since the rule was made.
593 JoinType jointype; /* type of join */
594 List *joinaliasvars; /* list of alias-var expansions */
597 * Fields valid in all RTEs:
599 Alias *alias; /* user-written alias clause, if any */
600 Alias *eref; /* expanded reference names */
601 bool inh; /* inheritance requested? */
602 bool inFromCl; /* present in FROM clause? */
603 AclMode requiredPerms; /* bitmask of required access permissions */
604 Oid checkAsUser; /* if valid, check access as this role */
609 * representation of ORDER BY clauses
611 * tleSortGroupRef must match ressortgroupref of exactly one entry of the
612 * associated targetlist; that is the expression to be sorted (or grouped) by.
613 * sortop is the OID of the ordering operator (a "<" or ">" operator).
614 * nulls_first does about what you'd expect.
616 * SortClauses are also used to identify targets that we will do a "Unique"
617 * filter step on (for SELECT DISTINCT and SELECT DISTINCT ON). The
618 * distinctClause list is simply a copy of the relevant members of the
619 * sortClause list. Note that distinctClause can be a subset of sortClause,
620 * but cannot have members not present in sortClause; and the members that
621 * do appear must be in the same order as in sortClause.
623 typedef struct SortClause
626 Index tleSortGroupRef; /* reference into targetlist */
627 Oid sortop; /* the ordering operator ('<' op) */
628 bool nulls_first; /* do NULLs come before normal values? */
633 * representation of GROUP BY clauses
635 * GroupClause is exactly like SortClause except for the nodetag value.
636 * We have routines that operate interchangeably on both.
638 * XXX SortClause overspecifies the semantics so far as GROUP BY is concerned
639 * (ditto for DISTINCT). It'd be better to specify an equality operator not
640 * an ordering operator. However, the two implementations are tightly entwined
641 * at the moment ... breaking them apart is work for another day.
643 typedef SortClause GroupClause;
647 * representation of FOR UPDATE/SHARE clauses
649 * We create a separate RowMarkClause node for each target relation
651 typedef struct RowMarkClause
654 Index rti; /* range table index of target relation */
655 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
656 bool noWait; /* NOWAIT option */
659 /*****************************************************************************
660 * Optimizable Statements
661 *****************************************************************************/
663 /* ----------------------
666 * The source expression is represented by SelectStmt for both the
667 * SELECT and VALUES cases. If selectStmt is NULL, then the query
668 * is INSERT ... DEFAULT VALUES.
669 * ----------------------
671 typedef struct InsertStmt
674 RangeVar *relation; /* relation to insert into */
675 List *cols; /* optional: names of the target columns */
676 Node *selectStmt; /* the source SELECT/VALUES, or NULL */
677 List *returningList; /* list of expressions to return */
680 /* ----------------------
682 * ----------------------
684 typedef struct DeleteStmt
687 RangeVar *relation; /* relation to delete from */
688 List *usingClause; /* optional using clause for more tables */
689 Node *whereClause; /* qualifications */
690 List *returningList; /* list of expressions to return */
693 /* ----------------------
695 * ----------------------
697 typedef struct UpdateStmt
700 RangeVar *relation; /* relation to update */
701 List *targetList; /* the target list (of ResTarget) */
702 Node *whereClause; /* qualifications */
703 List *fromClause; /* optional from clause for more tables */
704 List *returningList; /* list of expressions to return */
707 /* ----------------------
710 * A "simple" SELECT is represented in the output of gram.y by a single
711 * SelectStmt node; so is a VALUES construct. A query containing set
712 * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
713 * nodes, in which the leaf nodes are component SELECTs and the internal nodes
714 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node
715 * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
716 * LIMIT, etc, clause values into a SELECT statement without worrying
717 * whether it is a simple or compound SELECT.
718 * ----------------------
720 typedef enum SetOperation
728 typedef struct SelectStmt
733 * These fields are used only in "leaf" SelectStmts.
735 List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
736 * lcons(NIL,NIL) for all (SELECT DISTINCT) */
737 IntoClause *intoClause; /* target for SELECT INTO / CREATE TABLE AS */
738 List *targetList; /* the target list (of ResTarget) */
739 List *fromClause; /* the FROM clause */
740 Node *whereClause; /* WHERE qualification */
741 List *groupClause; /* GROUP BY clauses */
742 Node *havingClause; /* HAVING conditional-expression */
745 * In a "leaf" node representing a VALUES list, the above fields are all
746 * null, and instead this field is set. Note that the elements of the
747 * sublists are just expressions, without ResTarget decoration. Also note
748 * that a list element can be DEFAULT (represented as a SetToDefault
749 * node), regardless of the context of the VALUES list. It's up to parse
750 * analysis to reject that where not valid.
752 List *valuesLists; /* untransformed list of expression lists */
755 * These fields are used in both "leaf" SelectStmts and upper-level
758 List *sortClause; /* sort clause (a list of SortBy's) */
759 Node *limitOffset; /* # of result tuples to skip */
760 Node *limitCount; /* # of result tuples to return */
761 List *lockingClause; /* FOR UPDATE (list of LockingClause's) */
764 * These fields are used only in upper-level SelectStmts.
766 SetOperation op; /* type of set op */
767 bool all; /* ALL specified? */
768 struct SelectStmt *larg; /* left child */
769 struct SelectStmt *rarg; /* right child */
770 /* Eventually add fields for CORRESPONDING spec here */
774 /* ----------------------
775 * Set Operation node for post-analysis query trees
777 * After parse analysis, a SELECT with set operations is represented by a
778 * top-level Query node containing the leaf SELECTs as subqueries in its
779 * range table. Its setOperations field shows the tree of set operations,
780 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
781 * nodes replaced by SetOperationStmt nodes.
782 * ----------------------
784 typedef struct SetOperationStmt
787 SetOperation op; /* type of set op */
788 bool all; /* ALL specified? */
789 Node *larg; /* left child */
790 Node *rarg; /* right child */
791 /* Eventually add fields for CORRESPONDING spec here */
793 /* Fields derived during parse analysis: */
794 List *colTypes; /* OID list of output column type OIDs */
795 List *colTypmods; /* integer list of output column typmods */
799 /*****************************************************************************
800 * Other Statements (no optimizations required)
802 * These are not touched by parser/analyze.c except to put them into
803 * the utilityStmt field of a Query. This is eventually passed to
804 * ProcessUtility (by-passing rewriting and planning). Some of the
805 * statements do need attention from parse analysis, and this is
806 * done by routines in parser/parse_utilcmd.c after ProcessUtility
807 * receives the command for execution.
808 *****************************************************************************/
811 * When a command can act on several kinds of objects with only one
812 * parse structure required, use these constants to designate the
816 typedef enum ObjectType
839 OBJECT_TSCONFIGURATION,
847 /* ----------------------
848 * Create Schema Statement
850 * NOTE: the schemaElts list contains raw parsetrees for component statements
851 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
852 * executed after the schema itself is created.
853 * ----------------------
855 typedef struct CreateSchemaStmt
858 char *schemaname; /* the name of the schema to create */
859 char *authid; /* the owner of the created schema */
860 List *schemaElts; /* schema components (list of parsenodes) */
863 typedef enum DropBehavior
865 DROP_RESTRICT, /* drop fails if any dependent objects */
866 DROP_CASCADE /* remove dependent objects too */
869 /* ----------------------
871 * ----------------------
873 typedef struct AlterTableStmt
876 RangeVar *relation; /* table to work on */
877 List *cmds; /* list of subcommands */
878 ObjectType relkind; /* type of object */
881 typedef enum AlterTableType
883 AT_AddColumn, /* add column */
884 AT_ColumnDefault, /* alter column default */
885 AT_DropNotNull, /* alter column drop not null */
886 AT_SetNotNull, /* alter column set not null */
887 AT_SetStatistics, /* alter column statistics */
888 AT_SetStorage, /* alter column storage */
889 AT_DropColumn, /* drop column */
890 AT_DropColumnRecurse, /* internal to commands/tablecmds.c */
891 AT_AddIndex, /* add index */
892 AT_ReAddIndex, /* internal to commands/tablecmds.c */
893 AT_AddConstraint, /* add constraint */
894 AT_ProcessedConstraint, /* pre-processed add constraint (local in
895 * parser/parse_utilcmd.c) */
896 AT_DropConstraint, /* drop constraint */
897 AT_DropConstraintQuietly, /* drop constraint, no error/warning (local in
898 * commands/tablecmds.c) */
899 AT_AlterColumnType, /* alter column type */
900 AT_ChangeOwner, /* change owner */
901 AT_ClusterOn, /* CLUSTER ON */
902 AT_DropCluster, /* SET WITHOUT CLUSTER */
903 AT_DropOids, /* SET WITHOUT OIDS */
904 AT_SetTableSpace, /* SET TABLESPACE */
905 AT_SetRelOptions, /* SET (...) -- AM specific parameters */
906 AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */
907 AT_EnableTrig, /* ENABLE TRIGGER name */
908 AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */
909 AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */
910 AT_DisableTrig, /* DISABLE TRIGGER name */
911 AT_EnableTrigAll, /* ENABLE TRIGGER ALL */
912 AT_DisableTrigAll, /* DISABLE TRIGGER ALL */
913 AT_EnableTrigUser, /* ENABLE TRIGGER USER */
914 AT_DisableTrigUser, /* DISABLE TRIGGER USER */
915 AT_EnableRule, /* ENABLE RULE name */
916 AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */
917 AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */
918 AT_DisableRule, /* DISABLE RULE name */
919 AT_AddInherit, /* INHERIT parent */
920 AT_DropInherit /* NO INHERIT parent */
923 typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */
926 AlterTableType subtype; /* Type of table alteration to apply */
927 char *name; /* column, constraint, or trigger to act on,
928 * or new owner or tablespace */
929 Node *def; /* definition of new column, column type,
930 * index, constraint, or parent table */
931 Node *transform; /* transformation expr for ALTER TYPE */
932 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
936 /* ----------------------
939 * The fields are used in different ways by the different variants of
941 * ----------------------
943 typedef struct AlterDomainStmt
946 char subtype; /*------------
947 * T = alter column default
948 * N = alter column drop not null
949 * O = alter column set not null
951 * X = drop constraint
954 List *typename; /* domain to work on */
955 char *name; /* column or constraint name to act on */
956 Node *def; /* definition of default or constraint */
957 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
961 /* ----------------------
962 * Grant|Revoke Statement
963 * ----------------------
965 typedef enum GrantObjectType
967 ACL_OBJECT_RELATION, /* table, view */
968 ACL_OBJECT_SEQUENCE, /* sequence */
969 ACL_OBJECT_DATABASE, /* database */
970 ACL_OBJECT_FUNCTION, /* function */
971 ACL_OBJECT_LANGUAGE, /* procedural language */
972 ACL_OBJECT_NAMESPACE, /* namespace */
973 ACL_OBJECT_TABLESPACE /* tablespace */
976 typedef struct GrantStmt
979 bool is_grant; /* true = GRANT, false = REVOKE */
980 GrantObjectType objtype; /* kind of object being operated on */
981 List *objects; /* list of RangeVar nodes, FuncWithArgs nodes,
982 * or plain names (as Value strings) */
983 List *privileges; /* list of privilege names (as Strings) */
984 /* privileges == NIL denotes "all privileges" */
985 List *grantees; /* list of PrivGrantee nodes */
986 bool grant_option; /* grant or revoke grant option */
987 DropBehavior behavior; /* drop behavior (for REVOKE) */
990 typedef struct PrivGrantee
993 char *rolname; /* if NULL then PUBLIC */
997 * Note: FuncWithArgs carries only the types of the input parameters of the
998 * function. So it is sufficient to identify an existing function, but it
999 * is not enough info to define a function nor to call it.
1001 typedef struct FuncWithArgs
1004 List *funcname; /* qualified name of function */
1005 List *funcargs; /* list of Typename nodes */
1008 /* This is only used internally in gram.y. */
1009 typedef struct PrivTarget
1012 GrantObjectType objtype;
1016 /* ----------------------
1017 * Grant/Revoke Role Statement
1019 * Note: the lists of roles are lists of names, as Value strings
1020 * ----------------------
1022 typedef struct GrantRoleStmt
1025 List *granted_roles; /* list of roles to be granted/revoked */
1026 List *grantee_roles; /* list of member roles to add/delete */
1027 bool is_grant; /* true = GRANT, false = REVOKE */
1028 bool admin_opt; /* with admin option */
1029 char *grantor; /* set grantor to other than current role */
1030 DropBehavior behavior; /* drop behavior (for REVOKE) */
1033 /* ----------------------
1036 * We support "COPY relation FROM file", "COPY relation TO file", and
1037 * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation"
1038 * and "query" must be non-NULL.
1039 * ----------------------
1041 typedef struct CopyStmt
1044 RangeVar *relation; /* the relation to copy */
1045 Node *query; /* the SELECT query to copy */
1046 List *attlist; /* List of column names (as Strings), or NIL
1047 * for all columns */
1048 bool is_from; /* TO or FROM */
1049 char *filename; /* filename, or NULL for STDIN/STDOUT */
1050 List *options; /* List of DefElem nodes */
1053 /* ----------------------
1054 * SET Statement (includes RESET)
1056 * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
1057 * preserve the distinction in VariableSetKind for CreateCommandTag().
1058 * ----------------------
1062 VAR_SET_VALUE, /* SET var = value */
1063 VAR_SET_DEFAULT, /* SET var TO DEFAULT */
1064 VAR_SET_CURRENT, /* SET var FROM CURRENT */
1065 VAR_SET_MULTI, /* special case for SET TRANSACTION ... */
1066 VAR_RESET, /* RESET var */
1067 VAR_RESET_ALL /* RESET ALL */
1070 typedef struct VariableSetStmt
1073 VariableSetKind kind;
1074 char *name; /* variable to be set */
1075 List *args; /* List of A_Const nodes */
1076 bool is_local; /* SET LOCAL? */
1079 /* ----------------------
1081 * ----------------------
1083 typedef struct VariableShowStmt
1089 /* ----------------------
1090 * Create Table Statement
1092 * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
1093 * nodes are intermixed in tableElts, and constraints is NIL. After parse
1094 * analysis, tableElts contains just ColumnDefs, and constraints contains
1095 * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
1097 * ----------------------
1100 typedef struct CreateStmt
1103 RangeVar *relation; /* relation to create */
1104 List *tableElts; /* column definitions (list of ColumnDef) */
1105 List *inhRelations; /* relations to inherit from (list of
1107 List *constraints; /* constraints (list of Constraint nodes) */
1108 List *options; /* options from WITH clause */
1109 OnCommitAction oncommit; /* what do we do at COMMIT? */
1110 char *tablespacename; /* table space to use, or NULL */
1114 * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
1116 * XXX probably these ought to be unified with FkConstraints at some point?
1117 * To this end we include CONSTR_FOREIGN in the ConstrType enum, even though
1118 * the parser does not generate it.
1120 * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
1121 * we may have the expression in either "raw" form (an untransformed
1122 * parse tree) or "cooked" form (the nodeToString representation of
1123 * an executable expression tree), depending on how this Constraint
1124 * node was created (by parsing, or by inheritance from an existing
1125 * relation). We should never have both in the same node!
1127 * Constraint attributes (DEFERRABLE etc) are initially represented as
1128 * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes
1129 * a pass through the constraints list to attach the info to the appropriate
1130 * FkConstraint node (and, perhaps, someday to other kinds of constraints).
1134 typedef enum ConstrType /* types of constraints */
1136 CONSTR_NULL, /* not SQL92, but a lot of people expect it */
1143 CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
1144 CONSTR_ATTR_NOT_DEFERRABLE,
1145 CONSTR_ATTR_DEFERRED,
1146 CONSTR_ATTR_IMMEDIATE
1149 typedef struct Constraint
1153 char *name; /* name, or NULL if unnamed */
1154 Node *raw_expr; /* expr, as untransformed parse tree */
1155 char *cooked_expr; /* expr, as nodeToString representation */
1156 List *keys; /* String nodes naming referenced column(s) */
1157 List *options; /* options from WITH clause */
1158 char *indexspace; /* index tablespace for PKEY/UNIQUE
1159 * constraints; NULL for default */
1163 * Definitions for FOREIGN KEY constraints in CreateStmt
1165 * Note: FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
1166 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
1167 * stored into pg_constraint.confmatchtype. Changing the code values may
1168 * require an initdb!
1170 * If skip_validation is true then we skip checking that the existing rows
1171 * in the table satisfy the constraint, and just install the catalog entries
1172 * for the constraint. This is currently used only during CREATE TABLE
1173 * (when we know the table must be empty).
1176 #define FKCONSTR_ACTION_NOACTION 'a'
1177 #define FKCONSTR_ACTION_RESTRICT 'r'
1178 #define FKCONSTR_ACTION_CASCADE 'c'
1179 #define FKCONSTR_ACTION_SETNULL 'n'
1180 #define FKCONSTR_ACTION_SETDEFAULT 'd'
1182 #define FKCONSTR_MATCH_FULL 'f'
1183 #define FKCONSTR_MATCH_PARTIAL 'p'
1184 #define FKCONSTR_MATCH_UNSPECIFIED 'u'
1186 typedef struct FkConstraint
1189 char *constr_name; /* Constraint name, or NULL if unnamed */
1190 RangeVar *pktable; /* Primary key table */
1191 List *fk_attrs; /* Attributes of foreign key */
1192 List *pk_attrs; /* Corresponding attrs in PK table */
1193 char fk_matchtype; /* FULL, PARTIAL, UNSPECIFIED */
1194 char fk_upd_action; /* ON UPDATE action */
1195 char fk_del_action; /* ON DELETE action */
1196 bool deferrable; /* DEFERRABLE */
1197 bool initdeferred; /* INITIALLY DEFERRED */
1198 bool skip_validation; /* skip validation of existing rows? */
1202 /* ----------------------
1203 * Create/Drop Table Space Statements
1204 * ----------------------
1207 typedef struct CreateTableSpaceStmt
1210 char *tablespacename;
1213 } CreateTableSpaceStmt;
1215 typedef struct DropTableSpaceStmt
1218 char *tablespacename;
1219 bool missing_ok; /* skip error if missing? */
1220 } DropTableSpaceStmt;
1222 /* ----------------------
1223 * Create/Drop TRIGGER Statements
1224 * ----------------------
1227 typedef struct CreateTrigStmt
1230 char *trigname; /* TRIGGER's name */
1231 RangeVar *relation; /* relation trigger is on */
1232 List *funcname; /* qual. name of function to call */
1233 List *args; /* list of (T_String) Values or NIL */
1234 bool before; /* BEFORE/AFTER */
1235 bool row; /* ROW/STATEMENT */
1236 char actions[4]; /* 1 to 3 of 'i', 'u', 'd', + trailing \0 */
1238 /* The following are used for referential */
1239 /* integrity constraint triggers */
1240 bool isconstraint; /* This is an RI trigger */
1241 bool deferrable; /* [NOT] DEFERRABLE */
1242 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
1243 RangeVar *constrrel; /* opposite relation */
1246 /* ----------------------
1247 * Create/Drop PROCEDURAL LANGUAGE Statement
1248 * ----------------------
1250 typedef struct CreatePLangStmt
1253 char *plname; /* PL name */
1254 List *plhandler; /* PL call handler function (qual. name) */
1255 List *plvalidator; /* optional validator function (qual. name) */
1256 bool pltrusted; /* PL is trusted */
1259 typedef struct DropPLangStmt
1262 char *plname; /* PL name */
1263 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1264 bool missing_ok; /* skip error if missing? */
1267 /* ----------------------
1268 * Create/Alter/Drop Role Statements
1270 * Note: these node types are also used for the backwards-compatible
1271 * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases
1272 * there's really no need to distinguish what the original spelling was,
1273 * but for CREATE we mark the type because the defaults vary.
1274 * ----------------------
1276 typedef enum RoleStmtType
1283 typedef struct CreateRoleStmt
1286 RoleStmtType stmt_type; /* ROLE/USER/GROUP */
1287 char *role; /* role name */
1288 List *options; /* List of DefElem nodes */
1291 typedef struct AlterRoleStmt
1294 char *role; /* role name */
1295 List *options; /* List of DefElem nodes */
1296 int action; /* +1 = add members, -1 = drop members */
1299 typedef struct AlterRoleSetStmt
1302 char *role; /* role name */
1303 VariableSetStmt *setstmt; /* SET or RESET subcommand */
1306 typedef struct DropRoleStmt
1309 List *roles; /* List of roles to remove */
1310 bool missing_ok; /* skip error if a role is missing? */
1313 /* ----------------------
1314 * {Create|Alter} SEQUENCE Statement
1315 * ----------------------
1318 typedef struct CreateSeqStmt
1321 RangeVar *sequence; /* the sequence to create */
1325 typedef struct AlterSeqStmt
1328 RangeVar *sequence; /* the sequence to alter */
1332 /* ----------------------
1333 * Create {Aggregate|Operator|Type} Statement
1334 * ----------------------
1336 typedef struct DefineStmt
1339 ObjectType kind; /* aggregate, operator, type */
1340 bool oldstyle; /* hack to signal old CREATE AGG syntax */
1341 List *defnames; /* qualified name (list of Value strings) */
1342 List *args; /* a list of TypeName (if needed) */
1343 List *definition; /* a list of DefElem */
1346 /* ----------------------
1347 * Create Domain Statement
1348 * ----------------------
1350 typedef struct CreateDomainStmt
1353 List *domainname; /* qualified name (list of Value strings) */
1354 TypeName *typename; /* the base type */
1355 List *constraints; /* constraints (list of Constraint nodes) */
1358 /* ----------------------
1359 * Create Operator Class Statement
1360 * ----------------------
1362 typedef struct CreateOpClassStmt
1365 List *opclassname; /* qualified name (list of Value strings) */
1366 List *opfamilyname; /* qualified name (ditto); NIL if omitted */
1367 char *amname; /* name of index AM opclass is for */
1368 TypeName *datatype; /* datatype of indexed column */
1369 List *items; /* List of CreateOpClassItem nodes */
1370 bool isDefault; /* Should be marked as default for type? */
1371 } CreateOpClassStmt;
1373 #define OPCLASS_ITEM_OPERATOR 1
1374 #define OPCLASS_ITEM_FUNCTION 2
1375 #define OPCLASS_ITEM_STORAGETYPE 3
1377 typedef struct CreateOpClassItem
1380 int itemtype; /* see codes above */
1381 /* fields used for an operator or function item: */
1382 List *name; /* operator or function name */
1383 List *args; /* argument types */
1384 int number; /* strategy num or support proc num */
1385 bool recheck; /* only used for operators */
1386 List *class_args; /* only used for functions */
1387 /* fields used for a storagetype item: */
1388 TypeName *storedtype; /* datatype stored in index */
1389 } CreateOpClassItem;
1391 /* ----------------------
1392 * Create Operator Family Statement
1393 * ----------------------
1395 typedef struct CreateOpFamilyStmt
1398 List *opfamilyname; /* qualified name (list of Value strings) */
1399 char *amname; /* name of index AM opfamily is for */
1400 } CreateOpFamilyStmt;
1402 /* ----------------------
1403 * Alter Operator Family Statement
1404 * ----------------------
1406 typedef struct AlterOpFamilyStmt
1409 List *opfamilyname; /* qualified name (list of Value strings) */
1410 char *amname; /* name of index AM opfamily is for */
1411 bool isDrop; /* ADD or DROP the items? */
1412 List *items; /* List of CreateOpClassItem nodes */
1413 } AlterOpFamilyStmt;
1415 /* ----------------------
1416 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
1417 * ----------------------
1420 typedef struct DropStmt
1423 List *objects; /* list of sublists of names (as Values) */
1424 ObjectType removeType; /* object type */
1425 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1426 bool missing_ok; /* skip error if object is missing? */
1429 /* ----------------------
1430 * Drop Rule|Trigger Statement
1432 * In general this may be used for dropping any property of a relation;
1433 * for example, someday soon we may have DROP ATTRIBUTE.
1434 * ----------------------
1437 typedef struct DropPropertyStmt
1440 RangeVar *relation; /* owning relation */
1441 char *property; /* name of rule, trigger, etc */
1442 ObjectType removeType; /* OBJECT_RULE or OBJECT_TRIGGER */
1443 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1444 bool missing_ok; /* skip error if missing? */
1447 /* ----------------------
1448 * Truncate Table Statement
1449 * ----------------------
1451 typedef struct TruncateStmt
1454 List *relations; /* relations (RangeVars) to be truncated */
1455 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1458 /* ----------------------
1459 * Comment On Statement
1460 * ----------------------
1462 typedef struct CommentStmt
1465 ObjectType objtype; /* Object's type */
1466 List *objname; /* Qualified name of the object */
1467 List *objargs; /* Arguments if needed (eg, for functions) */
1468 char *comment; /* Comment to insert, or NULL to remove */
1471 /* ----------------------
1472 * Declare Cursor Statement
1474 * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar
1475 * output. After parse analysis it's set to null, and the Query points to the
1476 * DeclareCursorStmt, not vice versa.
1477 * ----------------------
1479 #define CURSOR_OPT_BINARY 0x0001 /* BINARY */
1480 #define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */
1481 #define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */
1482 #define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */
1483 #define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */
1484 #define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */
1486 typedef struct DeclareCursorStmt
1489 char *portalname; /* name of the portal (cursor) */
1490 int options; /* bitmask of options (see above) */
1491 Node *query; /* the raw SELECT query */
1492 } DeclareCursorStmt;
1494 /* ----------------------
1495 * Close Portal Statement
1496 * ----------------------
1498 typedef struct ClosePortalStmt
1501 char *portalname; /* name of the portal (cursor) */
1502 /* NULL means CLOSE ALL */
1505 /* ----------------------
1506 * Fetch Statement (also Move)
1507 * ----------------------
1509 typedef enum FetchDirection
1511 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1514 /* for these, howMany indicates a position; only one row is fetched */
1519 #define FETCH_ALL LONG_MAX
1521 typedef struct FetchStmt
1524 FetchDirection direction; /* see above */
1525 long howMany; /* number of rows, or position argument */
1526 char *portalname; /* name of portal (cursor) */
1527 bool ismove; /* TRUE if MOVE */
1530 /* ----------------------
1531 * Create Index Statement
1532 * ----------------------
1534 typedef struct IndexStmt
1537 char *idxname; /* name of new index, or NULL for default */
1538 RangeVar *relation; /* relation to build index on */
1539 char *accessMethod; /* name of access method (eg. btree) */
1540 char *tableSpace; /* tablespace, or NULL to use parent's */
1541 List *indexParams; /* a list of IndexElem */
1542 List *options; /* options from WITH clause */
1543 Node *whereClause; /* qualification (partial-index predicate) */
1544 bool unique; /* is index unique? */
1545 bool primary; /* is index on primary key? */
1546 bool isconstraint; /* is it from a CONSTRAINT clause? */
1547 bool concurrent; /* should this be a concurrent index build? */
1550 /* ----------------------
1551 * Create Function Statement
1552 * ----------------------
1554 typedef struct CreateFunctionStmt
1557 bool replace; /* T => replace if already exists */
1558 List *funcname; /* qualified name of function to create */
1559 List *parameters; /* a list of FunctionParameter */
1560 TypeName *returnType; /* the return type */
1561 List *options; /* a list of DefElem */
1562 List *withClause; /* a list of DefElem */
1563 } CreateFunctionStmt;
1565 typedef enum FunctionParameterMode
1567 /* the assigned enum values appear in pg_proc, don't change 'em! */
1568 FUNC_PARAM_IN = 'i', /* input only */
1569 FUNC_PARAM_OUT = 'o', /* output only */
1570 FUNC_PARAM_INOUT = 'b' /* both */
1571 } FunctionParameterMode;
1573 typedef struct FunctionParameter
1576 char *name; /* parameter name, or NULL if not given */
1577 TypeName *argType; /* TypeName for parameter type */
1578 FunctionParameterMode mode; /* IN/OUT/INOUT */
1579 } FunctionParameter;
1581 typedef struct AlterFunctionStmt
1584 FuncWithArgs *func; /* name and args of function */
1585 List *actions; /* list of DefElem */
1586 } AlterFunctionStmt;
1588 /* ----------------------
1589 * Drop {Function|Aggregate|Operator} Statement
1590 * ----------------------
1592 typedef struct RemoveFuncStmt
1595 ObjectType kind; /* function, aggregate, operator */
1596 List *name; /* qualified name of object to drop */
1597 List *args; /* types of the arguments */
1598 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1599 bool missing_ok; /* skip error if missing? */
1602 /* ----------------------
1603 * Drop Operator Class Statement
1604 * ----------------------
1606 typedef struct RemoveOpClassStmt
1609 List *opclassname; /* qualified name (list of Value strings) */
1610 char *amname; /* name of index AM opclass is for */
1611 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1612 bool missing_ok; /* skip error if missing? */
1613 } RemoveOpClassStmt;
1615 /* ----------------------
1616 * Drop Operator Family Statement
1617 * ----------------------
1619 typedef struct RemoveOpFamilyStmt
1622 List *opfamilyname; /* qualified name (list of Value strings) */
1623 char *amname; /* name of index AM opfamily is for */
1624 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1625 bool missing_ok; /* skip error if missing? */
1626 } RemoveOpFamilyStmt;
1628 /* ----------------------
1629 * Alter Object Rename Statement
1630 * ----------------------
1632 typedef struct RenameStmt
1635 ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
1636 RangeVar *relation; /* in case it's a table */
1637 List *object; /* in case it's some other object */
1638 List *objarg; /* argument types, if applicable */
1639 char *subname; /* name of contained object (column, rule,
1641 char *newname; /* the new name */
1644 /* ----------------------
1645 * ALTER object SET SCHEMA Statement
1646 * ----------------------
1648 typedef struct AlterObjectSchemaStmt
1651 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1652 RangeVar *relation; /* in case it's a table */
1653 List *object; /* in case it's some other object */
1654 List *objarg; /* argument types, if applicable */
1655 char *addname; /* additional name if needed */
1656 char *newschema; /* the new schema */
1657 } AlterObjectSchemaStmt;
1659 /* ----------------------
1660 * Alter Object Owner Statement
1661 * ----------------------
1663 typedef struct AlterOwnerStmt
1666 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1667 RangeVar *relation; /* in case it's a table */
1668 List *object; /* in case it's some other object */
1669 List *objarg; /* argument types, if applicable */
1670 char *addname; /* additional name if needed */
1671 char *newowner; /* the new owner */
1675 /* ----------------------
1676 * Create Rule Statement
1677 * ----------------------
1679 typedef struct RuleStmt
1682 RangeVar *relation; /* relation the rule is for */
1683 char *rulename; /* name of the rule */
1684 Node *whereClause; /* qualifications */
1685 CmdType event; /* SELECT, INSERT, etc */
1686 bool instead; /* is a 'do instead'? */
1687 List *actions; /* the action statements */
1688 bool replace; /* OR REPLACE */
1691 /* ----------------------
1693 * ----------------------
1695 typedef struct NotifyStmt
1698 RangeVar *relation; /* qualified name to notify */
1701 /* ----------------------
1703 * ----------------------
1705 typedef struct ListenStmt
1708 RangeVar *relation; /* qualified name to listen on */
1711 /* ----------------------
1712 * Unlisten Statement
1713 * ----------------------
1715 typedef struct UnlistenStmt
1718 RangeVar *relation; /* qualified name to unlisten on, or '*' */
1721 /* ----------------------
1722 * {Begin|Commit|Rollback} Transaction Statement
1723 * ----------------------
1725 typedef enum TransactionStmtKind
1728 TRANS_STMT_START, /* semantically identical to BEGIN */
1730 TRANS_STMT_ROLLBACK,
1731 TRANS_STMT_SAVEPOINT,
1733 TRANS_STMT_ROLLBACK_TO,
1735 TRANS_STMT_COMMIT_PREPARED,
1736 TRANS_STMT_ROLLBACK_PREPARED
1737 } TransactionStmtKind;
1739 typedef struct TransactionStmt
1742 TransactionStmtKind kind; /* see above */
1743 List *options; /* for BEGIN/START and savepoint commands */
1744 char *gid; /* for two-phase-commit related commands */
1747 /* ----------------------
1748 * Create Type Statement, composite types
1749 * ----------------------
1751 typedef struct CompositeTypeStmt
1754 RangeVar *typevar; /* the composite type to be created */
1755 List *coldeflist; /* list of ColumnDef nodes */
1756 } CompositeTypeStmt;
1758 /* ----------------------
1759 * Create Type Statement, enum types
1760 * ----------------------
1762 typedef struct CreateEnumStmt
1765 List *typename; /* qualified name (list of Value strings) */
1766 List *vals; /* enum values (list of Value strings) */
1770 /* ----------------------
1771 * Create View Statement
1772 * ----------------------
1774 typedef struct ViewStmt
1777 RangeVar *view; /* the view to be created */
1778 List *aliases; /* target column names */
1779 Node *query; /* the SELECT query */
1780 bool replace; /* replace an existing view? */
1783 /* ----------------------
1785 * ----------------------
1787 typedef struct LoadStmt
1790 char *filename; /* file to load */
1793 /* ----------------------
1794 * Createdb Statement
1795 * ----------------------
1797 typedef struct CreatedbStmt
1800 char *dbname; /* name of database to create */
1801 List *options; /* List of DefElem nodes */
1804 /* ----------------------
1806 * ----------------------
1808 typedef struct AlterDatabaseStmt
1811 char *dbname; /* name of database to alter */
1812 List *options; /* List of DefElem nodes */
1813 } AlterDatabaseStmt;
1815 typedef struct AlterDatabaseSetStmt
1818 char *dbname; /* database name */
1819 VariableSetStmt *setstmt; /* SET or RESET subcommand */
1820 } AlterDatabaseSetStmt;
1822 /* ----------------------
1824 * ----------------------
1826 typedef struct DropdbStmt
1829 char *dbname; /* database to drop */
1830 bool missing_ok; /* skip error if db is missing? */
1833 /* ----------------------
1834 * Cluster Statement (support pbrown's cluster index implementation)
1835 * ----------------------
1837 typedef struct ClusterStmt
1840 RangeVar *relation; /* relation being indexed, or NULL if all */
1841 char *indexname; /* original index defined */
1844 /* ----------------------
1845 * Vacuum and Analyze Statements
1847 * Even though these are nominally two statements, it's convenient to use
1848 * just one node type for both.
1849 * ----------------------
1851 typedef struct VacuumStmt
1854 bool vacuum; /* do VACUUM step */
1855 bool full; /* do FULL (non-concurrent) vacuum */
1856 bool analyze; /* do ANALYZE step */
1857 bool verbose; /* print progress info */
1858 int freeze_min_age; /* min freeze age, or -1 to use default */
1859 RangeVar *relation; /* single table to process, or NULL */
1860 List *va_cols; /* list of column names, or NIL for all */
1863 /* ----------------------
1865 * ----------------------
1867 typedef struct ExplainStmt
1870 Node *query; /* the query (as a raw parse tree) */
1871 bool verbose; /* print plan info */
1872 bool analyze; /* get statistics by executing plan */
1875 /* ----------------------
1876 * Checkpoint Statement
1877 * ----------------------
1879 typedef struct CheckPointStmt
1884 /* ----------------------
1886 * ----------------------
1889 typedef enum DiscardMode
1896 typedef struct DiscardStmt
1902 /* ----------------------
1904 * ----------------------
1906 typedef struct LockStmt
1909 List *relations; /* relations to lock */
1910 int mode; /* lock mode */
1911 bool nowait; /* no wait mode */
1914 /* ----------------------
1915 * SET CONSTRAINTS Statement
1916 * ----------------------
1918 typedef struct ConstraintsSetStmt
1921 List *constraints; /* List of names as RangeVars */
1923 } ConstraintsSetStmt;
1925 /* ----------------------
1927 * ----------------------
1929 typedef struct ReindexStmt
1932 ObjectType kind; /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_DATABASE */
1933 RangeVar *relation; /* Table or index to reindex */
1934 const char *name; /* name of database to reindex */
1935 bool do_system; /* include system tables in database case */
1936 bool do_user; /* include user tables in database case */
1939 /* ----------------------
1940 * CREATE CONVERSION Statement
1941 * ----------------------
1943 typedef struct CreateConversionStmt
1946 List *conversion_name; /* Name of the conversion */
1947 char *for_encoding_name; /* source encoding name */
1948 char *to_encoding_name; /* destination encoding name */
1949 List *func_name; /* qualified conversion function name */
1950 bool def; /* is this a default conversion? */
1951 } CreateConversionStmt;
1953 /* ----------------------
1954 * CREATE CAST Statement
1955 * ----------------------
1957 typedef struct CreateCastStmt
1960 TypeName *sourcetype;
1961 TypeName *targettype;
1963 CoercionContext context;
1966 /* ----------------------
1967 * DROP CAST Statement
1968 * ----------------------
1970 typedef struct DropCastStmt
1973 TypeName *sourcetype;
1974 TypeName *targettype;
1975 DropBehavior behavior;
1976 bool missing_ok; /* skip error if missing? */
1980 /* ----------------------
1982 * ----------------------
1984 typedef struct PrepareStmt
1987 char *name; /* Name of plan, arbitrary */
1988 List *argtypes; /* Types of parameters (List of TypeName) */
1989 Node *query; /* The query itself (as a raw parsetree) */
1993 /* ----------------------
1995 * ----------------------
1998 typedef struct ExecuteStmt
2001 char *name; /* The name of the plan to execute */
2002 IntoClause *into; /* Optional table to store results in */
2003 List *params; /* Values to assign to parameters */
2007 /* ----------------------
2008 * DEALLOCATE Statement
2009 * ----------------------
2011 typedef struct DeallocateStmt
2014 char *name; /* The name of the plan to remove */
2015 /* NULL means DEALLOCATE ALL */
2019 * DROP OWNED statement
2021 typedef struct DropOwnedStmt
2025 DropBehavior behavior;
2029 * REASSIGN OWNED statement
2031 typedef struct ReassignOwnedStmt
2036 } ReassignOwnedStmt;
2039 * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
2041 typedef struct AlterTSDictionaryStmt
2044 List *dictname; /* qualified name (list of Value strings) */
2045 List *options; /* List of DefElem nodes */
2046 } AlterTSDictionaryStmt;
2049 * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
2051 typedef struct AlterTSConfigurationStmt
2054 List *cfgname; /* qualified name (list of Value strings) */
2057 * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is
2058 * NIL, but tokentype isn't, DROP MAPPING was specified.
2060 List *tokentype; /* list of Value strings */
2061 List *dicts; /* list of list of Value strings */
2062 bool override; /* if true - remove old variant */
2063 bool replace; /* if true - replace dictionary by another */
2064 bool missing_ok; /* for DROP - skip error if missing? */
2065 } AlterTSConfigurationStmt;
2067 #endif /* PARSENODES_H */