1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
6 * Many of the node types used in parsetrees include a "location" field.
7 * This is a byte (not character) offset in the original source text, to be
8 * used for positioning an error cursor when there is an error related to
9 * the node. Access to the original source text is needed to make use of
13 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
14 * Portions Copyright (c) 1994, Regents of the University of California
18 *-------------------------------------------------------------------------
23 #include "nodes/primnodes.h"
24 #include "nodes/value.h"
26 /* Possible sources of a Query */
27 typedef enum QuerySource
29 QSRC_ORIGINAL
, /* original parsetree (explicit query) */
30 QSRC_PARSER
, /* added by parse analysis (now unused) */
31 QSRC_INSTEAD_RULE
, /* added by unconditional INSTEAD rule */
32 QSRC_QUAL_INSTEAD_RULE
, /* added by conditional INSTEAD rule */
33 QSRC_NON_INSTEAD_RULE
/* added by non-INSTEAD rule */
36 /* Sort ordering options for ORDER BY and CREATE INDEX */
37 typedef enum SortByDir
42 SORTBY_USING
/* not allowed in CREATE INDEX ... */
45 typedef enum SortByNulls
54 * Grantable rights are encoded so that we can OR them together in a bitmask.
55 * The present representation of AclItem limits us to 16 distinct rights,
56 * even though AclMode is defined as uint32. See utils/acl.h.
58 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
60 typedef uint32 AclMode
; /* a bitmask of privilege bits */
62 #define ACL_INSERT (1<<0) /* for relations */
63 #define ACL_SELECT (1<<1)
64 #define ACL_UPDATE (1<<2)
65 #define ACL_DELETE (1<<3)
66 #define ACL_TRUNCATE (1<<4)
67 #define ACL_REFERENCES (1<<5)
68 #define ACL_TRIGGER (1<<6)
69 #define ACL_EXECUTE (1<<7) /* for functions */
70 #define ACL_USAGE (1<<8) /* for languages and namespaces */
71 #define ACL_CREATE (1<<9) /* for namespaces and databases */
72 #define ACL_CREATE_TEMP (1<<10) /* for databases */
73 #define ACL_CONNECT (1<<11) /* for databases */
74 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */
75 #define ACL_NO_RIGHTS 0
76 /* Currently, SELECT ... FOR UPDATE/FOR SHARE requires UPDATE privileges */
77 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE
80 /*****************************************************************************
82 *****************************************************************************/
86 * Parse analysis turns all statements into a Query tree (via transformStmt)
87 * for further processing by the rewriter and planner.
89 * Utility statements (i.e. non-optimizable statements) have the
90 * utilityStmt field set, and the Query itself is mostly dummy.
91 * DECLARE CURSOR is a special case: it is represented like a SELECT,
92 * but the original DeclareCursorStmt is stored in utilityStmt.
94 * Planning converts a Query tree into a Plan tree headed by a PlannedStmt
95 * node --- the Query structure is not used by the executor.
101 CmdType commandType
; /* select|insert|update|delete|utility */
103 QuerySource querySource
; /* where did I come from? */
105 bool canSetTag
; /* do I set the command result tag? */
107 Node
*utilityStmt
; /* non-null if this is DECLARE CURSOR or a
108 * non-optimizable statement */
110 int resultRelation
; /* rtable index of target relation for
111 * INSERT/UPDATE/DELETE; 0 for SELECT */
113 IntoClause
*intoClause
; /* target for SELECT INTO / CREATE TABLE AS */
115 bool hasAggs
; /* has aggregates in tlist or havingQual */
116 bool hasSubLinks
; /* has subquery SubLink */
117 bool hasDistinctOn
; /* distinctClause is from DISTINCT ON */
119 List
*rtable
; /* list of range table entries */
120 FromExpr
*jointree
; /* table join tree (FROM and WHERE clauses) */
122 List
*targetList
; /* target list (of TargetEntry) */
124 List
*returningList
; /* return-values list (of TargetEntry) */
126 List
*groupClause
; /* a list of SortGroupClause's */
128 Node
*havingQual
; /* qualifications applied to groups */
130 List
*distinctClause
; /* a list of SortGroupClause's */
132 List
*sortClause
; /* a list of SortGroupClause's */
134 Node
*limitOffset
; /* # of result tuples to skip (int8 expr) */
135 Node
*limitCount
; /* # of result tuples to return (int8 expr) */
137 List
*rowMarks
; /* a list of RowMarkClause's */
139 Node
*setOperations
; /* set-operation tree if this is top level of
140 * a UNION/INTERSECT/EXCEPT query */
144 /****************************************************************************
145 * Supporting data structures for Parse Trees
147 * Most of these node types appear in raw parsetrees output by the grammar,
148 * and get transformed to something else by the analyzer. A few of them
149 * are used as-is in transformed querytrees.
150 ****************************************************************************/
153 * TypeName - specifies a type in definitions
155 * For TypeName structures generated internally, it is often easier to
156 * specify the type by OID than by name. If "names" is NIL then the
157 * actual type OID is given by typeid, otherwise typeid is unused.
158 * Similarly, if "typmods" is NIL then the actual typmod is expected to
159 * be prespecified in typemod, otherwise typemod is unused.
161 * If pct_type is TRUE, then names is actually a field name and we look up
162 * the type of that field. Otherwise (the normal case), names is a type
163 * name possibly qualified with schema and database name.
165 typedef struct TypeName
168 List
*names
; /* qualified name (list of Value strings) */
169 Oid
typeid; /* type identified by OID */
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. It can contain string Value nodes
182 * (representing names) and A_Star nodes (representing occurrence of a '*').
183 * Currently, A_Star must appear only as the last list element --- the grammar
184 * is responsible for enforcing this!
186 * Note: any array subscripting or selection of fields from composite columns
187 * is represented by an A_Indirection node above the ColumnRef. However,
188 * for simplicity in the normal case, initial field selection from a table
189 * name is represented within ColumnRef and not by adding A_Indirection.
191 typedef struct ColumnRef
194 List
*fields
; /* field names (Value strings) or A_Star */
195 int location
; /* token location, or -1 if unknown */
199 * ParamRef - specifies a $n parameter reference
201 typedef struct ParamRef
204 int number
; /* the number of the parameter */
205 int location
; /* token location, or -1 if unknown */
209 * A_Expr - infix, prefix, and postfix expressions
211 typedef enum A_Expr_Kind
213 AEXPR_OP
, /* normal operator */
214 AEXPR_AND
, /* booleans - name field is unused */
217 AEXPR_OP_ANY
, /* scalar op ANY (array) */
218 AEXPR_OP_ALL
, /* scalar op ALL (array) */
219 AEXPR_DISTINCT
, /* IS DISTINCT FROM - name must be "=" */
220 AEXPR_NULLIF
, /* NULLIF - name must be "=" */
221 AEXPR_OF
, /* IS [NOT] OF - name must be "=" or "<>" */
222 AEXPR_IN
/* [NOT] IN - name must be "=" or "<>" */
225 typedef struct A_Expr
228 A_Expr_Kind kind
; /* see above */
229 List
*name
; /* possibly-qualified name of operator */
230 Node
*lexpr
; /* left argument, or NULL if none */
231 Node
*rexpr
; /* right argument, or NULL if none */
232 int location
; /* token location, or -1 if unknown */
236 * A_Const - a literal constant
238 typedef struct A_Const
241 Value val
; /* value (includes type info, see value.h) */
242 int location
; /* token location, or -1 if unknown */
246 * TypeCast - a CAST expression
248 typedef struct TypeCast
251 Node
*arg
; /* the expression being casted */
252 TypeName
*typename
; /* the target type */
253 int location
; /* token location, or -1 if unknown */
257 * FuncCall - a function or aggregate invocation
259 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
260 * indicates we saw 'foo(DISTINCT ...)'. In either case, the construct
261 * *must* be an aggregate call. Otherwise, it might be either an
262 * aggregate or some other kind of function.
264 typedef struct FuncCall
267 List
*funcname
; /* qualified name of function */
268 List
*args
; /* the arguments (list of exprs) */
269 bool agg_star
; /* argument was really '*' */
270 bool agg_distinct
; /* arguments were labeled DISTINCT */
271 bool func_variadic
; /* last argument was labeled VARIADIC */
272 int location
; /* token location, or -1 if unknown */
276 * A_Star - '*' representing all columns of a table or compound field
278 * This can appear within ColumnRef.fields, A_Indirection.indirection, and
279 * ResTarget.indirection lists.
281 typedef struct A_Star
287 * A_Indices - array subscript or slice bounds ([lidx:uidx] or [uidx])
289 typedef struct A_Indices
292 Node
*lidx
; /* NULL if it's a single subscript */
297 * A_Indirection - select a field and/or array element from an expression
299 * The indirection list can contain A_Indices nodes (representing
300 * subscripting), string Value nodes (representing field selection --- the
301 * string value is the name of the field to select), and A_Star nodes
302 * (representing selection of all fields of a composite type).
303 * For example, a complex selection operation like
304 * (foo).field1[42][7].field2
305 * would be represented with a single A_Indirection node having a 4-element
308 * Currently, A_Star must appear only as the last list element --- the grammar
309 * is responsible for enforcing this!
311 typedef struct A_Indirection
314 Node
*arg
; /* the thing being selected from */
315 List
*indirection
; /* subscripts and/or field names and/or * */
319 * A_ArrayExpr - an ARRAY[] construct
321 typedef struct A_ArrayExpr
324 List
*elements
; /* array element expressions */
325 int location
; /* token location, or -1 if unknown */
330 * result target (used in target list of pre-transformed parse trees)
332 * In a SELECT target list, 'name' is the column label from an
333 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
334 * value expression itself. The 'indirection' field is not used.
336 * INSERT uses ResTarget in its target-column-names list. Here, 'name' is
337 * the name of the destination column, 'indirection' stores any subscripts
338 * attached to the destination, and 'val' is not used.
340 * In an UPDATE target list, 'name' is the name of the destination column,
341 * 'indirection' stores any subscripts attached to the destination, and
342 * 'val' is the expression to assign.
344 * See A_Indirection for more info about what can appear in 'indirection'.
346 typedef struct ResTarget
349 char *name
; /* column name or NULL */
350 List
*indirection
; /* subscripts, field names, and '*', or NIL */
351 Node
*val
; /* the value expression to compute or assign */
352 int location
; /* token location, or -1 if unknown */
356 * SortBy - for ORDER BY clause
358 typedef struct SortBy
361 Node
*node
; /* expression to sort on */
362 SortByDir sortby_dir
; /* ASC/DESC/USING/default */
363 SortByNulls sortby_nulls
; /* NULLS FIRST/LAST */
364 List
*useOp
; /* name of op to use, if SORTBY_USING */
365 int location
; /* operator location, or -1 if none/unknown */
369 * RangeSubselect - subquery appearing in a FROM clause
371 typedef struct RangeSubselect
374 Node
*subquery
; /* the untransformed sub-select clause */
375 Alias
*alias
; /* table alias & optional column aliases */
379 * RangeFunction - function call appearing in a FROM clause
381 typedef struct RangeFunction
384 Node
*funccallnode
; /* untransformed function call tree */
385 Alias
*alias
; /* table alias & optional column aliases */
386 List
*coldeflist
; /* list of ColumnDef nodes to describe result
387 * of function returning RECORD */
391 * ColumnDef - column definition (used in various creates)
393 * If the column has a default value, we may have the value expression
394 * in either "raw" form (an untransformed parse tree) or "cooked" form
395 * (the nodeToString representation of an executable expression tree),
396 * depending on how this ColumnDef node was created (by parsing, or by
397 * inheritance from an existing relation). We should never have both
400 * The constraints list may contain a CONSTR_DEFAULT item in a raw
401 * parsetree produced by gram.y, but transformCreateStmt will remove
402 * the item and set raw_default instead. CONSTR_DEFAULT items
403 * should not appear in any subsequent processing.
405 typedef struct ColumnDef
408 char *colname
; /* name of column */
409 TypeName
*typename
; /* type of column */
410 int inhcount
; /* number of times column is inherited */
411 bool is_local
; /* column has local (non-inherited) def'n */
412 bool is_not_null
; /* NOT NULL constraint specified? */
413 Node
*raw_default
; /* default value (untransformed parse tree) */
414 char *cooked_default
; /* nodeToString representation */
415 List
*constraints
; /* other constraints on column */
419 * inhRelation - Relations a CREATE TABLE is to inherit attributes of
421 typedef struct InhRelation
425 List
*options
; /* integer List of CreateStmtLikeOption */
428 typedef enum CreateStmtLikeOption
430 CREATE_TABLE_LIKE_INCLUDING_DEFAULTS
,
431 CREATE_TABLE_LIKE_EXCLUDING_DEFAULTS
,
432 CREATE_TABLE_LIKE_INCLUDING_CONSTRAINTS
,
433 CREATE_TABLE_LIKE_EXCLUDING_CONSTRAINTS
,
434 CREATE_TABLE_LIKE_INCLUDING_INDEXES
,
435 CREATE_TABLE_LIKE_EXCLUDING_INDEXES
436 } CreateStmtLikeOption
;
439 * IndexElem - index parameters (used in CREATE INDEX)
441 * For a plain index attribute, 'name' is the name of the table column to
442 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and
443 * 'expr' is the expression tree.
445 typedef struct IndexElem
448 char *name
; /* name of attribute to index, or NULL */
449 Node
*expr
; /* expression to index, or NULL */
450 List
*opclass
; /* name of desired opclass; NIL = default */
451 SortByDir ordering
; /* ASC/DESC/default */
452 SortByNulls nulls_ordering
; /* FIRST/LAST/default */
457 * a definition (used in definition lists in the form of defname = arg)
459 typedef struct DefElem
463 Node
*arg
; /* a (Value *) or a (TypeName *) */
467 * LockingClause - raw representation of FOR UPDATE/SHARE options
469 * Note: lockedRels == NIL means "all relations in query". Otherwise it
470 * is a list of RangeVar nodes. (We use RangeVar mainly because it carries
471 * a location field --- currently, parse analysis insists on unqualified
472 * names in LockingClause.)
474 typedef struct LockingClause
477 List
*lockedRels
; /* FOR UPDATE or FOR SHARE relations */
478 bool forUpdate
; /* true = FOR UPDATE, false = FOR SHARE */
479 bool noWait
; /* NOWAIT option */
483 * XMLSERIALIZE (in raw parse tree only)
485 typedef struct XmlSerialize
488 XmlOptionType xmloption
; /* DOCUMENT or CONTENT */
491 int location
; /* token location, or -1 if unknown */
495 /****************************************************************************
496 * Nodes for a Query tree
497 ****************************************************************************/
499 /*--------------------
501 * A range table is a List of RangeTblEntry nodes.
503 * A range table entry may represent a plain relation, a sub-select in
504 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax
505 * produces an RTE, not the implicit join resulting from multiple FROM
506 * items. This is because we only need the RTE to deal with SQL features
507 * like outer joins and join-output-column aliasing.) Other special
508 * RTE types also exist, as indicated by RTEKind.
510 * alias is an Alias node representing the AS alias-clause attached to the
511 * FROM expression, or NULL if no clause.
513 * eref is the table reference name and column reference names (either
514 * real or aliases). Note that system columns (OID etc) are not included
515 * in the column list.
516 * eref->aliasname is required to be present, and should generally be used
517 * to identify the RTE for error messages etc.
519 * In RELATION RTEs, the colnames in both alias and eref are indexed by
520 * physical attribute number; this means there must be colname entries for
521 * dropped columns. When building an RTE we insert empty strings ("") for
522 * dropped columns. Note however that a stored rule may have nonempty
523 * colnames for columns dropped since the rule was created (and for that
524 * matter the colnames might be out of date due to column renamings).
525 * The same comments apply to FUNCTION RTEs when the function's return type
526 * is a named composite type.
528 * In JOIN RTEs, the colnames in both alias and eref are one-to-one with
529 * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when
530 * those columns are known to be dropped at parse time. Again, however,
531 * a stored rule might contain entries for columns dropped since the rule
532 * was created. (This is only possible for columns not actually referenced
533 * in the rule.) When loading a stored rule, we replace the joinaliasvars
534 * items for any such columns with NULL Consts. (We can't simply delete
535 * them from the joinaliasvars list, because that would affect the attnums
536 * of Vars referencing the rest of the list.)
538 * inh is TRUE for relation references that should be expanded to include
539 * inheritance children, if the rel has any. This *must* be FALSE for
540 * RTEs other than RTE_RELATION entries.
542 * inFromCl marks those range variables that are listed in the FROM clause.
543 * It's false for RTEs that are added to a query behind the scenes, such
544 * as the NEW and OLD variables for a rule, or the subqueries of a UNION.
545 * This flag is not used anymore during parsing, since the parser now uses
546 * a separate "namespace" data structure to control visibility, but it is
547 * needed by ruleutils.c to determine whether RTEs should be shown in
548 * decompiled queries.
550 * requiredPerms and checkAsUser specify run-time access permissions
551 * checks to be performed at query startup. The user must have *all*
552 * of the permissions that are OR'd together in requiredPerms (zero
553 * indicates no permissions checking). If checkAsUser is not zero,
554 * then do the permissions checks using the access rights of that user,
555 * not the current effective user ID. (This allows rules to act as
557 *--------------------
561 RTE_RELATION
, /* ordinary relation reference */
562 RTE_SUBQUERY
, /* subquery in FROM */
564 RTE_SPECIAL
, /* special rule relation (NEW or OLD) */
565 RTE_FUNCTION
, /* function in FROM */
566 RTE_VALUES
/* VALUES (<exprlist>), (<exprlist>), ... */
569 typedef struct RangeTblEntry
573 RTEKind rtekind
; /* see above */
576 * XXX the fields applicable to only some rte kinds should be merged into
577 * a union. I didn't do this yet because the diffs would impact a lot of
578 * code that is being actively worked on. FIXME later.
582 * Fields valid for a plain relation RTE (else zero):
584 Oid relid
; /* OID of the relation */
587 * Fields valid for a subquery RTE (else NULL):
589 Query
*subquery
; /* the sub-query */
592 * Fields valid for a function RTE (else NULL):
594 * If the function returns RECORD, funccoltypes lists the column types
595 * declared in the RTE's column type specification, and funccoltypmods
596 * lists their declared typmods. Otherwise, both fields are NIL.
598 Node
*funcexpr
; /* expression tree for func call */
599 List
*funccoltypes
; /* OID list of column type OIDs */
600 List
*funccoltypmods
; /* integer list of column typmods */
603 * Fields valid for a values RTE (else NIL):
605 List
*values_lists
; /* list of expression lists */
608 * Fields valid for a join RTE (else NULL/zero):
610 * joinaliasvars is a list of Vars or COALESCE expressions corresponding
611 * to the columns of the join result. An alias Var referencing column K
612 * of the join result can be replaced by the K'th element of joinaliasvars
613 * --- but to simplify the task of reverse-listing aliases correctly, we
614 * do not do that until planning time. In a Query loaded from a stored
615 * rule, it is also possible for joinaliasvars items to be NULL Consts,
616 * denoting columns dropped since the rule was made.
618 JoinType jointype
; /* type of join */
619 List
*joinaliasvars
; /* list of alias-var expansions */
622 * Fields valid in all RTEs:
624 Alias
*alias
; /* user-written alias clause, if any */
625 Alias
*eref
; /* expanded reference names */
626 bool inh
; /* inheritance requested? */
627 bool inFromCl
; /* present in FROM clause? */
628 AclMode requiredPerms
; /* bitmask of required access permissions */
629 Oid checkAsUser
; /* if valid, check access as this role */
634 * representation of ORDER BY, GROUP BY, DISTINCT, DISTINCT ON items
636 * You might think that ORDER BY is only interested in defining ordering,
637 * and GROUP/DISTINCT are only interested in defining equality. However,
638 * one way to implement grouping is to sort and then apply a "uniq"-like
639 * filter. So it's also interesting to keep track of possible sort operators
640 * for GROUP/DISTINCT, and in particular to try to sort for the grouping
641 * in a way that will also yield a requested ORDER BY ordering. So we need
642 * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates
643 * the decision to give them the same representation.
645 * tleSortGroupRef must match ressortgroupref of exactly one entry of the
646 * query's targetlist; that is the expression to be sorted or grouped by.
647 * eqop is the OID of the equality operator.
648 * sortop is the OID of the ordering operator (a "<" or ">" operator),
649 * or InvalidOid if not available.
650 * nulls_first means about what you'd expect. If sortop is InvalidOid
651 * then nulls_first is meaningless and should be set to false.
653 * In an ORDER BY item, all fields must be valid. (The eqop isn't essential
654 * here, but it's cheap to get it along with the sortop, and requiring it
655 * to be valid eases comparisons to grouping items.)
657 * In a grouping item, eqop must be valid. If the eqop is a btree equality
658 * operator, then sortop should be set to a compatible ordering operator.
659 * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that
660 * the query presents for the same tlist item. If there is none, we just
661 * use the default ordering op for the datatype.
663 * If the tlist item's type has a hash opclass but no btree opclass, then
664 * we will set eqop to the hash equality operator, sortop to InvalidOid,
665 * and nulls_first to false. A grouping item of this kind can only be
666 * implemented by hashing, and of course it'll never match an ORDER BY item.
668 * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses.
669 * In SELECT DISTINCT, the distinctClause list is as long or longer than the
670 * sortClause list, while in SELECT DISTINCT ON it's typically shorter.
671 * The two lists must match up to the end of the shorter one --- the parser
672 * rearranges the distinctClause if necessary to make this true. (This
673 * restriction ensures that only one sort step is needed to both satisfy the
674 * ORDER BY and set up for the Unique step. This is semantically necessary
675 * for DISTINCT ON, and presents no real drawback for DISTINCT.)
677 typedef struct SortGroupClause
680 Index tleSortGroupRef
; /* reference into targetlist */
681 Oid eqop
; /* the equality operator ('=' op) */
682 Oid sortop
; /* the ordering operator ('<' op), or 0 */
683 bool nulls_first
; /* do NULLs come before normal values? */
688 * representation of FOR UPDATE/SHARE clauses
690 * We create a separate RowMarkClause node for each target relation
692 typedef struct RowMarkClause
695 Index rti
; /* range table index of target relation */
696 bool forUpdate
; /* true = FOR UPDATE, false = FOR SHARE */
697 bool noWait
; /* NOWAIT option */
700 /*****************************************************************************
701 * Optimizable Statements
702 *****************************************************************************/
704 /* ----------------------
707 * The source expression is represented by SelectStmt for both the
708 * SELECT and VALUES cases. If selectStmt is NULL, then the query
709 * is INSERT ... DEFAULT VALUES.
710 * ----------------------
712 typedef struct InsertStmt
715 RangeVar
*relation
; /* relation to insert into */
716 List
*cols
; /* optional: names of the target columns */
717 Node
*selectStmt
; /* the source SELECT/VALUES, or NULL */
718 List
*returningList
; /* list of expressions to return */
721 /* ----------------------
723 * ----------------------
725 typedef struct DeleteStmt
728 RangeVar
*relation
; /* relation to delete from */
729 List
*usingClause
; /* optional using clause for more tables */
730 Node
*whereClause
; /* qualifications */
731 List
*returningList
; /* list of expressions to return */
734 /* ----------------------
736 * ----------------------
738 typedef struct UpdateStmt
741 RangeVar
*relation
; /* relation to update */
742 List
*targetList
; /* the target list (of ResTarget) */
743 Node
*whereClause
; /* qualifications */
744 List
*fromClause
; /* optional from clause for more tables */
745 List
*returningList
; /* list of expressions to return */
748 /* ----------------------
751 * A "simple" SELECT is represented in the output of gram.y by a single
752 * SelectStmt node; so is a VALUES construct. A query containing set
753 * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
754 * nodes, in which the leaf nodes are component SELECTs and the internal nodes
755 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node
756 * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
757 * LIMIT, etc, clause values into a SELECT statement without worrying
758 * whether it is a simple or compound SELECT.
759 * ----------------------
761 typedef enum SetOperation
769 typedef struct SelectStmt
774 * These fields are used only in "leaf" SelectStmts.
776 List
*distinctClause
; /* NULL, list of DISTINCT ON exprs, or
777 * lcons(NIL,NIL) for all (SELECT DISTINCT) */
778 IntoClause
*intoClause
; /* target for SELECT INTO / CREATE TABLE AS */
779 List
*targetList
; /* the target list (of ResTarget) */
780 List
*fromClause
; /* the FROM clause */
781 Node
*whereClause
; /* WHERE qualification */
782 List
*groupClause
; /* GROUP BY clauses */
783 Node
*havingClause
; /* HAVING conditional-expression */
786 * In a "leaf" node representing a VALUES list, the above fields are all
787 * null, and instead this field is set. Note that the elements of the
788 * sublists are just expressions, without ResTarget decoration. Also note
789 * that a list element can be DEFAULT (represented as a SetToDefault
790 * node), regardless of the context of the VALUES list. It's up to parse
791 * analysis to reject that where not valid.
793 List
*valuesLists
; /* untransformed list of expression lists */
796 * These fields are used in both "leaf" SelectStmts and upper-level
799 List
*sortClause
; /* sort clause (a list of SortBy's) */
800 Node
*limitOffset
; /* # of result tuples to skip */
801 Node
*limitCount
; /* # of result tuples to return */
802 List
*lockingClause
; /* FOR UPDATE (list of LockingClause's) */
805 * These fields are used only in upper-level SelectStmts.
807 SetOperation op
; /* type of set op */
808 bool all
; /* ALL specified? */
809 struct SelectStmt
*larg
; /* left child */
810 struct SelectStmt
*rarg
; /* right child */
811 /* Eventually add fields for CORRESPONDING spec here */
815 /* ----------------------
816 * Set Operation node for post-analysis query trees
818 * After parse analysis, a SELECT with set operations is represented by a
819 * top-level Query node containing the leaf SELECTs as subqueries in its
820 * range table. Its setOperations field shows the tree of set operations,
821 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
822 * nodes replaced by SetOperationStmt nodes. Information about the output
823 * column types is added, too. (Note that the child nodes do not necessarily
824 * produce these types directly, but we've checked that their output types
825 * can be coerced to the output column type.) Also, if it's not UNION ALL,
826 * information about the types' sort/group semantics is provided in the form
827 * of a SortGroupClause list (same representation as, eg, DISTINCT).
828 * ----------------------
830 typedef struct SetOperationStmt
833 SetOperation op
; /* type of set op */
834 bool all
; /* ALL specified? */
835 Node
*larg
; /* left child */
836 Node
*rarg
; /* right child */
837 /* Eventually add fields for CORRESPONDING spec here */
839 /* Fields derived during parse analysis: */
840 List
*colTypes
; /* OID list of output column type OIDs */
841 List
*colTypmods
; /* integer list of output column typmods */
842 List
*groupClauses
; /* a list of SortGroupClause's */
843 /* groupClauses is NIL if UNION ALL, but must be set otherwise */
847 /*****************************************************************************
848 * Other Statements (no optimizations required)
850 * These are not touched by parser/analyze.c except to put them into
851 * the utilityStmt field of a Query. This is eventually passed to
852 * ProcessUtility (by-passing rewriting and planning). Some of the
853 * statements do need attention from parse analysis, and this is
854 * done by routines in parser/parse_utilcmd.c after ProcessUtility
855 * receives the command for execution.
856 *****************************************************************************/
859 * When a command can act on several kinds of objects with only one
860 * parse structure required, use these constants to designate the
864 typedef enum ObjectType
887 OBJECT_TSCONFIGURATION
,
895 /* ----------------------
896 * Create Schema Statement
898 * NOTE: the schemaElts list contains raw parsetrees for component statements
899 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
900 * executed after the schema itself is created.
901 * ----------------------
903 typedef struct CreateSchemaStmt
906 char *schemaname
; /* the name of the schema to create */
907 char *authid
; /* the owner of the created schema */
908 List
*schemaElts
; /* schema components (list of parsenodes) */
911 typedef enum DropBehavior
913 DROP_RESTRICT
, /* drop fails if any dependent objects */
914 DROP_CASCADE
/* remove dependent objects too */
917 /* ----------------------
919 * ----------------------
921 typedef struct AlterTableStmt
924 RangeVar
*relation
; /* table to work on */
925 List
*cmds
; /* list of subcommands */
926 ObjectType relkind
; /* type of object */
929 typedef enum AlterTableType
931 AT_AddColumn
, /* add column */
932 AT_ColumnDefault
, /* alter column default */
933 AT_DropNotNull
, /* alter column drop not null */
934 AT_SetNotNull
, /* alter column set not null */
935 AT_SetStatistics
, /* alter column statistics */
936 AT_SetStorage
, /* alter column storage */
937 AT_DropColumn
, /* drop column */
938 AT_DropColumnRecurse
, /* internal to commands/tablecmds.c */
939 AT_AddIndex
, /* add index */
940 AT_ReAddIndex
, /* internal to commands/tablecmds.c */
941 AT_AddConstraint
, /* add constraint */
942 AT_AddConstraintRecurse
, /* internal to commands/tablecmds.c */
943 AT_ProcessedConstraint
, /* pre-processed add constraint (local in
944 * parser/parse_utilcmd.c) */
945 AT_DropConstraint
, /* drop constraint */
946 AT_DropConstraintRecurse
, /* internal to commands/tablecmds.c */
947 AT_AlterColumnType
, /* alter column type */
948 AT_ChangeOwner
, /* change owner */
949 AT_ClusterOn
, /* CLUSTER ON */
950 AT_DropCluster
, /* SET WITHOUT CLUSTER */
951 AT_DropOids
, /* SET WITHOUT OIDS */
952 AT_SetTableSpace
, /* SET TABLESPACE */
953 AT_SetRelOptions
, /* SET (...) -- AM specific parameters */
954 AT_ResetRelOptions
, /* RESET (...) -- AM specific parameters */
955 AT_EnableTrig
, /* ENABLE TRIGGER name */
956 AT_EnableAlwaysTrig
, /* ENABLE ALWAYS TRIGGER name */
957 AT_EnableReplicaTrig
, /* ENABLE REPLICA TRIGGER name */
958 AT_DisableTrig
, /* DISABLE TRIGGER name */
959 AT_EnableTrigAll
, /* ENABLE TRIGGER ALL */
960 AT_DisableTrigAll
, /* DISABLE TRIGGER ALL */
961 AT_EnableTrigUser
, /* ENABLE TRIGGER USER */
962 AT_DisableTrigUser
, /* DISABLE TRIGGER USER */
963 AT_EnableRule
, /* ENABLE RULE name */
964 AT_EnableAlwaysRule
, /* ENABLE ALWAYS RULE name */
965 AT_EnableReplicaRule
, /* ENABLE REPLICA RULE name */
966 AT_DisableRule
, /* DISABLE RULE name */
967 AT_AddInherit
, /* INHERIT parent */
968 AT_DropInherit
/* NO INHERIT parent */
971 typedef struct AlterTableCmd
/* one subcommand of an ALTER TABLE */
974 AlterTableType subtype
; /* Type of table alteration to apply */
975 char *name
; /* column, constraint, or trigger to act on,
976 * or new owner or tablespace */
977 Node
*def
; /* definition of new column, column type,
978 * index, constraint, or parent table */
979 Node
*transform
; /* transformation expr for ALTER TYPE */
980 DropBehavior behavior
; /* RESTRICT or CASCADE for DROP cases */
984 /* ----------------------
987 * The fields are used in different ways by the different variants of
989 * ----------------------
991 typedef struct AlterDomainStmt
994 char subtype
; /*------------
995 * T = alter column default
996 * N = alter column drop not null
997 * O = alter column set not null
999 * X = drop constraint
1002 List
*typename
; /* domain to work on */
1003 char *name
; /* column or constraint name to act on */
1004 Node
*def
; /* definition of default or constraint */
1005 DropBehavior behavior
; /* RESTRICT or CASCADE for DROP cases */
1009 /* ----------------------
1010 * Grant|Revoke Statement
1011 * ----------------------
1013 typedef enum GrantObjectType
1015 ACL_OBJECT_RELATION
, /* table, view */
1016 ACL_OBJECT_SEQUENCE
, /* sequence */
1017 ACL_OBJECT_DATABASE
, /* database */
1018 ACL_OBJECT_FUNCTION
, /* function */
1019 ACL_OBJECT_LANGUAGE
, /* procedural language */
1020 ACL_OBJECT_NAMESPACE
, /* namespace */
1021 ACL_OBJECT_TABLESPACE
/* tablespace */
1024 typedef struct GrantStmt
1027 bool is_grant
; /* true = GRANT, false = REVOKE */
1028 GrantObjectType objtype
; /* kind of object being operated on */
1029 List
*objects
; /* list of RangeVar nodes, FuncWithArgs nodes,
1030 * or plain names (as Value strings) */
1031 List
*privileges
; /* list of privilege names (as Strings) */
1032 /* privileges == NIL denotes "all privileges" */
1033 List
*grantees
; /* list of PrivGrantee nodes */
1034 bool grant_option
; /* grant or revoke grant option */
1035 DropBehavior behavior
; /* drop behavior (for REVOKE) */
1038 typedef struct PrivGrantee
1041 char *rolname
; /* if NULL then PUBLIC */
1045 * Note: FuncWithArgs carries only the types of the input parameters of the
1046 * function. So it is sufficient to identify an existing function, but it
1047 * is not enough info to define a function nor to call it.
1049 typedef struct FuncWithArgs
1052 List
*funcname
; /* qualified name of function */
1053 List
*funcargs
; /* list of Typename nodes */
1056 /* This is only used internally in gram.y. */
1057 typedef struct PrivTarget
1060 GrantObjectType objtype
;
1064 /* ----------------------
1065 * Grant/Revoke Role Statement
1067 * Note: the lists of roles are lists of names, as Value strings
1068 * ----------------------
1070 typedef struct GrantRoleStmt
1073 List
*granted_roles
; /* list of roles to be granted/revoked */
1074 List
*grantee_roles
; /* list of member roles to add/delete */
1075 bool is_grant
; /* true = GRANT, false = REVOKE */
1076 bool admin_opt
; /* with admin option */
1077 char *grantor
; /* set grantor to other than current role */
1078 DropBehavior behavior
; /* drop behavior (for REVOKE) */
1081 /* ----------------------
1084 * We support "COPY relation FROM file", "COPY relation TO file", and
1085 * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation"
1086 * and "query" must be non-NULL.
1087 * ----------------------
1089 typedef struct CopyStmt
1092 RangeVar
*relation
; /* the relation to copy */
1093 Node
*query
; /* the SELECT query to copy */
1094 List
*attlist
; /* List of column names (as Strings), or NIL
1095 * for all columns */
1096 bool is_from
; /* TO or FROM */
1097 char *filename
; /* filename, or NULL for STDIN/STDOUT */
1098 List
*options
; /* List of DefElem nodes */
1101 /* ----------------------
1102 * SET Statement (includes RESET)
1104 * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
1105 * preserve the distinction in VariableSetKind for CreateCommandTag().
1106 * ----------------------
1110 VAR_SET_VALUE
, /* SET var = value */
1111 VAR_SET_DEFAULT
, /* SET var TO DEFAULT */
1112 VAR_SET_CURRENT
, /* SET var FROM CURRENT */
1113 VAR_SET_MULTI
, /* special case for SET TRANSACTION ... */
1114 VAR_RESET
, /* RESET var */
1115 VAR_RESET_ALL
/* RESET ALL */
1118 typedef struct VariableSetStmt
1121 VariableSetKind kind
;
1122 char *name
; /* variable to be set */
1123 List
*args
; /* List of A_Const nodes */
1124 bool is_local
; /* SET LOCAL? */
1127 /* ----------------------
1129 * ----------------------
1131 typedef struct VariableShowStmt
1137 /* ----------------------
1138 * Create Table Statement
1140 * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
1141 * nodes are intermixed in tableElts, and constraints is NIL. After parse
1142 * analysis, tableElts contains just ColumnDefs, and constraints contains
1143 * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
1145 * ----------------------
1148 typedef struct CreateStmt
1151 RangeVar
*relation
; /* relation to create */
1152 List
*tableElts
; /* column definitions (list of ColumnDef) */
1153 List
*inhRelations
; /* relations to inherit from (list of
1155 List
*constraints
; /* constraints (list of Constraint nodes) */
1156 List
*options
; /* options from WITH clause */
1157 OnCommitAction oncommit
; /* what do we do at COMMIT? */
1158 char *tablespacename
; /* table space to use, or NULL */
1162 * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
1164 * XXX probably these ought to be unified with FkConstraints at some point?
1165 * To this end we include CONSTR_FOREIGN in the ConstrType enum, even though
1166 * the parser does not generate it.
1168 * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
1169 * we may have the expression in either "raw" form (an untransformed
1170 * parse tree) or "cooked" form (the nodeToString representation of
1171 * an executable expression tree), depending on how this Constraint
1172 * node was created (by parsing, or by inheritance from an existing
1173 * relation). We should never have both in the same node!
1175 * Constraint attributes (DEFERRABLE etc) are initially represented as
1176 * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes
1177 * a pass through the constraints list to attach the info to the appropriate
1178 * FkConstraint node (and, perhaps, someday to other kinds of constraints).
1182 typedef enum ConstrType
/* types of constraints */
1184 CONSTR_NULL
, /* not SQL92, but a lot of people expect it */
1191 CONSTR_ATTR_DEFERRABLE
, /* attributes for previous constraint node */
1192 CONSTR_ATTR_NOT_DEFERRABLE
,
1193 CONSTR_ATTR_DEFERRED
,
1194 CONSTR_ATTR_IMMEDIATE
1197 typedef struct Constraint
1201 char *name
; /* name, or NULL if unnamed */
1202 Node
*raw_expr
; /* expr, as untransformed parse tree */
1203 char *cooked_expr
; /* expr, as nodeToString representation */
1204 List
*keys
; /* String nodes naming referenced column(s) */
1205 List
*options
; /* options from WITH clause */
1206 char *indexspace
; /* index tablespace for PKEY/UNIQUE
1207 * constraints; NULL for default */
1211 * Definitions for FOREIGN KEY constraints in CreateStmt
1213 * Note: FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
1214 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
1215 * stored into pg_constraint.confmatchtype. Changing the code values may
1216 * require an initdb!
1218 * If skip_validation is true then we skip checking that the existing rows
1219 * in the table satisfy the constraint, and just install the catalog entries
1220 * for the constraint. This is currently used only during CREATE TABLE
1221 * (when we know the table must be empty).
1224 #define FKCONSTR_ACTION_NOACTION 'a'
1225 #define FKCONSTR_ACTION_RESTRICT 'r'
1226 #define FKCONSTR_ACTION_CASCADE 'c'
1227 #define FKCONSTR_ACTION_SETNULL 'n'
1228 #define FKCONSTR_ACTION_SETDEFAULT 'd'
1230 #define FKCONSTR_MATCH_FULL 'f'
1231 #define FKCONSTR_MATCH_PARTIAL 'p'
1232 #define FKCONSTR_MATCH_UNSPECIFIED 'u'
1234 typedef struct FkConstraint
1237 char *constr_name
; /* Constraint name, or NULL if unnamed */
1238 RangeVar
*pktable
; /* Primary key table */
1239 List
*fk_attrs
; /* Attributes of foreign key */
1240 List
*pk_attrs
; /* Corresponding attrs in PK table */
1241 char fk_matchtype
; /* FULL, PARTIAL, UNSPECIFIED */
1242 char fk_upd_action
; /* ON UPDATE action */
1243 char fk_del_action
; /* ON DELETE action */
1244 bool deferrable
; /* DEFERRABLE */
1245 bool initdeferred
; /* INITIALLY DEFERRED */
1246 bool skip_validation
; /* skip validation of existing rows? */
1250 /* ----------------------
1251 * Create/Drop Table Space Statements
1252 * ----------------------
1255 typedef struct CreateTableSpaceStmt
1258 char *tablespacename
;
1261 } CreateTableSpaceStmt
;
1263 typedef struct DropTableSpaceStmt
1266 char *tablespacename
;
1267 bool missing_ok
; /* skip error if missing? */
1268 } DropTableSpaceStmt
;
1270 /* ----------------------
1271 * Create/Drop TRIGGER Statements
1272 * ----------------------
1275 typedef struct CreateTrigStmt
1278 char *trigname
; /* TRIGGER's name */
1279 RangeVar
*relation
; /* relation trigger is on */
1280 List
*funcname
; /* qual. name of function to call */
1281 List
*args
; /* list of (T_String) Values or NIL */
1282 bool before
; /* BEFORE/AFTER */
1283 bool row
; /* ROW/STATEMENT */
1284 char actions
[4]; /* 1 to 3 of 'i', 'u', 'd', + trailing \0 */
1286 /* The following are used for referential */
1287 /* integrity constraint triggers */
1288 bool isconstraint
; /* This is an RI trigger */
1289 bool deferrable
; /* [NOT] DEFERRABLE */
1290 bool initdeferred
; /* INITIALLY {DEFERRED|IMMEDIATE} */
1291 RangeVar
*constrrel
; /* opposite relation */
1294 /* ----------------------
1295 * Create/Drop PROCEDURAL LANGUAGE Statement
1296 * ----------------------
1298 typedef struct CreatePLangStmt
1301 char *plname
; /* PL name */
1302 List
*plhandler
; /* PL call handler function (qual. name) */
1303 List
*plvalidator
; /* optional validator function (qual. name) */
1304 bool pltrusted
; /* PL is trusted */
1307 typedef struct DropPLangStmt
1310 char *plname
; /* PL name */
1311 DropBehavior behavior
; /* RESTRICT or CASCADE behavior */
1312 bool missing_ok
; /* skip error if missing? */
1315 /* ----------------------
1316 * Create/Alter/Drop Role Statements
1318 * Note: these node types are also used for the backwards-compatible
1319 * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases
1320 * there's really no need to distinguish what the original spelling was,
1321 * but for CREATE we mark the type because the defaults vary.
1322 * ----------------------
1324 typedef enum RoleStmtType
1331 typedef struct CreateRoleStmt
1334 RoleStmtType stmt_type
; /* ROLE/USER/GROUP */
1335 char *role
; /* role name */
1336 List
*options
; /* List of DefElem nodes */
1339 typedef struct AlterRoleStmt
1342 char *role
; /* role name */
1343 List
*options
; /* List of DefElem nodes */
1344 int action
; /* +1 = add members, -1 = drop members */
1347 typedef struct AlterRoleSetStmt
1350 char *role
; /* role name */
1351 VariableSetStmt
*setstmt
; /* SET or RESET subcommand */
1354 typedef struct DropRoleStmt
1357 List
*roles
; /* List of roles to remove */
1358 bool missing_ok
; /* skip error if a role is missing? */
1361 /* ----------------------
1362 * {Create|Alter} SEQUENCE Statement
1363 * ----------------------
1366 typedef struct CreateSeqStmt
1369 RangeVar
*sequence
; /* the sequence to create */
1373 typedef struct AlterSeqStmt
1376 RangeVar
*sequence
; /* the sequence to alter */
1380 /* ----------------------
1381 * Create {Aggregate|Operator|Type} Statement
1382 * ----------------------
1384 typedef struct DefineStmt
1387 ObjectType kind
; /* aggregate, operator, type */
1388 bool oldstyle
; /* hack to signal old CREATE AGG syntax */
1389 List
*defnames
; /* qualified name (list of Value strings) */
1390 List
*args
; /* a list of TypeName (if needed) */
1391 List
*definition
; /* a list of DefElem */
1394 /* ----------------------
1395 * Create Domain Statement
1396 * ----------------------
1398 typedef struct CreateDomainStmt
1401 List
*domainname
; /* qualified name (list of Value strings) */
1402 TypeName
*typename
; /* the base type */
1403 List
*constraints
; /* constraints (list of Constraint nodes) */
1406 /* ----------------------
1407 * Create Operator Class Statement
1408 * ----------------------
1410 typedef struct CreateOpClassStmt
1413 List
*opclassname
; /* qualified name (list of Value strings) */
1414 List
*opfamilyname
; /* qualified name (ditto); NIL if omitted */
1415 char *amname
; /* name of index AM opclass is for */
1416 TypeName
*datatype
; /* datatype of indexed column */
1417 List
*items
; /* List of CreateOpClassItem nodes */
1418 bool isDefault
; /* Should be marked as default for type? */
1419 } CreateOpClassStmt
;
1421 #define OPCLASS_ITEM_OPERATOR 1
1422 #define OPCLASS_ITEM_FUNCTION 2
1423 #define OPCLASS_ITEM_STORAGETYPE 3
1425 typedef struct CreateOpClassItem
1428 int itemtype
; /* see codes above */
1429 /* fields used for an operator or function item: */
1430 List
*name
; /* operator or function name */
1431 List
*args
; /* argument types */
1432 int number
; /* strategy num or support proc num */
1433 List
*class_args
; /* only used for functions */
1434 /* fields used for a storagetype item: */
1435 TypeName
*storedtype
; /* datatype stored in index */
1436 } CreateOpClassItem
;
1438 /* ----------------------
1439 * Create Operator Family Statement
1440 * ----------------------
1442 typedef struct CreateOpFamilyStmt
1445 List
*opfamilyname
; /* qualified name (list of Value strings) */
1446 char *amname
; /* name of index AM opfamily is for */
1447 } CreateOpFamilyStmt
;
1449 /* ----------------------
1450 * Alter Operator Family Statement
1451 * ----------------------
1453 typedef struct AlterOpFamilyStmt
1456 List
*opfamilyname
; /* qualified name (list of Value strings) */
1457 char *amname
; /* name of index AM opfamily is for */
1458 bool isDrop
; /* ADD or DROP the items? */
1459 List
*items
; /* List of CreateOpClassItem nodes */
1460 } AlterOpFamilyStmt
;
1462 /* ----------------------
1463 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
1464 * ----------------------
1467 typedef struct DropStmt
1470 List
*objects
; /* list of sublists of names (as Values) */
1471 ObjectType removeType
; /* object type */
1472 DropBehavior behavior
; /* RESTRICT or CASCADE behavior */
1473 bool missing_ok
; /* skip error if object is missing? */
1476 /* ----------------------
1477 * Drop Rule|Trigger Statement
1479 * In general this may be used for dropping any property of a relation;
1480 * for example, someday soon we may have DROP ATTRIBUTE.
1481 * ----------------------
1484 typedef struct DropPropertyStmt
1487 RangeVar
*relation
; /* owning relation */
1488 char *property
; /* name of rule, trigger, etc */
1489 ObjectType removeType
; /* OBJECT_RULE or OBJECT_TRIGGER */
1490 DropBehavior behavior
; /* RESTRICT or CASCADE behavior */
1491 bool missing_ok
; /* skip error if missing? */
1494 /* ----------------------
1495 * Truncate Table Statement
1496 * ----------------------
1498 typedef struct TruncateStmt
1501 List
*relations
; /* relations (RangeVars) to be truncated */
1502 bool restart_seqs
; /* restart owned sequences? */
1503 DropBehavior behavior
; /* RESTRICT or CASCADE behavior */
1506 /* ----------------------
1507 * Comment On Statement
1508 * ----------------------
1510 typedef struct CommentStmt
1513 ObjectType objtype
; /* Object's type */
1514 List
*objname
; /* Qualified name of the object */
1515 List
*objargs
; /* Arguments if needed (eg, for functions) */
1516 char *comment
; /* Comment to insert, or NULL to remove */
1519 /* ----------------------
1520 * Declare Cursor Statement
1522 * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar
1523 * output. After parse analysis it's set to null, and the Query points to the
1524 * DeclareCursorStmt, not vice versa.
1525 * ----------------------
1527 #define CURSOR_OPT_BINARY 0x0001 /* BINARY */
1528 #define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */
1529 #define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */
1530 #define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */
1531 #define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */
1532 #define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */
1534 typedef struct DeclareCursorStmt
1537 char *portalname
; /* name of the portal (cursor) */
1538 int options
; /* bitmask of options (see above) */
1539 Node
*query
; /* the raw SELECT query */
1540 } DeclareCursorStmt
;
1542 /* ----------------------
1543 * Close Portal Statement
1544 * ----------------------
1546 typedef struct ClosePortalStmt
1549 char *portalname
; /* name of the portal (cursor) */
1550 /* NULL means CLOSE ALL */
1553 /* ----------------------
1554 * Fetch Statement (also Move)
1555 * ----------------------
1557 typedef enum FetchDirection
1559 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1562 /* for these, howMany indicates a position; only one row is fetched */
1567 #define FETCH_ALL LONG_MAX
1569 typedef struct FetchStmt
1572 FetchDirection direction
; /* see above */
1573 long howMany
; /* number of rows, or position argument */
1574 char *portalname
; /* name of portal (cursor) */
1575 bool ismove
; /* TRUE if MOVE */
1578 /* ----------------------
1579 * Create Index Statement
1580 * ----------------------
1582 typedef struct IndexStmt
1585 char *idxname
; /* name of new index, or NULL for default */
1586 RangeVar
*relation
; /* relation to build index on */
1587 char *accessMethod
; /* name of access method (eg. btree) */
1588 char *tableSpace
; /* tablespace, or NULL for default */
1589 List
*indexParams
; /* a list of IndexElem */
1590 List
*options
; /* options from WITH clause */
1591 Node
*whereClause
; /* qualification (partial-index predicate) */
1592 bool unique
; /* is index unique? */
1593 bool primary
; /* is index on primary key? */
1594 bool isconstraint
; /* is it from a CONSTRAINT clause? */
1595 bool concurrent
; /* should this be a concurrent index build? */
1598 /* ----------------------
1599 * Create Function Statement
1600 * ----------------------
1602 typedef struct CreateFunctionStmt
1605 bool replace
; /* T => replace if already exists */
1606 List
*funcname
; /* qualified name of function to create */
1607 List
*parameters
; /* a list of FunctionParameter */
1608 TypeName
*returnType
; /* the return type */
1609 List
*options
; /* a list of DefElem */
1610 List
*withClause
; /* a list of DefElem */
1611 } CreateFunctionStmt
;
1613 typedef enum FunctionParameterMode
1615 /* the assigned enum values appear in pg_proc, don't change 'em! */
1616 FUNC_PARAM_IN
= 'i', /* input only */
1617 FUNC_PARAM_OUT
= 'o', /* output only */
1618 FUNC_PARAM_INOUT
= 'b', /* both */
1619 FUNC_PARAM_VARIADIC
= 'v', /* variadic */
1620 FUNC_PARAM_TABLE
= 't' /* table function output column */
1621 } FunctionParameterMode
;
1623 typedef struct FunctionParameter
1626 char *name
; /* parameter name, or NULL if not given */
1627 TypeName
*argType
; /* TypeName for parameter type */
1628 FunctionParameterMode mode
; /* IN/OUT/INOUT */
1629 } FunctionParameter
;
1631 typedef struct AlterFunctionStmt
1634 FuncWithArgs
*func
; /* name and args of function */
1635 List
*actions
; /* list of DefElem */
1636 } AlterFunctionStmt
;
1638 /* ----------------------
1639 * Drop {Function|Aggregate|Operator} Statement
1640 * ----------------------
1642 typedef struct RemoveFuncStmt
1645 ObjectType kind
; /* function, aggregate, operator */
1646 List
*name
; /* qualified name of object to drop */
1647 List
*args
; /* types of the arguments */
1648 DropBehavior behavior
; /* RESTRICT or CASCADE behavior */
1649 bool missing_ok
; /* skip error if missing? */
1652 /* ----------------------
1653 * Drop Operator Class Statement
1654 * ----------------------
1656 typedef struct RemoveOpClassStmt
1659 List
*opclassname
; /* qualified name (list of Value strings) */
1660 char *amname
; /* name of index AM opclass is for */
1661 DropBehavior behavior
; /* RESTRICT or CASCADE behavior */
1662 bool missing_ok
; /* skip error if missing? */
1663 } RemoveOpClassStmt
;
1665 /* ----------------------
1666 * Drop Operator Family Statement
1667 * ----------------------
1669 typedef struct RemoveOpFamilyStmt
1672 List
*opfamilyname
; /* qualified name (list of Value strings) */
1673 char *amname
; /* name of index AM opfamily is for */
1674 DropBehavior behavior
; /* RESTRICT or CASCADE behavior */
1675 bool missing_ok
; /* skip error if missing? */
1676 } RemoveOpFamilyStmt
;
1678 /* ----------------------
1679 * Alter Object Rename Statement
1680 * ----------------------
1682 typedef struct RenameStmt
1685 ObjectType renameType
; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
1686 RangeVar
*relation
; /* in case it's a table */
1687 List
*object
; /* in case it's some other object */
1688 List
*objarg
; /* argument types, if applicable */
1689 char *subname
; /* name of contained object (column, rule,
1691 char *newname
; /* the new name */
1694 /* ----------------------
1695 * ALTER object SET SCHEMA Statement
1696 * ----------------------
1698 typedef struct AlterObjectSchemaStmt
1701 ObjectType objectType
; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1702 RangeVar
*relation
; /* in case it's a table */
1703 List
*object
; /* in case it's some other object */
1704 List
*objarg
; /* argument types, if applicable */
1705 char *addname
; /* additional name if needed */
1706 char *newschema
; /* the new schema */
1707 } AlterObjectSchemaStmt
;
1709 /* ----------------------
1710 * Alter Object Owner Statement
1711 * ----------------------
1713 typedef struct AlterOwnerStmt
1716 ObjectType objectType
; /* OBJECT_TABLE, OBJECT_TYPE, etc */
1717 RangeVar
*relation
; /* in case it's a table */
1718 List
*object
; /* in case it's some other object */
1719 List
*objarg
; /* argument types, if applicable */
1720 char *addname
; /* additional name if needed */
1721 char *newowner
; /* the new owner */
1725 /* ----------------------
1726 * Create Rule Statement
1727 * ----------------------
1729 typedef struct RuleStmt
1732 RangeVar
*relation
; /* relation the rule is for */
1733 char *rulename
; /* name of the rule */
1734 Node
*whereClause
; /* qualifications */
1735 CmdType event
; /* SELECT, INSERT, etc */
1736 bool instead
; /* is a 'do instead'? */
1737 List
*actions
; /* the action statements */
1738 bool replace
; /* OR REPLACE */
1741 /* ----------------------
1743 * ----------------------
1745 typedef struct NotifyStmt
1748 char *conditionname
; /* condition name to notify */
1751 /* ----------------------
1753 * ----------------------
1755 typedef struct ListenStmt
1758 char *conditionname
; /* condition name to listen on */
1761 /* ----------------------
1762 * Unlisten Statement
1763 * ----------------------
1765 typedef struct UnlistenStmt
1768 char *conditionname
; /* name to unlisten on, or NULL for all */
1771 /* ----------------------
1772 * {Begin|Commit|Rollback} Transaction Statement
1773 * ----------------------
1775 typedef enum TransactionStmtKind
1778 TRANS_STMT_START
, /* semantically identical to BEGIN */
1780 TRANS_STMT_ROLLBACK
,
1781 TRANS_STMT_SAVEPOINT
,
1783 TRANS_STMT_ROLLBACK_TO
,
1785 TRANS_STMT_COMMIT_PREPARED
,
1786 TRANS_STMT_ROLLBACK_PREPARED
1787 } TransactionStmtKind
;
1789 typedef struct TransactionStmt
1792 TransactionStmtKind kind
; /* see above */
1793 List
*options
; /* for BEGIN/START and savepoint commands */
1794 char *gid
; /* for two-phase-commit related commands */
1797 /* ----------------------
1798 * Create Type Statement, composite types
1799 * ----------------------
1801 typedef struct CompositeTypeStmt
1804 RangeVar
*typevar
; /* the composite type to be created */
1805 List
*coldeflist
; /* list of ColumnDef nodes */
1806 } CompositeTypeStmt
;
1808 /* ----------------------
1809 * Create Type Statement, enum types
1810 * ----------------------
1812 typedef struct CreateEnumStmt
1815 List
*typename
; /* qualified name (list of Value strings) */
1816 List
*vals
; /* enum values (list of Value strings) */
1820 /* ----------------------
1821 * Create View Statement
1822 * ----------------------
1824 typedef struct ViewStmt
1827 RangeVar
*view
; /* the view to be created */
1828 List
*aliases
; /* target column names */
1829 Node
*query
; /* the SELECT query */
1830 bool replace
; /* replace an existing view? */
1833 /* ----------------------
1835 * ----------------------
1837 typedef struct LoadStmt
1840 char *filename
; /* file to load */
1843 /* ----------------------
1844 * Createdb Statement
1845 * ----------------------
1847 typedef struct CreatedbStmt
1850 char *dbname
; /* name of database to create */
1851 List
*options
; /* List of DefElem nodes */
1854 /* ----------------------
1856 * ----------------------
1858 typedef struct AlterDatabaseStmt
1861 char *dbname
; /* name of database to alter */
1862 List
*options
; /* List of DefElem nodes */
1863 } AlterDatabaseStmt
;
1865 typedef struct AlterDatabaseSetStmt
1868 char *dbname
; /* database name */
1869 VariableSetStmt
*setstmt
; /* SET or RESET subcommand */
1870 } AlterDatabaseSetStmt
;
1872 /* ----------------------
1874 * ----------------------
1876 typedef struct DropdbStmt
1879 char *dbname
; /* database to drop */
1880 bool missing_ok
; /* skip error if db is missing? */
1883 /* ----------------------
1884 * Cluster Statement (support pbrown's cluster index implementation)
1885 * ----------------------
1887 typedef struct ClusterStmt
1890 RangeVar
*relation
; /* relation being indexed, or NULL if all */
1891 char *indexname
; /* original index defined */
1894 /* ----------------------
1895 * Vacuum and Analyze Statements
1897 * Even though these are nominally two statements, it's convenient to use
1898 * just one node type for both.
1899 * ----------------------
1901 typedef struct VacuumStmt
1904 bool vacuum
; /* do VACUUM step */
1905 bool full
; /* do FULL (non-concurrent) vacuum */
1906 bool analyze
; /* do ANALYZE step */
1907 bool verbose
; /* print progress info */
1908 int freeze_min_age
; /* min freeze age, or -1 to use default */
1909 RangeVar
*relation
; /* single table to process, or NULL */
1910 List
*va_cols
; /* list of column names, or NIL for all */
1913 /* ----------------------
1915 * ----------------------
1917 typedef struct ExplainStmt
1920 Node
*query
; /* the query (as a raw parse tree) */
1921 bool verbose
; /* print plan info */
1922 bool analyze
; /* get statistics by executing plan */
1925 /* ----------------------
1926 * Checkpoint Statement
1927 * ----------------------
1929 typedef struct CheckPointStmt
1934 /* ----------------------
1936 * ----------------------
1939 typedef enum DiscardMode
1946 typedef struct DiscardStmt
1952 /* ----------------------
1954 * ----------------------
1956 typedef struct LockStmt
1959 List
*relations
; /* relations to lock */
1960 int mode
; /* lock mode */
1961 bool nowait
; /* no wait mode */
1964 /* ----------------------
1965 * SET CONSTRAINTS Statement
1966 * ----------------------
1968 typedef struct ConstraintsSetStmt
1971 List
*constraints
; /* List of names as RangeVars */
1973 } ConstraintsSetStmt
;
1975 /* ----------------------
1977 * ----------------------
1979 typedef struct ReindexStmt
1982 ObjectType kind
; /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_DATABASE */
1983 RangeVar
*relation
; /* Table or index to reindex */
1984 const char *name
; /* name of database to reindex */
1985 bool do_system
; /* include system tables in database case */
1986 bool do_user
; /* include user tables in database case */
1989 /* ----------------------
1990 * CREATE CONVERSION Statement
1991 * ----------------------
1993 typedef struct CreateConversionStmt
1996 List
*conversion_name
; /* Name of the conversion */
1997 char *for_encoding_name
; /* source encoding name */
1998 char *to_encoding_name
; /* destination encoding name */
1999 List
*func_name
; /* qualified conversion function name */
2000 bool def
; /* is this a default conversion? */
2001 } CreateConversionStmt
;
2003 /* ----------------------
2004 * CREATE CAST Statement
2005 * ----------------------
2007 typedef struct CreateCastStmt
2010 TypeName
*sourcetype
;
2011 TypeName
*targettype
;
2013 CoercionContext context
;
2016 /* ----------------------
2017 * DROP CAST Statement
2018 * ----------------------
2020 typedef struct DropCastStmt
2023 TypeName
*sourcetype
;
2024 TypeName
*targettype
;
2025 DropBehavior behavior
;
2026 bool missing_ok
; /* skip error if missing? */
2030 /* ----------------------
2032 * ----------------------
2034 typedef struct PrepareStmt
2037 char *name
; /* Name of plan, arbitrary */
2038 List
*argtypes
; /* Types of parameters (List of TypeName) */
2039 Node
*query
; /* The query itself (as a raw parsetree) */
2043 /* ----------------------
2045 * ----------------------
2048 typedef struct ExecuteStmt
2051 char *name
; /* The name of the plan to execute */
2052 IntoClause
*into
; /* Optional table to store results in */
2053 List
*params
; /* Values to assign to parameters */
2057 /* ----------------------
2058 * DEALLOCATE Statement
2059 * ----------------------
2061 typedef struct DeallocateStmt
2064 char *name
; /* The name of the plan to remove */
2065 /* NULL means DEALLOCATE ALL */
2069 * DROP OWNED statement
2071 typedef struct DropOwnedStmt
2075 DropBehavior behavior
;
2079 * REASSIGN OWNED statement
2081 typedef struct ReassignOwnedStmt
2086 } ReassignOwnedStmt
;
2089 * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
2091 typedef struct AlterTSDictionaryStmt
2094 List
*dictname
; /* qualified name (list of Value strings) */
2095 List
*options
; /* List of DefElem nodes */
2096 } AlterTSDictionaryStmt
;
2099 * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
2101 typedef struct AlterTSConfigurationStmt
2104 List
*cfgname
; /* qualified name (list of Value strings) */
2107 * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is
2108 * NIL, but tokentype isn't, DROP MAPPING was specified.
2110 List
*tokentype
; /* list of Value strings */
2111 List
*dicts
; /* list of list of Value strings */
2112 bool override
; /* if true - remove old variant */
2113 bool replace
; /* if true - replace dictionary by another */
2114 bool missing_ok
; /* for DROP - skip error if missing? */
2115 } AlterTSConfigurationStmt
;
2117 #endif /* PARSENODES_H */