1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
7 * Portions Copyright (c) 2003-2008, PgPool Global Development Group
8 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.353 2007/09/03 18:46:30 tgl Exp $
13 *-------------------------------------------------------------------------
18 #include "primnodes.h"
21 /* Possible sources of a Query */
22 typedef enum QuerySource
24 QSRC_ORIGINAL, /* original parsetree (explicit query) */
25 QSRC_PARSER, /* added by parse analysis (now unused) */
26 QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */
27 QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */
28 QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */
31 /* Sort ordering options for ORDER BY and CREATE INDEX */
32 typedef enum SortByDir
37 SORTBY_USING /* not allowed in CREATE INDEX ... */
40 typedef enum SortByNulls
49 * Grantable rights are encoded so that we can OR them together in a bitmask.
50 * The present representation of AclItem limits us to 16 distinct rights,
51 * even though AclMode is defined as uint32. See utils/acl.h.
53 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
55 typedef unsigned int AclMode; /* a bitmask of privilege bits */
57 #define ACL_INSERT (1<<0) /* for relations */
58 #define ACL_SELECT (1<<1)
59 #define ACL_UPDATE (1<<2)
60 #define ACL_DELETE (1<<3)
61 /* #define ACL_RULE (1<<4) unused, available */
62 #define ACL_REFERENCES (1<<5)
63 #define ACL_TRIGGER (1<<6)
64 #define ACL_EXECUTE (1<<7) /* for functions */
65 #define ACL_USAGE (1<<8) /* for languages and namespaces */
66 #define ACL_CREATE (1<<9) /* for namespaces and databases */
67 #define ACL_CREATE_TEMP (1<<10) /* for databases */
68 #define ACL_CONNECT (1<<11) /* for databases */
69 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */
70 #define ACL_NO_RIGHTS 0
71 /* Currently, SELECT ... FOR UPDATE/FOR SHARE requires UPDATE privileges */
72 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE
75 /*****************************************************************************
77 *****************************************************************************/
81 * Parse analysis turns all statements into a Query tree (via transformStmt)
82 * for further processing by the rewriter and planner.
84 * Utility statements (i.e. non-optimizable statements) have the
85 * utilityStmt field set, and the Query itself is mostly dummy.
86 * DECLARE CURSOR is a special case: it is represented like a SELECT,
87 * but the original DeclareCursorStmt is stored in utilityStmt.
89 * Planning converts a Query tree into a Plan tree headed by a PlannedStmt
90 * node --- the Query structure is not used by the executor.
96 CmdType commandType; /* select|insert|update|delete|utility */
98 QuerySource querySource; /* where did I come from? */
100 bool canSetTag; /* do I set the command result tag? */
102 Node *utilityStmt; /* non-null if this is DECLARE CURSOR or a
103 * non-optimizable statement */
105 int resultRelation; /* rtable index of target relation for
106 * INSERT/UPDATE/DELETE; 0 for SELECT */
108 IntoClause *intoClause; /* target for SELECT INTO / CREATE TABLE AS */
110 bool hasAggs; /* has aggregates in tlist or havingQual */
111 bool hasSubLinks; /* has subquery SubLink */
113 List *rtable; /* list of range table entries */
114 FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */
116 List *targetList; /* target list (of TargetEntry) */
118 List *returningList; /* return-values list (of TargetEntry) */
120 List *groupClause; /* a list of GroupClause's */
122 Node *havingQual; /* qualifications applied to groups */
124 List *distinctClause; /* a list of SortClause's */
126 List *sortClause; /* a list of SortClause's */
128 Node *limitOffset; /* # of result tuples to skip (int8 expr) */
129 Node *limitCount; /* # of result tuples to return (int8 expr) */
131 List *rowMarks; /* a list of RowMarkClause's */
133 Node *setOperations; /* set-operation tree if this is top level of
134 * a UNION/INTERSECT/EXCEPT query */
138 /****************************************************************************
139 * Supporting data structures for Parse Trees
141 * Most of these node types appear in raw parsetrees output by the grammar,
142 * and get transformed to something else by the analyzer. A few of them
143 * are used as-is in transformed querytrees.
145 * Many of the node types used in raw parsetrees include a "location" field.
146 * This is a byte (not character) offset in the original source text, to be
147 * used for positioning an error cursor when there is an analysis-time
148 * error related to the node.
149 ****************************************************************************/
152 * TypeName - specifies a type in definitions
154 * For TypeName structures generated internally, it is often easier to
155 * specify the type by OID than by name. If "names" is NIL then the
156 * actual type OID is given by typeid, otherwise typeid is unused.
157 * Similarly, if "typmods" is NIL then the actual typmod is expected to
158 * be prespecified in typemod, otherwise typemod is unused.
160 * If pct_type is TRUE, then names is actually a field name and we look up
161 * the type of that field. Otherwise (the normal case), names is a type
162 * name possibly qualified with schema and database name.
164 typedef struct TypeName
167 List *names; /* qualified name (list of Value strings) */
168 Oid typeid; /* type identified by OID */
169 bool timezone; /* timezone specified? */
170 bool setof; /* is a set? */
171 bool pct_type; /* %TYPE specified? */
172 List *typmods; /* type modifier expression(s) */
173 int32 typemod; /* prespecified type modifier */
174 List *arrayBounds; /* array bounds */
175 int location; /* token location, or -1 if unknown */
179 * ColumnRef - specifies a reference to a column, or possibly a whole tuple
181 * The "fields" list must be nonempty; its last component may be "*"
182 * instead of a regular field name.
184 * Note: any array subscripting or selection of fields from composite columns
185 * is represented by an A_Indirection node above the ColumnRef. However,
186 * for simplicity in the normal case, initial field selection from a table
187 * name is represented within ColumnRef and not by adding A_Indirection.
189 typedef struct ColumnRef
192 List *fields; /* field names (list of Value strings) */
193 int location; /* token location, or -1 if unknown */
197 * ParamRef - specifies a $n parameter reference
199 typedef struct ParamRef
202 int number; /* the number of the parameter */
206 * A_Expr - infix, prefix, and postfix expressions
208 typedef enum A_Expr_Kind
210 AEXPR_OP, /* normal operator */
211 AEXPR_AND, /* booleans - name field is unused */
214 AEXPR_OP_ANY, /* scalar op ANY (array) */
215 AEXPR_OP_ALL, /* scalar op ALL (array) */
216 AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */
217 AEXPR_NULLIF, /* NULLIF - name must be "=" */
218 AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */
219 AEXPR_IN /* [NOT] IN - name must be "=" or "<>" */
222 typedef struct A_Expr
225 A_Expr_Kind kind; /* see above */
226 List *name; /* possibly-qualified name of operator */
227 Node *lexpr; /* left argument, or NULL if none */
228 Node *rexpr; /* right argument, or NULL if none */
229 int location; /* token location, or -1 if unknown */
233 * A_Const - a constant expression
235 typedef struct A_Const
238 Value val; /* the value (with the tag) */
239 TypeName *typename; /* typecast, or NULL if none */
243 * TypeCast - a CAST expression
245 * NOTE: for mostly historical reasons, A_Const parsenodes contain
246 * room for a TypeName; we only generate a separate TypeCast node if the
247 * argument to be casted is not a constant. In theory either representation
248 * would work, but the combined representation saves a bit of code in many
249 * productions in gram.y.
251 typedef struct TypeCast
254 Node *arg; /* the expression being casted */
255 TypeName *typename; /* the target type */
259 * FuncCall - a function or aggregate invocation
261 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
262 * indicates we saw 'foo(DISTINCT ...)'. In either case, the construct
263 * *must* be an aggregate call. Otherwise, it might be either an
264 * aggregate or some other kind of function.
266 typedef struct FuncCall
269 List *funcname; /* qualified name of function */
270 List *args; /* the arguments (list of exprs) */
271 bool agg_star; /* argument was really '*' */
272 bool agg_distinct; /* arguments were labeled DISTINCT */
273 int location; /* token location, or -1 if unknown */
277 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
279 typedef struct A_Indices
282 Node *lidx; /* could be NULL */
287 * A_Indirection - select a field and/or array element from an expression
289 * The indirection list can contain both A_Indices nodes (representing
290 * subscripting) and string Value nodes (representing field selection
291 * --- the string value is the name of the field to select). For example,
292 * a complex selection operation like
293 * (foo).field1[42][7].field2
294 * would be represented with a single A_Indirection node having a 4-element
297 * Note: as of Postgres 8.0, we don't support arrays of composite values,
298 * so cases in which a field select follows a subscript aren't actually
299 * semantically legal. However the parser is prepared to handle such.
301 typedef struct A_Indirection
304 Node *arg; /* the thing being selected from */
305 List *indirection; /* subscripts and/or field names */
310 * result target (used in target list of pre-transformed parse trees)
312 * In a SELECT target list, 'name' is the column label from an
313 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
314 * value expression itself. The 'indirection' field is not used.
316 * INSERT uses ResTarget in its target-column-names list. Here, 'name' is
317 * the name of the destination column, 'indirection' stores any subscripts
318 * attached to the destination, and 'val' is not used.
320 * In an UPDATE target list, 'name' is the name of the destination column,
321 * 'indirection' stores any subscripts attached to the destination, and
322 * 'val' is the expression to assign.
324 * See A_Indirection for more info about what can appear in 'indirection'.
326 typedef struct ResTarget
329 char *name; /* column name or NULL */
330 List *indirection; /* subscripts and field names, or NIL */
331 Node *val; /* the value expression to compute or assign */
332 int location; /* token location, or -1 if unknown */
336 * SortBy - for ORDER BY clause
338 typedef struct SortBy
341 SortByDir sortby_dir; /* ASC/DESC/USING */
342 SortByNulls sortby_nulls; /* NULLS FIRST/LAST */
343 List *useOp; /* name of op to use, if SORTBY_USING */
344 Node *node; /* expression to sort on */
348 * RangeSubselect - subquery appearing in a FROM clause
350 typedef struct RangeSubselect
353 Node *subquery; /* the untransformed sub-select clause */
354 Alias *alias; /* table alias & optional column aliases */
358 * RangeFunction - function call appearing in a FROM clause
360 typedef struct RangeFunction
363 Node *funccallnode; /* untransformed function call tree */
364 Alias *alias; /* table alias & optional column aliases */
365 List *coldeflist; /* list of ColumnDef nodes to describe result
366 * of function returning RECORD */
370 * ColumnDef - column definition (used in various creates)
372 * If the column has a default value, we may have the value expression
373 * in either "raw" form (an untransformed parse tree) or "cooked" form
374 * (the nodeToString representation of an executable expression tree),
375 * depending on how this ColumnDef node was created (by parsing, or by
376 * inheritance from an existing relation). We should never have both
379 * The constraints list may contain a CONSTR_DEFAULT item in a raw
380 * parsetree produced by gram.y, but transformCreateStmt will remove
381 * the item and set raw_default instead. CONSTR_DEFAULT items
382 * should not appear in any subsequent processing.
384 typedef struct ColumnDef
387 char *colname; /* name of column */
388 TypeName *typename; /* type of column */
389 int inhcount; /* number of times column is inherited */
390 bool is_local; /* column has local (non-inherited) def'n */
391 bool is_not_null; /* NOT NULL constraint specified? */
392 Node *raw_default; /* default value (untransformed parse tree) */
393 char *cooked_default; /* nodeToString representation */
394 List *constraints; /* other constraints on column */
398 * inhRelation - Relations a CREATE TABLE is to inherit attributes of
400 typedef struct InhRelation
404 List *options; /* integer List of CreateStmtLikeOption */
407 typedef enum CreateStmtLikeOption
409 CREATE_TABLE_LIKE_INCLUDING_DEFAULTS,
410 CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS,
411 CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS,
412 CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS,
413 CREATE_TABLE_LIKE_INCLUDING_INDEXES,
414 CREATE_TABLE_LIKE_EXCLUDING_INDEXES
415 } CreateStmtLikeOption;
418 * IndexElem - index parameters (used in CREATE INDEX)
420 * For a plain index attribute, 'name' is the name of the table column to
421 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and
422 * 'expr' is the expression tree.
424 typedef struct IndexElem
427 char *name; /* name of attribute to index, or NULL */
428 Node *expr; /* expression to index, or NULL */
429 List *opclass; /* name of desired opclass; NIL = default */
430 SortByDir ordering; /* ASC/DESC/default */
431 SortByNulls nulls_ordering; /* FIRST/LAST/default */
436 * a definition (used in definition lists in the form of defname = arg)
438 typedef struct DefElem
442 Node *arg; /* a (Value *) or a (TypeName *) */
446 * LockingClause - raw representation of FOR UPDATE/SHARE options
448 * Note: lockedRels == NIL means "all relations in query". Otherwise it
449 * is a list of String nodes giving relation eref names.
451 typedef struct LockingClause
454 List *lockedRels; /* FOR UPDATE or FOR SHARE relations */
455 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
456 bool noWait; /* NOWAIT option */
462 typedef struct XmlSerialize
465 XmlOptionType xmloption;
471 /****************************************************************************
472 * Nodes for a Query tree
473 ****************************************************************************/
475 /*--------------------
477 * A range table is a List of RangeTblEntry nodes.
479 * A range table entry may represent a plain relation, a sub-select in
480 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax
481 * produces an RTE, not the implicit join resulting from multiple FROM
482 * items. This is because we only need the RTE to deal with SQL features
483 * like outer joins and join-output-column aliasing.) Other special
484 * RTE types also exist, as indicated by RTEKind.
486 * alias is an Alias node representing the AS alias-clause attached to the
487 * FROM expression, or NULL if no clause.
489 * eref is the table reference name and column reference names (either
490 * real or aliases). Note that system columns (OID etc) are not included
491 * in the column list.
492 * eref->aliasname is required to be present, and should generally be used
493 * to identify the RTE for error messages etc.
495 * In RELATION RTEs, the colnames in both alias and eref are indexed by
496 * physical attribute number; this means there must be colname entries for
497 * dropped columns. When building an RTE we insert empty strings ("") for
498 * dropped columns. Note however that a stored rule may have nonempty
499 * colnames for columns dropped since the rule was created (and for that
500 * matter the colnames might be out of date due to column renamings).
501 * The same comments apply to FUNCTION RTEs when the function's return type
502 * is a named composite type.
504 * In JOIN RTEs, the colnames in both alias and eref are one-to-one with
505 * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when
506 * those columns are known to be dropped at parse time. Again, however,
507 * a stored rule might contain entries for columns dropped since the rule
508 * was created. (This is only possible for columns not actually referenced
509 * in the rule.) When loading a stored rule, we replace the joinaliasvars
510 * items for any such columns with NULL Consts. (We can't simply delete
511 * them from the joinaliasvars list, because that would affect the attnums
512 * of Vars referencing the rest of the list.)
514 * inh is TRUE for relation references that should be expanded to include
515 * inheritance children, if the rel has any. This *must* be FALSE for
516 * RTEs other than RTE_RELATION entries.
518 * inFromCl marks those range variables that are listed in the FROM clause.
519 * It's false for RTEs that are added to a query behind the scenes, such
520 * as the NEW and OLD variables for a rule, or the subqueries of a UNION.
521 * This flag is not used anymore during parsing, since the parser now uses
522 * a separate "namespace" data structure to control visibility, but it is
523 * needed by ruleutils.c to determine whether RTEs should be shown in
524 * decompiled queries.
526 * requiredPerms and checkAsUser specify run-time access permissions
527 * checks to be performed at query startup. The user must have *all*
528 * of the permissions that are OR'd together in requiredPerms (zero
529 * indicates no permissions checking). If checkAsUser is not zero,
530 * then do the permissions checks using the access rights of that user,
531 * not the current effective user ID. (This allows rules to act as
533 *--------------------
537 RTE_RELATION, /* ordinary relation reference */
538 RTE_SUBQUERY, /* subquery in FROM */
540 RTE_SPECIAL, /* special rule relation (NEW or OLD) */
541 RTE_FUNCTION, /* function in FROM */
542 RTE_VALUES /* VALUES (<exprlist>), (<exprlist>), ... */
545 typedef struct RangeTblEntry
549 RTEKind rtekind; /* see above */
552 * XXX the fields applicable to only some rte kinds should be merged into
553 * a union. I didn't do this yet because the diffs would impact a lot of
554 * code that is being actively worked on. FIXME later.
558 * Fields valid for a plain relation RTE (else zero):
560 Oid relid; /* OID of the relation */
563 * Fields valid for a subquery RTE (else NULL):
565 Query *subquery; /* the sub-query */
568 * Fields valid for a function RTE (else NULL):
570 * If the function returns RECORD, funccoltypes lists the column types
571 * declared in the RTE's column type specification, and funccoltypmods
572 * lists their declared typmods. Otherwise, both fields are NIL.
574 Node *funcexpr; /* expression tree for func call */
575 List *funccoltypes; /* OID list of column type OIDs */
576 List *funccoltypmods; /* integer list of column typmods */
579 * Fields valid for a values RTE (else NIL):
581 List *values_lists; /* list of expression lists */
584 * Fields valid for a join RTE (else NULL/zero):
586 * joinaliasvars is a list of Vars or COALESCE expressions corresponding
587 * to the columns of the join result. An alias Var referencing column K
588 * of the join result can be replaced by the K'th element of joinaliasvars
589 * --- but to simplify the task of reverse-listing aliases correctly, we
590 * do not do that until planning time. In a Query loaded from a stored
591 * rule, it is also possible for joinaliasvars items to be NULL Consts,
592 * denoting columns dropped since the rule was made.
594 JoinType jointype; /* type of join */
595 List *joinaliasvars; /* list of alias-var expansions */
598 * Fields valid in all RTEs:
600 Alias *alias; /* user-written alias clause, if any */
601 Alias *eref; /* expanded reference names */
602 bool inh; /* inheritance requested? */
603 bool inFromCl; /* present in FROM clause? */
604 AclMode requiredPerms; /* bitmask of required access permissions */
605 Oid checkAsUser; /* if valid, check access as this role */
610 * representation of ORDER BY clauses
612 * tleSortGroupRef must match ressortgroupref of exactly one entry of the
613 * associated targetlist; that is the expression to be sorted (or grouped) by.
614 * sortop is the OID of the ordering operator (a "<" or ">" operator).
615 * nulls_first does about what you'd expect.
617 * SortClauses are also used to identify targets that we will do a "Unique"
618 * filter step on (for SELECT DISTINCT and SELECT DISTINCT ON). The
619 * distinctClause list is simply a copy of the relevant members of the
620 * sortClause list. Note that distinctClause can be a subset of sortClause,
621 * but cannot have members not present in sortClause; and the members that
622 * do appear must be in the same order as in sortClause.
624 typedef struct SortClause
627 Index tleSortGroupRef; /* reference into targetlist */
628 Oid sortop; /* the ordering operator ('<' op) */
629 bool nulls_first; /* do NULLs come before normal values? */
634 * representation of GROUP BY clauses
636 * GroupClause is exactly like SortClause except for the nodetag value.
637 * We have routines that operate interchangeably on both.
639 * XXX SortClause overspecifies the semantics so far as GROUP BY is concerned
640 * (ditto for DISTINCT). It'd be better to specify an equality operator not
641 * an ordering operator. However, the two implementations are tightly entwined
642 * at the moment ... breaking them apart is work for another day.
644 typedef SortClause GroupClause;
648 * representation of FOR UPDATE/SHARE clauses
650 * We create a separate RowMarkClause node for each target relation
652 typedef struct RowMarkClause
655 Index rti; /* range table index of target relation */
656 bool forUpdate; /* true = FOR UPDATE, false = FOR SHARE */
657 bool noWait; /* NOWAIT option */
660 /*****************************************************************************
661 * Optimizable Statements
662 *****************************************************************************/
664 /* ----------------------
667 * The source expression is represented by SelectStmt for both the
668 * SELECT and VALUES cases. If selectStmt is NULL, then the query
669 * is INSERT ... DEFAULT VALUES.
670 * ----------------------
672 typedef struct InsertStmt
675 RangeVar *relation; /* relation to insert into */
676 List *cols; /* optional: names of the target columns */
677 Node *selectStmt; /* the source SELECT/VALUES, or NULL */
678 List *returningList; /* list of expressions to return */
681 /* ----------------------
683 * ----------------------
685 typedef struct DeleteStmt
688 RangeVar *relation; /* relation to delete from */
689 List *usingClause; /* optional using clause for more tables */
690 Node *whereClause; /* qualifications */
691 List *returningList; /* list of expressions to return */
694 /* ----------------------
696 * ----------------------
698 typedef struct UpdateStmt
701 RangeVar *relation; /* relation to update */
702 List *targetList; /* the target list (of ResTarget) */
703 Node *whereClause; /* qualifications */
704 List *fromClause; /* optional from clause for more tables */
705 List *returningList; /* list of expressions to return */
708 /* ----------------------
711 * A "simple" SELECT is represented in the output of gram.y by a single
712 * SelectStmt node; so is a VALUES construct. A query containing set
713 * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
714 * nodes, in which the leaf nodes are component SELECTs and the internal nodes
715 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node
716 * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
717 * LIMIT, etc, clause values into a SELECT statement without worrying
718 * whether it is a simple or compound SELECT.
719 * ----------------------
721 typedef enum SetOperation
729 typedef struct SelectStmt
734 * These fields are used only in "leaf" SelectStmts.
736 List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
737 * lcons(NIL,NIL) for all (SELECT DISTINCT) */
738 IntoClause *intoClause; /* target for SELECT INTO / CREATE TABLE AS */
739 List *targetList; /* the target list (of ResTarget) */
740 List *fromClause; /* the FROM clause */
741 Node *whereClause; /* WHERE qualification */
742 List *groupClause; /* GROUP BY clauses */
743 Node *havingClause; /* HAVING conditional-expression */
746 * In a "leaf" node representing a VALUES list, the above fields are all
747 * null, and instead this field is set. Note that the elements of the
748 * sublists are just expressions, without ResTarget decoration. Also note
749 * that a list element can be DEFAULT (represented as a SetToDefault
750 * node), regardless of the context of the VALUES list. It's up to parse
751 * analysis to reject that where not valid.
753 List *valuesLists; /* untransformed list of expression lists */
756 * These fields are used in both "leaf" SelectStmts and upper-level
759 List *sortClause; /* sort clause (a list of SortBy's) */
760 Node *limitOffset; /* # of result tuples to skip */
761 Node *limitCount; /* # of result tuples to return */
762 List *lockingClause; /* FOR UPDATE (list of LockingClause's) */
765 * These fields are used only in upper-level SelectStmts.
767 SetOperation op; /* type of set op */
768 bool all; /* ALL specified? */
769 struct SelectStmt *larg; /* left child */
770 struct SelectStmt *rarg; /* right child */
771 /* Eventually add fields for CORRESPONDING spec here */
775 /* ----------------------
776 * Set Operation node for post-analysis query trees
778 * After parse analysis, a SELECT with set operations is represented by a
779 * top-level Query node containing the leaf SELECTs as subqueries in its
780 * range table. Its setOperations field shows the tree of set operations,
781 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
782 * nodes replaced by SetOperationStmt nodes.
783 * ----------------------
785 typedef struct SetOperationStmt
788 SetOperation op; /* type of set op */
789 bool all; /* ALL specified? */
790 Node *larg; /* left child */
791 Node *rarg; /* right child */
792 /* Eventually add fields for CORRESPONDING spec here */
794 /* Fields derived during parse analysis: */
795 List *colTypes; /* OID list of output column type OIDs */
796 List *colTypmods; /* integer list of output column typmods */
800 /*****************************************************************************
801 * Other Statements (no optimizations required)
803 * These are not touched by parser/analyze.c except to put them into
804 * the utilityStmt field of a Query. This is eventually passed to
805 * ProcessUtility (by-passing rewriting and planning). Some of the
806 * statements do need attention from parse analysis, and this is
807 * done by routines in parser/parse_utilcmd.c after ProcessUtility
808 * receives the command for execution.
809 *****************************************************************************/
812 * When a command can act on several kinds of objects with only one
813 * parse structure required, use these constants to designate the
817 typedef enum ObjectType
840 OBJECT_TSCONFIGURATION,
848 /* ----------------------
849 * Create Schema Statement
851 * NOTE: the schemaElts list contains raw parsetrees for component statements
852 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
853 * executed after the schema itself is created.
854 * ----------------------
856 typedef struct CreateSchemaStmt
859 char *schemaname; /* the name of the schema to create */
860 char *authid; /* the owner of the created schema */
861 List *schemaElts; /* schema components (list of parsenodes) */
864 typedef enum DropBehavior
866 DROP_RESTRICT, /* drop fails if any dependent objects */
867 DROP_CASCADE /* remove dependent objects too */
870 /* ----------------------
872 * ----------------------
874 typedef struct AlterTableStmt
877 RangeVar *relation; /* table to work on */
878 List *cmds; /* list of subcommands */
879 ObjectType relkind; /* type of object */
882 typedef enum AlterTableType
884 AT_AddColumn, /* add column */
885 AT_ColumnDefault, /* alter column default */
886 AT_DropNotNull, /* alter column drop not null */
887 AT_SetNotNull, /* alter column set not null */
888 AT_SetStatistics, /* alter column statistics */
889 AT_SetStorage, /* alter column storage */
890 AT_DropColumn, /* drop column */
891 AT_DropColumnRecurse, /* internal to commands/tablecmds.c */
892 AT_AddIndex, /* add index */
893 AT_ReAddIndex, /* internal to commands/tablecmds.c */
894 AT_AddConstraint, /* add constraint */
895 AT_ProcessedConstraint, /* pre-processed add constraint (local in
896 * parser/parse_utilcmd.c) */
897 AT_DropConstraint, /* drop constraint */
898 AT_DropConstraintQuietly, /* drop constraint, no error/warning (local in
899 * commands/tablecmds.c) */
900 AT_AlterColumnType, /* alter column type */
901 AT_ChangeOwner, /* change owner */
902 AT_ClusterOn, /* CLUSTER ON */
903 AT_DropCluster, /* SET WITHOUT CLUSTER */
904 AT_DropOids, /* SET WITHOUT OIDS */
905 AT_SetTableSpace, /* SET TABLESPACE */
906 AT_SetRelOptions, /* SET (...) -- AM specific parameters */
907 AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */
908 AT_EnableTrig, /* ENABLE TRIGGER name */
909 AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */
910 AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */
911 AT_DisableTrig, /* DISABLE TRIGGER name */
912 AT_EnableTrigAll, /* ENABLE TRIGGER ALL */
913 AT_DisableTrigAll, /* DISABLE TRIGGER ALL */
914 AT_EnableTrigUser, /* ENABLE TRIGGER USER */
915 AT_DisableTrigUser, /* DISABLE TRIGGER USER */
916 AT_EnableRule, /* ENABLE RULE name */
917 AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */
918 AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */
919 AT_DisableRule, /* DISABLE RULE name */
920 AT_AddInherit, /* INHERIT parent */
921 AT_DropInherit /* NO INHERIT parent */
924 typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */
927 AlterTableType subtype; /* Type of table alteration to apply */
928 char *name; /* column, constraint, or trigger to act on,
929 * or new owner or tablespace */
930 Node *def; /* definition of new column, column type,
931 * index, constraint, or parent table */
932 Node *transform; /* transformation expr for ALTER TYPE */
933 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
937 /* ----------------------
940 * The fields are used in different ways by the different variants of
942 * ----------------------
944 typedef struct AlterDomainStmt
947 char subtype; /*------------
948 * T = alter column default
949 * N = alter column drop not null
950 * O = alter column set not null
952 * X = drop constraint
955 List *typename; /* domain to work on */
956 char *name; /* column or constraint name to act on */
957 Node *def; /* definition of default or constraint */
958 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
962 /* ----------------------
963 * Grant|Revoke Statement
964 * ----------------------
966 typedef enum GrantObjectType
968 ACL_OBJECT_RELATION, /* table, view */
969 ACL_OBJECT_SEQUENCE, /* sequence */
970 ACL_OBJECT_DATABASE, /* database */
971 ACL_OBJECT_FUNCTION, /* function */
972 ACL_OBJECT_LANGUAGE, /* procedural language */
973 ACL_OBJECT_NAMESPACE, /* namespace */
974 ACL_OBJECT_TABLESPACE /* tablespace */
977 typedef struct GrantStmt
980 bool is_grant; /* true = GRANT, false = REVOKE */
981 GrantObjectType objtype; /* kind of object being operated on */
982 List *objects; /* list of RangeVar nodes, FuncWithArgs nodes,
983 * or plain names (as Value strings) */
984 List *privileges; /* list of privilege names (as Strings) */
985 /* privileges == NIL denotes "all privileges" */
986 List *grantees; /* list of PrivGrantee nodes */
987 bool grant_option; /* grant or revoke grant option */
988 DropBehavior behavior; /* drop behavior (for REVOKE) */
991 typedef struct PrivGrantee
994 char *rolname; /* if NULL then PUBLIC */
998 * Note: FuncWithArgs carries only the types of the input parameters of the
999 * function. So it is sufficient to identify an existing function, but it
1000 * is not enough info to define a function nor to call it.
1002 typedef struct FuncWithArgs
1005 List *funcname; /* qualified name of function */
1006 List *funcargs; /* list of Typename nodes */
1009 /* This is only used internally in gram.y. */
1010 typedef struct PrivTarget
1013 GrantObjectType objtype;
1017 /* ----------------------
1018 * Grant/Revoke Role Statement
1020 * Note: the lists of roles are lists of names, as Value strings
1021 * ----------------------
1023 typedef struct GrantRoleStmt
1026 List *granted_roles; /* list of roles to be granted/revoked */
1027 List *grantee_roles; /* list of member roles to add/delete */
1028 bool is_grant; /* true = GRANT, false = REVOKE */
1029 bool admin_opt; /* with admin option */
1030 char *grantor; /* set grantor to other than current role */
1031 DropBehavior behavior; /* drop behavior (for REVOKE) */
1034 /* ----------------------
1037 * We support "COPY relation FROM file", "COPY relation TO file", and
1038 * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation"
1039 * and "query" must be non-NULL.
1040 * ----------------------
1042 typedef struct CopyStmt
1045 RangeVar *relation; /* the relation to copy */
1046 Node *query; /* the SELECT query to copy */
1047 List *attlist; /* List of column names (as Strings), or NIL
1048 * for all columns */
1049 bool is_from; /* TO or FROM */
1050 char *filename; /* filename, or NULL for STDIN/STDOUT */
1051 List *options; /* List of DefElem nodes */
1054 /* ----------------------
1055 * SET Statement (includes RESET)
1057 * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
1058 * preserve the distinction in VariableSetKind for CreateCommandTag().
1059 * ----------------------
1063 VAR_SET_VALUE, /* SET var = value */
1064 VAR_SET_DEFAULT, /* SET var TO DEFAULT */
1065 VAR_SET_CURRENT, /* SET var FROM CURRENT */
1066 VAR_SET_MULTI, /* special case for SET TRANSACTION ... */
1067 VAR_RESET, /* RESET var */
1068 VAR_RESET_ALL /* RESET ALL */
1071 typedef struct VariableSetStmt
1074 VariableSetKind kind;
1075 char *name; /* variable to be set */
1076 List *args; /* List of A_Const nodes */
1077 bool is_local; /* SET LOCAL? */
1080 /* ----------------------
1082 * ----------------------
1084 typedef struct VariableShowStmt
1090 /* ----------------------
1091 * Create Table Statement
1093 * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
1094 * nodes are intermixed in tableElts, and constraints is NIL. After parse
1095 * analysis, tableElts contains just ColumnDefs, and constraints contains
1096 * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
1098 * ----------------------
1101 typedef struct CreateStmt
1104 RangeVar *relation; /* relation to create */
1105 List *tableElts; /* column definitions (list of ColumnDef) */
1106 List *inhRelations; /* relations to inherit from (list of
1108 List *constraints; /* constraints (list of Constraint nodes) */
1109 List *options; /* options from WITH clause */
1110 OnCommitAction oncommit; /* what do we do at COMMIT? */
1111 char *tablespacename; /* table space to use, or NULL */
1115 * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
1117 * XXX probably these ought to be unified with FkConstraints at some point?
1118 * To this end we include CONSTR_FOREIGN in the ConstrType enum, even though
1119 * the parser does not generate it.
1121 * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
1122 * we may have the expression in either "raw" form (an untransformed
1123 * parse tree) or "cooked" form (the nodeToString representation of
1124 * an executable expression tree), depending on how this Constraint
1125 * node was created (by parsing, or by inheritance from an existing
1126 * relation). We should never have both in the same node!
1128 * Constraint attributes (DEFERRABLE etc) are initially represented as
1129 * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes
1130 * a pass through the constraints list to attach the info to the appropriate
1131 * FkConstraint node (and, perhaps, someday to other kinds of constraints).
1135 typedef enum ConstrType /* types of constraints */
1137 CONSTR_NULL, /* not SQL92, but a lot of people expect it */
1144 CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
1145 CONSTR_ATTR_NOT_DEFERRABLE,
1146 CONSTR_ATTR_DEFERRED,
1147 CONSTR_ATTR_IMMEDIATE
1150 typedef struct Constraint
1154 char *name; /* name, or NULL if unnamed */
1155 Node *raw_expr; /* expr, as untransformed parse tree */
1156 char *cooked_expr; /* expr, as nodeToString representation */
1157 List *keys; /* String nodes naming referenced column(s) */
1158 List *options; /* options from WITH clause */
1159 char *indexspace; /* index tablespace for PKEY/UNIQUE
1160 * constraints; NULL for default */
1164 * Definitions for FOREIGN KEY constraints in CreateStmt
1166 * Note: FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
1167 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
1168 * stored into pg_constraint.confmatchtype. Changing the code values may
1169 * require an initdb!
1171 * If skip_validation is true then we skip checking that the existing rows
1172 * in the table satisfy the constraint, and just install the catalog entries
1173 * for the constraint. This is currently used only during CREATE TABLE
1174 * (when we know the table must be empty).
1177 #define FKCONSTR_ACTION_NOACTION 'a'
1178 #define FKCONSTR_ACTION_RESTRICT 'r'
1179 #define FKCONSTR_ACTION_CASCADE 'c'
1180 #define FKCONSTR_ACTION_SETNULL 'n'
1181 #define FKCONSTR_ACTION_SETDEFAULT 'd'
1183 #define FKCONSTR_MATCH_FULL 'f'
1184 #define FKCONSTR_MATCH_PARTIAL 'p'
1185 #define FKCONSTR_MATCH_UNSPECIFIED 'u'
1187 typedef struct FkConstraint
1190 char *constr_name; /* Constraint name, or NULL if unnamed */
1191 RangeVar *pktable; /* Primary key table */
1192 List *fk_attrs; /* Attributes of foreign key */
1193 List *pk_attrs; /* Corresponding attrs in PK table */
1194 char fk_matchtype; /* FULL, PARTIAL, UNSPECIFIED */
1195 char fk_upd_action; /* ON UPDATE action */
1196 char fk_del_action; /* ON DELETE action */
1197 bool deferrable; /* DEFERRABLE */
1198 bool initdeferred; /* INITIALLY DEFERRED */
1199 bool skip_validation; /* skip validation of existing rows? */
1203 /* ----------------------
1204 * Create/Drop Table Space Statements
1205 * ----------------------
1208 typedef struct CreateTableSpaceStmt
1211 char *tablespacename;
1214 } CreateTableSpaceStmt;
1216 typedef struct DropTableSpaceStmt
1219 char *tablespacename;
1220 bool missing_ok; /* skip error if missing? */
1221 } DropTableSpaceStmt;
1223 /* ----------------------
1224 * Create/Drop TRIGGER Statements
1225 * ----------------------
1228 typedef struct CreateTrigStmt
1231 char *trigname; /* TRIGGER's name */
1232 RangeVar *relation; /* relation trigger is on */
1233 List *funcname; /* qual. name of function to call */
1234 List *args; /* list of (T_String) Values or NIL */
1235 bool before; /* BEFORE/AFTER */
1236 bool row; /* ROW/STATEMENT */
1237 char actions[4]; /* 1 to 3 of 'i', 'u', 'd', + trailing \0 */
1239 /* The following are used for referential */
1240 /* integrity constraint triggers */
1241 bool isconstraint; /* This is an RI trigger */
1242 bool deferrable; /* [NOT] DEFERRABLE */
1243 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
1244 RangeVar *constrrel; /* opposite relation */
1247 /* ----------------------
1248 * Create/Drop PROCEDURAL LANGUAGE Statement
1249 * ----------------------
1251 typedef struct CreatePLangStmt
1254 char *plname; /* PL name */
1255 List *plhandler; /* PL call handler function (qual. name) */
1256 List *plvalidator; /* optional validator function (qual. name) */
1257 bool pltrusted; /* PL is trusted */
1260 typedef struct DropPLangStmt
1263 char *plname; /* PL name */
1264 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1265 bool missing_ok; /* skip error if missing? */
1268 /* ----------------------
1269 * Create/Alter/Drop Role Statements
1271 * Note: these node types are also used for the backwards-compatible
1272 * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases
1273 * there's really no need to distinguish what the original spelling was,
1274 * but for CREATE we mark the type because the defaults vary.
1275 * ----------------------
1277 typedef enum RoleStmtType
1284 typedef struct CreateRoleStmt
1287 RoleStmtType stmt_type; /* ROLE/USER/GROUP */
1288 char *role; /* role name */
1289 List *options; /* List of DefElem nodes */
1292 typedef struct AlterRoleStmt
1295 char *role; /* role name */
1296 List *options; /* List of DefElem nodes */
1297 int action; /* +1 = add members, -1 = drop members */
1300 typedef struct AlterRoleSetStmt
1303 char *role; /* role name */
1304 VariableSetStmt *setstmt; /* SET or RESET subcommand */
1307 typedef struct DropRoleStmt
1310 List *roles; /* List of roles to remove */
1311 bool missing_ok; /* skip error if a role is missing? */
1314 /* ----------------------
1315 * {Create|Alter} SEQUENCE Statement
1316 * ----------------------
1319 typedef struct CreateSeqStmt
1322 RangeVar *sequence; /* the sequence to create */
1326 typedef struct AlterSeqStmt
1329 RangeVar *sequence; /* the sequence to alter */
1333 /* ----------------------
1334 * Create {Aggregate|Operator|Type} Statement
1335 * ----------------------
1337 typedef struct DefineStmt
1340 ObjectType kind; /* aggregate, operator, type */
1341 bool oldstyle; /* hack to signal old CREATE AGG syntax */
1342 List *defnames; /* qualified name (list of Value strings) */
1343 List *args; /* a list of TypeName (if needed) */
1344 List *definition; /* a list of DefElem */
1347 /* ----------------------
1348 * Create Domain Statement
1349 * ----------------------
1351 typedef struct CreateDomainStmt
1354 List *domainname; /* qualified name (list of Value strings) */
1355 TypeName *typename; /* the base type */
1356 List *constraints; /* constraints (list of Constraint nodes) */
1359 /* ----------------------
1360 * Create Operator Class Statement
1361 * ----------------------
1363 typedef struct CreateOpClassStmt
1366 List *opclassname; /* qualified name (list of Value strings) */
1367 List *opfamilyname; /* qualified name (ditto); NIL if omitted */
1368 char *amname; /* name of index AM opclass is for */
1369 TypeName *datatype; /* datatype of indexed column */
1370 List *items; /* List of CreateOpClassItem nodes */
1371 bool isDefault; /* Should be marked as default for type? */
1372 } CreateOpClassStmt;
1374 #define OPCLASS_ITEM_OPERATOR 1
1375 #define OPCLASS_ITEM_FUNCTION 2
1376 #define OPCLASS_ITEM_STORAGETYPE 3
1378 typedef struct CreateOpClassItem
1381 int itemtype; /* see codes above */
1382 /* fields used for an operator or function item: */
1383 List *name; /* operator or function name */
1384 List *args; /* argument types */
1385 int number; /* strategy num or support proc num */
1386 bool recheck; /* only used for operators */
1387 List *class_args; /* only used for functions */
1388 /* fields used for a storagetype item: */
1389 TypeName *storedtype; /* datatype stored in index */
1390 } CreateOpClassItem;
1392 /* ----------------------
1393 * Create Operator Family Statement
1394 * ----------------------
1396 typedef struct CreateOpFamilyStmt
1399 List *opfamilyname; /* qualified name (list of Value strings) */
1400 char *amname; /* name of index AM opfamily is for */
1401 } CreateOpFamilyStmt;
1403 /* ----------------------
1404 * Alter Operator Family Statement
1405 * ----------------------
1407 typedef struct AlterOpFamilyStmt
1410 List *opfamilyname; /* qualified name (list of Value strings) */
1411 char *amname; /* name of index AM opfamily is for */
1412 bool isDrop; /* ADD or DROP the items? */
1413 List *items; /* List of CreateOpClassItem nodes */
1414 } AlterOpFamilyStmt;
1416 /* ----------------------
1417 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
1418 * ----------------------
1421 typedef struct DropStmt
1424 List *objects; /* list of sublists of names (as Values) */
1425 ObjectType removeType; /* object type */
1426 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1427 bool missing_ok; /* skip error if object is missing? */
1430 /* ----------------------
1431 * Drop Rule|Trigger Statement
1433 * In general this may be used for dropping any property of a relation;
1434 * for example, someday soon we may have DROP ATTRIBUTE.
1435 * ----------------------
1438 typedef struct DropPropertyStmt
1441 RangeVar *relation; /* owning relation */
1442 char *property; /* name of rule, trigger, etc */
1443 ObjectType removeType; /* OBJECT_RULE or OBJECT_TRIGGER */
1444 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1445 bool missing_ok; /* skip error if missing? */
1448 /* ----------------------
1449 * Truncate Table Statement
1450 * ----------------------
1452 typedef struct TruncateStmt
1455 List *relations; /* relations (RangeVars) to be truncated */
1456 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1459 /* ----------------------
1460 * Comment On Statement
1461 * ----------------------
1463 typedef struct CommentStmt
1466 ObjectType objtype; /* Object's type */
1467 List *objname; /* Qualified name of the object */
1468 List *objargs; /* Arguments if needed (eg, for functions) */
1469 char *comment; /* Comment to insert, or NULL to remove */
1472 /* ----------------------
1473 * Declare Cursor Statement
1475 * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar
1476 * output. After parse analysis it's set to null, and the Query points to the
1477 * DeclareCursorStmt, not vice versa.
1478 * ----------------------
1480 #define CURSOR_OPT_BINARY 0x0001 /* BINARY */
1481 #define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */
1482 #define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */
1483 #define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE (unimplemented) */
1484 #define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */
1485 #define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */
1487 typedef struct DeclareCursorStmt
1490 char *portalname; /* name of the portal (cursor) */
1491 int options; /* bitmask of options (see above) */
1492 Node *query; /* the raw SELECT query */
1493 } DeclareCursorStmt;
1495 /* ----------------------
1496 * Close Portal Statement
1497 * ----------------------
1499 typedef struct ClosePortalStmt
1502 char *portalname; /* name of the portal (cursor) */
1503 /* NULL means CLOSE ALL */
1506 /* ----------------------
1507 * Fetch Statement (also Move)
1508 * ----------------------
1510 typedef enum FetchDirection
1512 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1515 /* for these, howMany indicates a position; only one row is fetched */
1520 #define FETCH_ALL LONG_MAX
1522 typedef struct FetchStmt
1525 FetchDirection direction; /* see above */
1526 long howMany; /* number of rows, or position argument */
1527 char *portalname; /* name of portal (cursor) */
1528 bool ismove; /* TRUE if MOVE */
1531 /* ----------------------
1532 * Create Index Statement
1533 * ----------------------
1535 typedef struct IndexStmt
1538 char *idxname; /* name of new index, or NULL for default */
1539 RangeVar *relation; /* relation to build index on */
1540 char *accessMethod; /* name of access method (eg. btree) */
1541 char *tableSpace; /* tablespace, or NULL to use parent's */
1542 List *indexParams; /* a list of IndexElem */
1543 List *options; /* options from WITH clause */
1544 char *src_options; /* relopts inherited from source index */
1545 Node *whereClause; /* qualification (partial-index predicate) */
1546 bool unique; /* is index unique? */
1547 bool primary; /* is index on primary key? */
1548 bool isconstraint; /* is it from a CONSTRAINT clause? */
1549 bool concurrent; /* should this be a concurrent index build? */
1552 /* ----------------------
1553 * Create Function Statement
1554 * ----------------------
1556 typedef struct CreateFunctionStmt
1559 bool replace; /* T => replace if already exists */
1560 List *funcname; /* qualified name of function to create */
1561 List *parameters; /* a list of FunctionParameter */
1562 TypeName *returnType; /* the return type */
1563 List *options; /* a list of DefElem */
1564 List *withClause; /* a list of DefElem */
1565 } CreateFunctionStmt;
1567 typedef enum FunctionParameterMode
1569 /* the assigned enum values appear in pg_proc, don't change 'em! */
1570 FUNC_PARAM_IN = 'i', /* input only */
1571 FUNC_PARAM_OUT = 'o', /* output only */
1572 FUNC_PARAM_INOUT = 'b' /* both */
1573 } FunctionParameterMode;
1575 typedef struct FunctionParameter
1578 char *name; /* parameter name, or NULL if not given */
1579 TypeName *argType; /* TypeName for parameter type */
1580 FunctionParameterMode mode; /* IN/OUT/INOUT */
1581 } FunctionParameter;
1583 typedef struct AlterFunctionStmt
1586 FuncWithArgs *func; /* name and args of function */
1587 List *actions; /* list of DefElem */
1588 } AlterFunctionStmt;
1590 /* ----------------------
1591 * Drop {Function|Aggregate|Operator} Statement
1592 * ----------------------
1594 typedef struct RemoveFuncStmt
1597 ObjectType kind; /* function, aggregate, operator */
1598 List *name; /* qualified name of object to drop */
1599 List *args; /* types of the arguments */
1600 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1601 bool missing_ok; /* skip error if missing? */
1604 /* ----------------------
1605 * Drop Operator Class Statement
1606 * ----------------------
1608 typedef struct RemoveOpClassStmt
1611 List *opclassname; /* qualified name (list of Value strings) */
1612 char *amname; /* name of index AM opclass is for */
1613 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1614 bool missing_ok; /* skip error if missing? */
1615 } RemoveOpClassStmt;
1617 /* ----------------------
1618 * Drop Operator Family Statement
1619 * ----------------------
1621 typedef struct RemoveOpFamilyStmt
1624 List *opfamilyname; /* qualified name (list of Value strings) */
1625 char *amname; /* name of index AM opfamily is for */
1626 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1627 bool missing_ok; /* skip error if missing? */
1628 } RemoveOpFamilyStmt;
1630 /* ----------------------
1631 * Alter Object Rename Statement
1632 * ----------------------
1634 typedef struct RenameStmt
1637 ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
1638 RangeVar *relation; /* in case it's a table */
1639 List *object; /* in case it's some other object */
1640 List *objarg; /* argument types, if applicable */
1641 char *subname; /* name of contained object (column, rule,
1643 char *newname; /* the new name */
1646 /* ----------------------
1647 * ALTER object SET SCHEMA Statement
1648 * ----------------------
1650 typedef struct AlterObjectSchemaStmt
1653 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1654 RangeVar *relation; /* in case it's a table */
1655 List *object; /* in case it's some other object */
1656 List *objarg; /* argument types, if applicable */
1657 char *addname; /* additional name if needed */
1658 char *newschema; /* the new schema */
1659 } AlterObjectSchemaStmt;
1661 /* ----------------------
1662 * Alter Object Owner Statement
1663 * ----------------------
1665 typedef struct AlterOwnerStmt
1668 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1669 RangeVar *relation; /* in case it's a table */
1670 List *object; /* in case it's some other object */
1671 List *objarg; /* argument types, if applicable */
1672 char *addname; /* additional name if needed */
1673 char *newowner; /* the new owner */
1677 /* ----------------------
1678 * Create Rule Statement
1679 * ----------------------
1681 typedef struct RuleStmt
1684 RangeVar *relation; /* relation the rule is for */
1685 char *rulename; /* name of the rule */
1686 Node *whereClause; /* qualifications */
1687 CmdType event; /* SELECT, INSERT, etc */
1688 bool instead; /* is a 'do instead'? */
1689 List *actions; /* the action statements */
1690 bool replace; /* OR REPLACE */
1693 /* ----------------------
1695 * ----------------------
1697 typedef struct NotifyStmt
1700 RangeVar *relation; /* qualified name to notify */
1703 /* ----------------------
1705 * ----------------------
1707 typedef struct ListenStmt
1710 RangeVar *relation; /* qualified name to listen on */
1713 /* ----------------------
1714 * Unlisten Statement
1715 * ----------------------
1717 typedef struct UnlistenStmt
1720 RangeVar *relation; /* qualified name to unlisten on, or '*' */
1723 /* ----------------------
1724 * {Begin|Commit|Rollback} Transaction Statement
1725 * ----------------------
1727 typedef enum TransactionStmtKind
1730 TRANS_STMT_START, /* semantically identical to BEGIN */
1732 TRANS_STMT_ROLLBACK,
1733 TRANS_STMT_SAVEPOINT,
1735 TRANS_STMT_ROLLBACK_TO,
1737 TRANS_STMT_COMMIT_PREPARED,
1738 TRANS_STMT_ROLLBACK_PREPARED
1739 } TransactionStmtKind;
1741 typedef struct TransactionStmt
1744 TransactionStmtKind kind; /* see above */
1745 List *options; /* for BEGIN/START and savepoint commands */
1746 char *gid; /* for two-phase-commit related commands */
1749 /* ----------------------
1750 * Create Type Statement, composite types
1751 * ----------------------
1753 typedef struct CompositeTypeStmt
1756 RangeVar *typevar; /* the composite type to be created */
1757 List *coldeflist; /* list of ColumnDef nodes */
1758 } CompositeTypeStmt;
1760 /* ----------------------
1761 * Create Type Statement, enum types
1762 * ----------------------
1764 typedef struct CreateEnumStmt
1767 List *typename; /* qualified name (list of Value strings) */
1768 List *vals; /* enum values (list of Value strings) */
1772 /* ----------------------
1773 * Create View Statement
1774 * ----------------------
1776 typedef struct ViewStmt
1779 RangeVar *view; /* the view to be created */
1780 List *aliases; /* target column names */
1781 Node *query; /* the SELECT query */
1782 bool replace; /* replace an existing view? */
1785 /* ----------------------
1787 * ----------------------
1789 typedef struct LoadStmt
1792 char *filename; /* file to load */
1795 /* ----------------------
1796 * Createdb Statement
1797 * ----------------------
1799 typedef struct CreatedbStmt
1802 char *dbname; /* name of database to create */
1803 List *options; /* List of DefElem nodes */
1806 /* ----------------------
1808 * ----------------------
1810 typedef struct AlterDatabaseStmt
1813 char *dbname; /* name of database to alter */
1814 List *options; /* List of DefElem nodes */
1815 } AlterDatabaseStmt;
1817 typedef struct AlterDatabaseSetStmt
1820 char *dbname; /* database name */
1821 VariableSetStmt *setstmt; /* SET or RESET subcommand */
1822 } AlterDatabaseSetStmt;
1824 /* ----------------------
1826 * ----------------------
1828 typedef struct DropdbStmt
1831 char *dbname; /* database to drop */
1832 bool missing_ok; /* skip error if db is missing? */
1835 /* ----------------------
1836 * Cluster Statement (support pbrown's cluster index implementation)
1837 * ----------------------
1839 typedef struct ClusterStmt
1842 RangeVar *relation; /* relation being indexed, or NULL if all */
1843 char *indexname; /* original index defined */
1846 /* ----------------------
1847 * Vacuum and Analyze Statements
1849 * Even though these are nominally two statements, it's convenient to use
1850 * just one node type for both.
1851 * ----------------------
1853 typedef struct VacuumStmt
1856 bool vacuum; /* do VACUUM step */
1857 bool full; /* do FULL (non-concurrent) vacuum */
1858 bool analyze; /* do ANALYZE step */
1859 bool verbose; /* print progress info */
1860 int freeze_min_age; /* min freeze age, or -1 to use default */
1861 RangeVar *relation; /* single table to process, or NULL */
1862 List *va_cols; /* list of column names, or NIL for all */
1865 /* ----------------------
1867 * ----------------------
1869 typedef struct ExplainStmt
1872 Node *query; /* the query (as a raw parse tree) */
1873 bool verbose; /* print plan info */
1874 bool analyze; /* get statistics by executing plan */
1877 /* ----------------------
1878 * Checkpoint Statement
1879 * ----------------------
1881 typedef struct CheckPointStmt
1886 /* ----------------------
1888 * ----------------------
1891 typedef enum DiscardMode
1898 typedef struct DiscardStmt
1904 /* ----------------------
1906 * ----------------------
1908 typedef struct LockStmt
1911 List *relations; /* relations to lock */
1912 int mode; /* lock mode */
1913 bool nowait; /* no wait mode */
1916 /* ----------------------
1917 * SET CONSTRAINTS Statement
1918 * ----------------------
1920 typedef struct ConstraintsSetStmt
1923 List *constraints; /* List of names as RangeVars */
1925 } ConstraintsSetStmt;
1927 /* ----------------------
1929 * ----------------------
1931 typedef struct ReindexStmt
1934 ObjectType kind; /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_DATABASE */
1935 RangeVar *relation; /* Table or index to reindex */
1936 const char *name; /* name of database to reindex */
1937 bool do_system; /* include system tables in database case */
1938 bool do_user; /* include user tables in database case */
1941 /* ----------------------
1942 * CREATE CONVERSION Statement
1943 * ----------------------
1945 typedef struct CreateConversionStmt
1948 List *conversion_name; /* Name of the conversion */
1949 char *for_encoding_name; /* source encoding name */
1950 char *to_encoding_name; /* destination encoding name */
1951 List *func_name; /* qualified conversion function name */
1952 bool def; /* is this a default conversion? */
1953 } CreateConversionStmt;
1955 /* ----------------------
1956 * CREATE CAST Statement
1957 * ----------------------
1959 typedef struct CreateCastStmt
1962 TypeName *sourcetype;
1963 TypeName *targettype;
1965 CoercionContext context;
1968 /* ----------------------
1969 * DROP CAST Statement
1970 * ----------------------
1972 typedef struct DropCastStmt
1975 TypeName *sourcetype;
1976 TypeName *targettype;
1977 DropBehavior behavior;
1978 bool missing_ok; /* skip error if missing? */
1982 /* ----------------------
1984 * ----------------------
1986 typedef struct PrepareStmt
1989 char *name; /* Name of plan, arbitrary */
1990 List *argtypes; /* Types of parameters (List of TypeName) */
1991 Node *query; /* The query itself (as a raw parsetree) */
1995 /* ----------------------
1997 * ----------------------
2000 typedef struct ExecuteStmt
2003 char *name; /* The name of the plan to execute */
2004 IntoClause *into; /* Optional table to store results in */
2005 List *params; /* Values to assign to parameters */
2009 /* ----------------------
2010 * DEALLOCATE Statement
2011 * ----------------------
2013 typedef struct DeallocateStmt
2016 char *name; /* The name of the plan to remove */
2017 /* NULL means DEALLOCATE ALL */
2021 * DROP OWNED statement
2023 typedef struct DropOwnedStmt
2027 DropBehavior behavior;
2031 * REASSIGN OWNED statement
2033 typedef struct ReassignOwnedStmt
2038 } ReassignOwnedStmt;
2041 * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
2043 typedef struct AlterTSDictionaryStmt
2046 List *dictname; /* qualified name (list of Value strings) */
2047 List *options; /* List of DefElem nodes */
2048 } AlterTSDictionaryStmt;
2051 * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
2053 typedef struct AlterTSConfigurationStmt
2056 List *cfgname; /* qualified name (list of Value strings) */
2059 * dicts will be non-NIL if ADD/ALTER MAPPING was specified.
2060 * If dicts is NIL, but tokentype isn't, DROP MAPPING was specified.
2062 List *tokentype; /* list of Value strings */
2063 List *dicts; /* list of list of Value strings */
2064 bool override; /* if true - remove old variant */
2065 bool replace; /* if true - replace dictionary by another */
2066 bool missing_ok; /* for DROP - skip error if missing? */
2067 } AlterTSConfigurationStmt;
2069 #endif /* PARSENODES_H */