1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
7 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: parsenodes.h,v 1.246 2003/08/08 21:42:48 momjian Exp $
12 *-------------------------------------------------------------------------
17 #include "nodes/primnodes.h"
20 /* Possible sources of a Query */
21 typedef enum QuerySource
23 QSRC_ORIGINAL, /* original parsetree (explicit query) */
24 QSRC_PARSER, /* added by parse analysis */
25 QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */
26 QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */
27 QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */
31 /*****************************************************************************
33 *****************************************************************************/
37 * all statements are turned into a Query tree (via transformStmt)
38 * for further processing by the optimizer
39 * utility statements (i.e. non-optimizable statements)
40 * have the *utilityStmt field set.
46 CmdType commandType; /* select|insert|update|delete|utility */
48 QuerySource querySource; /* where did I come from? */
50 bool canSetTag; /* do I set the command result tag? */
52 Node *utilityStmt; /* non-null if this is a non-optimizable
55 int resultRelation; /* target relation (index into rtable) */
57 RangeVar *into; /* target relation for SELECT INTO */
59 bool hasAggs; /* has aggregates in tlist or havingQual */
60 bool hasSubLinks; /* has subquery SubLink */
62 List *rtable; /* list of range table entries */
63 FromExpr *jointree; /* table join tree (FROM and WHERE
66 List *rowMarks; /* integer list of RT indexes of relations
67 * that are selected FOR UPDATE */
69 List *targetList; /* target list (of TargetEntry) */
71 List *groupClause; /* a list of GroupClause's */
73 Node *havingQual; /* qualifications applied to groups */
75 List *distinctClause; /* a list of SortClause's */
77 List *sortClause; /* a list of SortClause's */
79 Node *limitOffset; /* # of result tuples to skip */
80 Node *limitCount; /* # of result tuples to return */
82 Node *setOperations; /* set-operation tree if this is top level
83 * of a UNION/INTERSECT/EXCEPT query */
86 * If the resultRelation turns out to be the parent of an inheritance
87 * tree, the planner will add all the child tables to the rtable and
88 * store a list of the rtindexes of all the result relations here.
89 * This is done at plan time, not parse time, since we don't want to
90 * commit to the exact set of child tables at parse time. This field
91 * ought to go in some sort of TopPlan plan node, not in the Query.
93 List *resultRelations; /* integer list of RT indexes, or NIL */
95 /* internal to planner */
96 List *base_rel_list; /* list of base-relation RelOptInfos */
97 List *other_rel_list; /* list of other 1-relation RelOptInfos */
98 List *join_rel_list; /* list of join-relation RelOptInfos */
99 List *equi_key_list; /* list of lists of equijoined
101 List *in_info_list; /* list of InClauseInfos */
102 List *query_pathkeys; /* desired pathkeys for query_planner() */
103 bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */
107 /****************************************************************************
108 * Supporting data structures for Parse Trees
110 * Most of these node types appear in raw parsetrees output by the grammar,
111 * and get transformed to something else by the analyzer. A few of them
112 * are used as-is in transformed querytrees.
113 ****************************************************************************/
116 * TypeName - specifies a type in definitions
118 * For TypeName structures generated internally, it is often easier to
119 * specify the type by OID than by name. If "names" is NIL then the
120 * actual type OID is given by typeid, otherwise typeid is unused.
122 * If pct_type is TRUE, then names is actually a field name and we look up
123 * the type of that field. Otherwise (the normal case), names is a type
124 * name possibly qualified with schema and database name.
126 typedef struct TypeName
129 List *names; /* qualified name (list of Value strings) */
130 Oid typeid; /* type identified by OID */
131 bool timezone; /* timezone specified? */
132 bool setof; /* is a set? */
133 bool pct_type; /* %TYPE specified? */
134 int32 typmod; /* type modifier */
135 List *arrayBounds; /* array bounds */
139 * ColumnRef - specifies a reference to a column, or possibly a whole tuple
141 * The "fields" list must be nonempty; its last component may be "*"
142 * instead of a field name. Subscripts are optional.
144 typedef struct ColumnRef
147 List *fields; /* field names (list of Value strings) */
148 List *indirection; /* subscripts (list of A_Indices) */
152 * ParamRef - specifies a parameter reference
154 * The parameter could be qualified with field names and/or subscripts
156 typedef struct ParamRef
159 int number; /* the number of the parameter */
160 List *fields; /* field names (list of Value strings) */
161 List *indirection; /* subscripts (list of A_Indices) */
165 * A_Expr - infix, prefix, and postfix expressions
167 typedef enum A_Expr_Kind
169 AEXPR_OP, /* normal operator */
170 AEXPR_AND, /* booleans - name field is unused */
173 AEXPR_OP_ANY, /* scalar op ANY (array) */
174 AEXPR_OP_ALL, /* scalar op ALL (array) */
175 AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */
176 AEXPR_NULLIF, /* NULLIF - name must be "=" */
177 AEXPR_OF /* IS (not) OF - name must be "=" or "!=" */
180 typedef struct A_Expr
183 A_Expr_Kind kind; /* see above */
184 List *name; /* possibly-qualified name of operator */
185 Node *lexpr; /* left argument, or NULL if none */
186 Node *rexpr; /* right argument, or NULL if none */
190 * A_Const - a constant expression
192 typedef struct A_Const
195 Value val; /* the value (with the tag) */
196 TypeName *typename; /* typecast */
200 * TypeCast - a CAST expression
202 * NOTE: for mostly historical reasons, A_Const parsenodes contain
203 * room for a TypeName; we only generate a separate TypeCast node if the
204 * argument to be casted is not a constant. In theory either representation
205 * would work, but it is convenient to have the target type immediately
206 * available while resolving a constant's datatype.
208 typedef struct TypeCast
211 Node *arg; /* the expression being casted */
212 TypeName *typename; /* the target type */
216 * FuncCall - a function or aggregate invocation
218 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
219 * indicates we saw 'foo(DISTINCT ...)'. In either case, the construct
220 * *must* be an aggregate call. Otherwise, it might be either an
221 * aggregate or some other kind of function.
223 typedef struct FuncCall
226 List *funcname; /* qualified name of function */
227 List *args; /* the arguments (list of exprs) */
228 bool agg_star; /* argument was really '*' */
229 bool agg_distinct; /* arguments were labeled DISTINCT */
233 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
235 typedef struct A_Indices
238 Node *lidx; /* could be NULL */
243 * ExprFieldSelect - select a field and/or array element from an expression
245 * This is used in the raw parsetree to represent selection from an
246 * arbitrary expression (not a column or param reference). Either
247 * fields or indirection may be NIL if not used.
249 typedef struct ExprFieldSelect
252 Node *arg; /* the thing being selected from */
253 List *fields; /* field names (list of Value strings) */
254 List *indirection; /* subscripts (list of A_Indices) */
259 * result target (used in target list of pre-transformed Parse trees)
261 * In a SELECT or INSERT target list, 'name' is either NULL or
262 * the column name assigned to the value. (If there is an 'AS ColumnLabel'
263 * clause, the grammar sets 'name' from it; otherwise 'name' is initially NULL
264 * and is filled in during the parse analysis phase.)
265 * The 'indirection' field is not used at all.
267 * In an UPDATE target list, 'name' is the name of the destination column,
268 * and 'indirection' stores any subscripts attached to the destination.
269 * That is, our representation is UPDATE table SET name [indirection] = val.
271 typedef struct ResTarget
274 char *name; /* column name or NULL */
275 List *indirection; /* subscripts for destination column, or
277 Node *val; /* the value expression to compute or
282 * SortGroupBy - for ORDER BY clause
284 typedef struct SortGroupBy
287 List *useOp; /* operator to use */
288 Node *node; /* Expression */
292 * RangeSubselect - subquery appearing in a FROM clause
294 typedef struct RangeSubselect
297 Node *subquery; /* the untransformed sub-select clause */
298 Alias *alias; /* table alias & optional column aliases */
302 * RangeFunction - function call appearing in a FROM clause
304 typedef struct RangeFunction
307 Node *funccallnode; /* untransformed function call tree */
308 Alias *alias; /* table alias & optional column aliases */
309 List *coldeflist; /* list of ColumnDef nodes for runtime
310 * assignment of RECORD TupleDesc */
314 * ColumnDef - column definition (used in various creates)
316 * If the column has a default value, we may have the value expression
317 * in either "raw" form (an untransformed parse tree) or "cooked" form
318 * (the nodeToString representation of an executable expression tree),
319 * depending on how this ColumnDef node was created (by parsing, or by
320 * inheritance from an existing relation). We should never have both
323 * The constraints list may contain a CONSTR_DEFAULT item in a raw
324 * parsetree produced by gram.y, but transformCreateStmt will remove
325 * the item and set raw_default instead. CONSTR_DEFAULT items
326 * should not appear in any subsequent processing.
328 * The "support" field, if not null, denotes a supporting relation that
329 * should be linked by an internal dependency to the column. Currently
330 * this is only used to link a SERIAL column's sequence to the column.
332 typedef struct ColumnDef
335 char *colname; /* name of column */
336 TypeName *typename; /* type of column */
337 int inhcount; /* number of times column is inherited */
338 bool is_local; /* column has local (non-inherited) def'n */
339 bool is_not_null; /* NOT NULL constraint specified? */
340 Node *raw_default; /* default value (untransformed parse
342 char *cooked_default; /* nodeToString representation */
343 List *constraints; /* other constraints on column */
344 RangeVar *support; /* supporting relation, if any */
348 * inhRelation - Relations a CREATE TABLE is to inherit attributes of
350 typedef struct InhRelation
354 bool including_defaults;
358 * IndexElem - index parameters (used in CREATE INDEX)
360 * For a plain index attribute, 'name' is the name of the table column to
361 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and
362 * 'expr' is the expression tree.
364 typedef struct IndexElem
367 char *name; /* name of attribute to index, or NULL */
368 Node *expr; /* expression to index, or NULL */
369 List *opclass; /* name of desired opclass; NIL = default */
374 * a definition (used in definition lists in the form of defname = arg)
376 typedef struct DefElem
380 Node *arg; /* a (Value *) or a (TypeName *) */
384 /****************************************************************************
385 * Nodes for a Query tree
386 ****************************************************************************/
388 /*--------------------
390 * A range table is a List of RangeTblEntry nodes.
392 * A range table entry may represent a plain relation, a sub-select in
393 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax
394 * produces an RTE, not the implicit join resulting from multiple FROM
395 * items. This is because we only need the RTE to deal with SQL features
396 * like outer joins and join-output-column aliasing.) Other special
397 * RTE types also exist, as indicated by RTEKind.
399 * alias is an Alias node representing the AS alias-clause attached to the
400 * FROM expression, or NULL if no clause.
402 * eref is the table reference name and column reference names (either
403 * real or aliases). Note that system columns (OID etc) are not included
404 * in the column list.
405 * eref->aliasname is required to be present, and should generally be used
406 * to identify the RTE for error messages etc.
408 * inh is TRUE for relation references that should be expanded to include
409 * inheritance children, if the rel has any. This *must* be FALSE for
410 * RTEs other than RTE_RELATION entries.
412 * inFromCl marks those range variables that are listed in the FROM clause.
413 * In SQL, the query can only refer to range variables listed in the
414 * FROM clause, but POSTQUEL allows you to refer to tables not listed,
415 * in which case a range table entry will be generated. We still support
416 * this POSTQUEL feature, although there is some doubt whether it's
417 * convenient or merely confusing. The flag is needed since an
418 * implicitly-added RTE shouldn't change the namespace for unqualified
419 * column names processed later, and it also shouldn't affect the
422 * checkForRead, checkForWrite, and checkAsUser control run-time access
423 * permissions checks. A rel will be checked for read or write access
424 * (or both, or neither) per checkForRead and checkForWrite. If
425 * checkAsUser is not InvalidOid, then do the permissions checks using
426 * the access rights of that user, not the current effective user ID.
427 * (This allows rules to act as setuid gateways.)
428 *--------------------
432 RTE_RELATION, /* ordinary relation reference */
433 RTE_SUBQUERY, /* subquery in FROM */
435 RTE_SPECIAL, /* special rule relation (NEW or OLD) */
436 RTE_FUNCTION /* function in FROM */
439 typedef struct RangeTblEntry
443 RTEKind rtekind; /* see above */
446 * XXX the fields applicable to only some rte kinds should be merged
447 * into a union. I didn't do this yet because the diffs would impact
448 * a lot of code that is being actively worked on. FIXME later.
452 * Fields valid for a plain relation RTE (else zero):
454 Oid relid; /* OID of the relation */
457 * Fields valid for a subquery RTE (else NULL):
459 Query *subquery; /* the sub-query */
462 * Fields valid for a function RTE (else NULL):
464 Node *funcexpr; /* expression tree for func call */
465 List *coldeflist; /* list of ColumnDef nodes for runtime
466 * assignment of RECORD TupleDesc */
469 * Fields valid for a join RTE (else NULL/zero):
471 * joinaliasvars is a list of Vars or COALESCE expressions corresponding
472 * to the columns of the join result. An alias Var referencing column
473 * K of the join result can be replaced by the K'th element of
474 * joinaliasvars --- but to simplify the task of reverse-listing
475 * aliases correctly, we do not do that until planning time.
477 JoinType jointype; /* type of join */
478 List *joinaliasvars; /* list of alias-var expansions */
481 * Fields valid in all RTEs:
483 Alias *alias; /* user-written alias clause, if any */
484 Alias *eref; /* expanded reference names */
485 bool inh; /* inheritance requested? */
486 bool inFromCl; /* present in FROM clause */
487 bool checkForRead; /* check rel for read access */
488 bool checkForWrite; /* check rel for write access */
489 Oid checkAsUser; /* if not zero, check access as this user */
494 * representation of ORDER BY clauses
496 * tleSortGroupRef must match ressortgroupref of exactly one Resdom of the
497 * associated targetlist; that is the expression to be sorted (or grouped) by.
498 * sortop is the OID of the ordering operator.
500 * SortClauses are also used to identify Resdoms that we will do a "Unique"
501 * filter step on (for SELECT DISTINCT and SELECT DISTINCT ON). The
502 * distinctClause list is simply a copy of the relevant members of the
503 * sortClause list. Note that distinctClause can be a subset of sortClause,
504 * but cannot have members not present in sortClause; and the members that
505 * do appear must be in the same order as in sortClause.
507 typedef struct SortClause
510 Index tleSortGroupRef; /* reference into targetlist */
511 Oid sortop; /* the sort operator to use */
516 * representation of GROUP BY clauses
518 * GroupClause is exactly like SortClause except for the nodetag value
519 * (it's probably not even really necessary to have two different
520 * nodetags...). We have routines that operate interchangeably on both.
522 typedef SortClause GroupClause;
525 /*****************************************************************************
526 * Optimizable Statements
527 *****************************************************************************/
529 /* ----------------------
531 * ----------------------
533 typedef struct InsertStmt
536 RangeVar *relation; /* relation to insert into */
537 List *cols; /* optional: names of the target columns */
540 * An INSERT statement has *either* VALUES or SELECT, never both. If
541 * VALUES, a targetList is supplied (empty for DEFAULT VALUES). If
542 * SELECT, a complete SelectStmt (or set-operation tree) is supplied.
544 List *targetList; /* the target list (of ResTarget) */
545 Node *selectStmt; /* the source SELECT */
548 /* ----------------------
550 * ----------------------
552 typedef struct DeleteStmt
555 RangeVar *relation; /* relation to delete from */
556 Node *whereClause; /* qualifications */
559 /* ----------------------
561 * ----------------------
563 typedef struct UpdateStmt
566 RangeVar *relation; /* relation to update */
567 List *targetList; /* the target list (of ResTarget) */
568 Node *whereClause; /* qualifications */
569 List *fromClause; /* optional from clause for more tables */
572 /* ----------------------
575 * A "simple" SELECT is represented in the output of gram.y by a single
576 * SelectStmt node. A SELECT construct containing set operators (UNION,
577 * INTERSECT, EXCEPT) is represented by a tree of SelectStmt nodes, in
578 * which the leaf nodes are component SELECTs and the internal nodes
579 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node
580 * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
581 * LIMIT, etc, clause values into a SELECT statement without worrying
582 * whether it is a simple or compound SELECT.
583 * ----------------------
585 typedef enum SetOperation
593 typedef struct SelectStmt
598 * These fields are used only in "leaf" SelectStmts.
600 * into and intoColNames are a kluge; they belong somewhere else...
602 List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
603 * lcons(NIL,NIL) for all (SELECT
605 RangeVar *into; /* target table (for select into table) */
606 List *intoColNames; /* column names for into table */
607 List *targetList; /* the target list (of ResTarget) */
608 List *fromClause; /* the FROM clause */
609 Node *whereClause; /* WHERE qualification */
610 List *groupClause; /* GROUP BY clauses */
611 Node *havingClause; /* HAVING conditional-expression */
614 * These fields are used in both "leaf" SelectStmts and upper-level
617 List *sortClause; /* sort clause (a list of SortGroupBy's) */
618 Node *limitOffset; /* # of result tuples to skip */
619 Node *limitCount; /* # of result tuples to return */
620 List *forUpdate; /* FOR UPDATE clause */
623 * These fields are used only in upper-level SelectStmts.
625 SetOperation op; /* type of set op */
626 bool all; /* ALL specified? */
627 struct SelectStmt *larg; /* left child */
628 struct SelectStmt *rarg; /* right child */
629 /* Eventually add fields for CORRESPONDING spec here */
632 /* ----------------------
633 * Set Operation node for post-analysis query trees
635 * After parse analysis, a SELECT with set operations is represented by a
636 * top-level Query node containing the leaf SELECTs as subqueries in its
637 * range table. Its setOperations field shows the tree of set operations,
638 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
639 * nodes replaced by SetOperationStmt nodes.
640 * ----------------------
642 typedef struct SetOperationStmt
645 SetOperation op; /* type of set op */
646 bool all; /* ALL specified? */
647 Node *larg; /* left child */
648 Node *rarg; /* right child */
649 /* Eventually add fields for CORRESPONDING spec here */
651 /* Fields derived during parse analysis: */
652 List *colTypes; /* list of OIDs of output column types */
656 /*****************************************************************************
657 * Other Statements (no optimizations required)
659 * Some of them require a little bit of transformation (which is also
660 * done by transformStmt). The whole structure is then passed on to
661 * ProcessUtility (by-passing the optimization step) as the utilityStmt
663 *****************************************************************************/
666 * When a command can act on several kinds of objects with only one
667 * parse structure required, use these constants to designate the
671 typedef enum ObjectType
696 /* ----------------------
697 * Create Schema Statement
699 * NOTE: the schemaElts list contains raw parsetrees for component statements
700 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
701 * executed after the schema itself is created.
702 * ----------------------
704 typedef struct CreateSchemaStmt
707 char *schemaname; /* the name of the schema to create */
708 char *authid; /* the owner of the created schema */
709 List *schemaElts; /* schema components (list of parsenodes) */
712 typedef enum DropBehavior
714 DROP_RESTRICT, /* drop fails if any dependent objects */
715 DROP_CASCADE /* remove dependent objects too */
718 /* ----------------------
721 * The fields are used in different ways by the different variants of
723 * ----------------------
725 typedef struct AlterTableStmt
728 char subtype; /*------------
730 * T = alter column default
731 * N = alter column drop not null
732 * n = alter column set not null
733 * S = alter column statistics
734 * M = alter column storage
737 * c = pre-processed add constraint
738 * (local in parser/analyze.c)
739 * X = drop constraint
740 * E = create toast table
746 RangeVar *relation; /* table to work on */
747 char *name; /* column or constraint name to act on, or
749 Node *def; /* definition of new column or constraint */
750 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
753 /* ----------------------
756 * The fields are used in different ways by the different variants of
757 * this command. Subtypes should match AlterTable subtypes where possible.
758 * ----------------------
760 typedef struct AlterDomainStmt
763 char subtype; /*------------
764 * T = alter column default
765 * N = alter column drop not null
766 * O = alter column set not null
768 * X = drop constraint
772 List *typename; /* table to work on */
773 char *name; /* column or constraint name to act on, or
775 Node *def; /* definition of default or constraint */
776 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
780 /* ----------------------
781 * Grant|Revoke Statement
782 * ----------------------
784 typedef enum GrantObjectType
786 ACL_OBJECT_RELATION, /* table, view, sequence */
787 ACL_OBJECT_DATABASE, /* database */
788 ACL_OBJECT_FUNCTION, /* function */
789 ACL_OBJECT_LANGUAGE, /* procedural language */
790 ACL_OBJECT_NAMESPACE /* namespace */
794 * Grantable rights are encoded so that we can OR them together in a bitmask.
795 * The present representation of AclItem limits us to 15 distinct rights.
796 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
798 #define ACL_INSERT (1<<0) /* for relations */
799 #define ACL_SELECT (1<<1)
800 #define ACL_UPDATE (1<<2)
801 #define ACL_DELETE (1<<3)
802 #define ACL_RULE (1<<4)
803 #define ACL_REFERENCES (1<<5)
804 #define ACL_TRIGGER (1<<6)
805 #define ACL_EXECUTE (1<<7) /* for functions */
806 #define ACL_USAGE (1<<8) /* for languages and namespaces */
807 #define ACL_CREATE (1<<9) /* for namespaces and databases */
808 #define ACL_CREATE_TEMP (1<<10) /* for databases */
809 #define N_ACL_RIGHTS 11 /* 1 plus the last 1<<x */
810 #define ACL_ALL_RIGHTS (-1) /* all-privileges marker in GRANT list */
811 #define ACL_NO_RIGHTS 0
813 typedef struct GrantStmt
816 bool is_grant; /* true = GRANT, false = REVOKE */
817 GrantObjectType objtype; /* kind of object being operated on */
818 List *objects; /* list of RangeVar nodes, FuncWithArgs
819 * nodes, or plain names (as Value
821 List *privileges; /* integer list of privilege codes */
822 List *grantees; /* list of PrivGrantee nodes */
823 bool grant_option; /* grant or revoke grant option */
824 DropBehavior behavior; /* drop behavior (for REVOKE) */
827 typedef struct PrivGrantee
830 char *username; /* if both are NULL then PUBLIC */
834 typedef struct FuncWithArgs
837 List *funcname; /* qualified name of function */
838 List *funcargs; /* list of Typename nodes */
841 /* This is only used internally in gram.y. */
842 typedef struct PrivTarget
845 GrantObjectType objtype;
849 /* ----------------------
851 * ----------------------
853 typedef struct CopyStmt
856 RangeVar *relation; /* the relation to copy */
857 List *attlist; /* List of column names (as Strings), or
858 * NIL for all columns */
859 bool is_from; /* TO or FROM */
860 char *filename; /* if NULL, use stdin/stdout */
861 List *options; /* List of DefElem nodes */
864 /* ----------------------
865 * Create Table Statement
867 * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
868 * nodes are intermixed in tableElts, and constraints is NIL. After parse
869 * analysis, tableElts contains just ColumnDefs, and constraints contains
870 * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
872 * ----------------------
875 /* What to do at commit time for temporary relations */
876 typedef enum OnCommitAction
878 ONCOMMIT_NOOP, /* No ON COMMIT clause (do nothing) */
879 ONCOMMIT_PRESERVE_ROWS, /* ON COMMIT PRESERVE ROWS (do nothing) */
880 ONCOMMIT_DELETE_ROWS, /* ON COMMIT DELETE ROWS */
881 ONCOMMIT_DROP /* ON COMMIT DROP */
884 typedef struct CreateStmt
887 RangeVar *relation; /* relation to create */
888 List *tableElts; /* column definitions (list of ColumnDef) */
889 List *inhRelations; /* relations to inherit from (list of
891 List *constraints; /* constraints (list of Constraint nodes) */
892 bool hasoids; /* should it have OIDs? */
893 OnCommitAction oncommit; /* what do we do at COMMIT? */
897 * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
899 * XXX probably these ought to be unified with FkConstraints at some point?
901 * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
902 * we may have the expression in either "raw" form (an untransformed
903 * parse tree) or "cooked" form (the nodeToString representation of
904 * an executable expression tree), depending on how this Constraint
905 * node was created (by parsing, or by inheritance from an existing
906 * relation). We should never have both in the same node!
908 * Constraint attributes (DEFERRABLE etc) are initially represented as
909 * separate Constraint nodes for simplicity of parsing. analyze.c makes
910 * a pass through the constraints list to attach the info to the appropriate
911 * FkConstraint node (and, perhaps, someday to other kinds of constraints).
915 typedef enum ConstrType /* types of constraints */
917 CONSTR_NULL, /* not SQL92, but a lot of people expect
924 CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
925 CONSTR_ATTR_NOT_DEFERRABLE,
926 CONSTR_ATTR_DEFERRED,
927 CONSTR_ATTR_IMMEDIATE
930 typedef struct Constraint
934 char *name; /* name, or NULL if unnamed */
935 Node *raw_expr; /* expr, as untransformed parse tree */
936 char *cooked_expr; /* expr, as nodeToString representation */
937 List *keys; /* String nodes naming referenced
942 * Definitions for FOREIGN KEY constraints in CreateStmt
944 * Note: FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
945 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
946 * stored into pg_constraint.confmatchtype. Changing the code values may
949 * If skip_validation is true then we skip checking that the existing rows
950 * in the table satisfy the constraint, and just install the catalog entries
951 * for the constraint. This is currently used only during CREATE TABLE
952 * (when we know the table must be empty).
955 #define FKCONSTR_ACTION_NOACTION 'a'
956 #define FKCONSTR_ACTION_RESTRICT 'r'
957 #define FKCONSTR_ACTION_CASCADE 'c'
958 #define FKCONSTR_ACTION_SETNULL 'n'
959 #define FKCONSTR_ACTION_SETDEFAULT 'd'
961 #define FKCONSTR_MATCH_FULL 'f'
962 #define FKCONSTR_MATCH_PARTIAL 'p'
963 #define FKCONSTR_MATCH_UNSPECIFIED 'u'
965 typedef struct FkConstraint
968 char *constr_name; /* Constraint name, or NULL if unnamed */
969 RangeVar *pktable; /* Primary key table */
970 List *fk_attrs; /* Attributes of foreign key */
971 List *pk_attrs; /* Corresponding attrs in PK table */
972 char fk_matchtype; /* FULL, PARTIAL, UNSPECIFIED */
973 char fk_upd_action; /* ON UPDATE action */
974 char fk_del_action; /* ON DELETE action */
975 bool deferrable; /* DEFERRABLE */
976 bool initdeferred; /* INITIALLY DEFERRED */
977 bool skip_validation; /* skip validation of existing rows? */
980 /* ----------------------
981 * Create/Drop TRIGGER Statements
982 * ----------------------
985 typedef struct CreateTrigStmt
988 char *trigname; /* TRIGGER's name */
989 RangeVar *relation; /* relation trigger is on */
990 List *funcname; /* qual. name of function to call */
991 List *args; /* list of (T_String) Values or NIL */
992 bool before; /* BEFORE/AFTER */
993 bool row; /* ROW/STATEMENT */
994 char actions[4]; /* 1 to 3 of 'i', 'u', 'd', + trailing \0 */
996 /* The following are used for referential */
997 /* integrity constraint triggers */
998 bool isconstraint; /* This is an RI trigger */
999 bool deferrable; /* [NOT] DEFERRABLE */
1000 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
1001 RangeVar *constrrel; /* opposite relation */
1004 /* ----------------------
1005 * Create/Drop PROCEDURAL LANGUAGE Statement
1006 * ----------------------
1008 typedef struct CreatePLangStmt
1011 char *plname; /* PL name */
1012 List *plhandler; /* PL call handler function (qual. name) */
1013 List *plvalidator; /* optional validator function (qual.
1015 bool pltrusted; /* PL is trusted */
1018 typedef struct DropPLangStmt
1021 char *plname; /* PL name */
1022 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1025 /* ----------------------
1026 * Create/Alter/Drop User Statements
1027 * ----------------------
1029 typedef struct CreateUserStmt
1032 char *user; /* PostgreSQL user login name */
1033 List *options; /* List of DefElem nodes */
1036 typedef struct AlterUserStmt
1039 char *user; /* PostgreSQL user login name */
1040 List *options; /* List of DefElem nodes */
1043 typedef struct AlterUserSetStmt
1051 typedef struct DropUserStmt
1054 List *users; /* List of users to remove */
1057 /* ----------------------
1058 * Create/Alter/Drop Group Statements
1059 * ----------------------
1061 typedef struct CreateGroupStmt
1064 char *name; /* name of the new group */
1065 List *options; /* List of DefElem nodes */
1068 typedef struct AlterGroupStmt
1071 char *name; /* name of group to alter */
1072 int action; /* +1 = add, -1 = drop user */
1073 List *listUsers; /* list of users to add/drop */
1076 typedef struct DropGroupStmt
1082 /* ----------------------
1083 * {Create|Alter} SEQUENCE Statement
1084 * ----------------------
1087 typedef struct CreateSeqStmt
1090 RangeVar *sequence; /* the sequence to create */
1094 typedef struct AlterSeqStmt
1097 RangeVar *sequence; /* the sequence to alter */
1101 /* ----------------------
1102 * Create {Aggregate|Operator|Type} Statement
1103 * ----------------------
1105 typedef struct DefineStmt
1108 ObjectType kind; /* aggregate, operator, type */
1109 List *defnames; /* qualified name (list of Value strings) */
1110 List *definition; /* a list of DefElem */
1113 /* ----------------------
1114 * Create Domain Statement
1115 * ----------------------
1117 typedef struct CreateDomainStmt
1120 List *domainname; /* qualified name (list of Value strings) */
1121 TypeName *typename; /* the base type */
1122 List *constraints; /* constraints (list of Constraint nodes) */
1125 /* ----------------------
1126 * Create Operator Class Statement
1127 * ----------------------
1129 typedef struct CreateOpClassStmt
1132 List *opclassname; /* qualified name (list of Value strings) */
1133 char *amname; /* name of index AM opclass is for */
1134 TypeName *datatype; /* datatype of indexed column */
1135 List *items; /* List of CreateOpClassItem nodes */
1136 bool isDefault; /* Should be marked as default for type? */
1137 } CreateOpClassStmt;
1139 #define OPCLASS_ITEM_OPERATOR 1
1140 #define OPCLASS_ITEM_FUNCTION 2
1141 #define OPCLASS_ITEM_STORAGETYPE 3
1143 typedef struct CreateOpClassItem
1146 int itemtype; /* see codes above */
1147 /* fields used for an operator or function item: */
1148 List *name; /* operator or function name */
1149 List *args; /* argument types */
1150 int number; /* strategy num or support proc num */
1151 bool recheck; /* only used for operators */
1152 /* fields used for a storagetype item: */
1153 TypeName *storedtype; /* datatype stored in index */
1154 } CreateOpClassItem;
1156 /* ----------------------
1157 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
1158 * ----------------------
1161 typedef struct DropStmt
1164 List *objects; /* list of sublists of names (as Values) */
1165 ObjectType removeType; /* object type */
1166 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1169 /* ----------------------
1170 * Drop Rule|Trigger Statement
1172 * In general this may be used for dropping any property of a relation;
1173 * for example, someday soon we may have DROP ATTRIBUTE.
1174 * ----------------------
1177 typedef struct DropPropertyStmt
1180 RangeVar *relation; /* owning relation */
1181 char *property; /* name of rule, trigger, etc */
1182 ObjectType removeType; /* OBJECT_RULE or OBJECT_TRIGGER */
1183 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1186 /* ----------------------
1187 * Truncate Table Statement
1188 * ----------------------
1190 typedef struct TruncateStmt
1193 RangeVar *relation; /* relation to be truncated */
1196 /* ----------------------
1197 * Comment On Statement
1198 * ----------------------
1200 typedef struct CommentStmt
1203 ObjectType objtype; /* Object's type */
1204 List *objname; /* Qualified name of the object */
1205 List *objargs; /* Arguments if needed (eg, for functions) */
1206 char *comment; /* Comment to insert, or NULL to remove */
1209 /* ----------------------
1210 * Declare Cursor Statement
1211 * ----------------------
1213 #define CURSOR_OPT_BINARY 0x0001
1214 #define CURSOR_OPT_SCROLL 0x0002
1215 #define CURSOR_OPT_NO_SCROLL 0x0004
1216 #define CURSOR_OPT_INSENSITIVE 0x0008
1217 #define CURSOR_OPT_HOLD 0x0010
1219 typedef struct DeclareCursorStmt
1222 char *portalname; /* name of the portal (cursor) */
1223 int options; /* bitmask of options (see above) */
1224 Node *query; /* the SELECT query */
1225 } DeclareCursorStmt;
1227 /* ----------------------
1228 * Close Portal Statement
1229 * ----------------------
1231 typedef struct ClosePortalStmt
1234 char *portalname; /* name of the portal (cursor) */
1237 /* ----------------------
1238 * Fetch Statement (also Move)
1239 * ----------------------
1241 typedef enum FetchDirection
1243 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1246 /* for these, howMany indicates a position; only one row is fetched */
1251 #define FETCH_ALL LONG_MAX
1253 typedef struct FetchStmt
1256 FetchDirection direction; /* see above */
1257 long howMany; /* number of rows, or position argument */
1258 char *portalname; /* name of portal (cursor) */
1259 bool ismove; /* TRUE if MOVE */
1262 /* ----------------------
1263 * Create Index Statement
1264 * ----------------------
1266 typedef struct IndexStmt
1269 char *idxname; /* name of the index */
1270 RangeVar *relation; /* relation to build index on */
1271 char *accessMethod; /* name of access method (eg. btree) */
1272 List *indexParams; /* a list of IndexElem */
1273 Node *whereClause; /* qualification (partial-index predicate) */
1274 List *rangetable; /* range table for qual and/or
1275 * expressions, filled in by
1276 * transformStmt() */
1277 bool unique; /* is index unique? */
1278 bool primary; /* is index on primary key? */
1279 bool isconstraint; /* is it from a CONSTRAINT clause? */
1282 /* ----------------------
1283 * Create Function Statement
1284 * ----------------------
1286 typedef struct CreateFunctionStmt
1289 bool replace; /* T => replace if already exists */
1290 List *funcname; /* qualified name of function to create */
1291 List *argTypes; /* list of argument types (TypeName nodes) */
1292 TypeName *returnType; /* the return type */
1293 List *options; /* a list of DefElem */
1294 List *withClause; /* a list of DefElem */
1295 } CreateFunctionStmt;
1297 /* ----------------------
1298 * Drop Aggregate Statement
1299 * ----------------------
1301 typedef struct RemoveAggrStmt
1304 List *aggname; /* aggregate to drop */
1305 TypeName *aggtype; /* TypeName for input datatype, or NULL */
1306 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1309 /* ----------------------
1310 * Drop Function Statement
1311 * ----------------------
1313 typedef struct RemoveFuncStmt
1316 List *funcname; /* function to drop */
1317 List *args; /* types of the arguments */
1318 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1321 /* ----------------------
1322 * Drop Operator Statement
1323 * ----------------------
1325 typedef struct RemoveOperStmt
1328 List *opname; /* operator to drop */
1329 List *args; /* types of the arguments */
1330 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1333 /* ----------------------
1334 * Drop Operator Class Statement
1335 * ----------------------
1337 typedef struct RemoveOpClassStmt
1340 List *opclassname; /* qualified name (list of Value strings) */
1341 char *amname; /* name of index AM opclass is for */
1342 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
1343 } RemoveOpClassStmt;
1345 /* ----------------------
1346 * Alter Object Rename Statement
1347 * ----------------------
1349 typedef struct RenameStmt
1352 RangeVar *relation; /* in case it's a table */
1353 List *object; /* in case it's some other object */
1354 List *objarg; /* argument types, if applicable */
1355 char *subname; /* name of contained object (column, rule,
1357 char *newname; /* the new name */
1358 ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
1361 /* ----------------------
1362 * Create Rule Statement
1363 * ----------------------
1365 typedef struct RuleStmt
1368 RangeVar *relation; /* relation the rule is for */
1369 char *rulename; /* name of the rule */
1370 Node *whereClause; /* qualifications */
1371 CmdType event; /* SELECT, INSERT, etc */
1372 bool instead; /* is a 'do instead'? */
1373 List *actions; /* the action statements */
1374 bool replace; /* OR REPLACE */
1377 /* ----------------------
1379 * ----------------------
1381 typedef struct NotifyStmt
1384 RangeVar *relation; /* qualified name to notify */
1387 /* ----------------------
1389 * ----------------------
1391 typedef struct ListenStmt
1394 RangeVar *relation; /* qualified name to listen on */
1397 /* ----------------------
1398 * Unlisten Statement
1399 * ----------------------
1401 typedef struct UnlistenStmt
1404 RangeVar *relation; /* qualified name to unlisten on, or '*' */
1407 /* ----------------------
1408 * {Begin|Commit|Rollback} Transaction Statement
1409 * ----------------------
1411 typedef enum TransactionStmtKind
1414 TRANS_STMT_START, /* semantically identical to BEGIN */
1417 } TransactionStmtKind;
1419 typedef struct TransactionStmt
1422 TransactionStmtKind kind; /* see above */
1423 List *options; /* for BEGIN/START only */
1426 /* ----------------------
1427 * Create Type Statement, composite types
1428 * ----------------------
1430 typedef struct CompositeTypeStmt
1433 RangeVar *typevar; /* the composite type to be created */
1434 List *coldeflist; /* list of ColumnDef nodes */
1435 } CompositeTypeStmt;
1438 /* ----------------------
1439 * Create View Statement
1440 * ----------------------
1442 typedef struct ViewStmt
1445 RangeVar *view; /* the view to be created */
1446 List *aliases; /* target column names */
1447 Query *query; /* the SQL statement */
1448 bool replace; /* replace an existing view? */
1451 /* ----------------------
1453 * ----------------------
1455 typedef struct LoadStmt
1458 char *filename; /* file to load */
1461 /* ----------------------
1462 * Createdb Statement
1463 * ----------------------
1465 typedef struct CreatedbStmt
1468 char *dbname; /* name of database to create */
1469 List *options; /* List of DefElem nodes */
1472 /* ----------------------
1474 * ----------------------
1476 typedef struct AlterDatabaseSetStmt
1482 } AlterDatabaseSetStmt;
1484 /* ----------------------
1486 * ----------------------
1488 typedef struct DropdbStmt
1491 char *dbname; /* database to drop */
1494 /* ----------------------
1495 * Cluster Statement (support pbrown's cluster index implementation)
1496 * ----------------------
1498 typedef struct ClusterStmt
1501 RangeVar *relation; /* relation being indexed, or NULL if all */
1502 char *indexname; /* original index defined */
1505 /* ----------------------
1506 * Vacuum and Analyze Statements
1508 * Even though these are nominally two statements, it's convenient to use
1509 * just one node type for both.
1510 * ----------------------
1512 typedef struct VacuumStmt
1515 bool vacuum; /* do VACUUM step */
1516 bool full; /* do FULL (non-concurrent) vacuum */
1517 bool analyze; /* do ANALYZE step */
1518 bool freeze; /* early-freeze option */
1519 bool verbose; /* print progress info */
1520 RangeVar *relation; /* single table to process, or NULL */
1521 List *va_cols; /* list of column names, or NIL for all */
1524 /* ----------------------
1526 * ----------------------
1528 typedef struct ExplainStmt
1531 Query *query; /* the query */
1532 bool verbose; /* print plan info */
1533 bool analyze; /* get statistics by executing plan */
1536 /* ----------------------
1537 * Checkpoint Statement
1538 * ----------------------
1540 typedef struct CheckPointStmt
1545 /* ----------------------
1547 * ----------------------
1550 typedef struct VariableSetStmt
1555 bool is_local; /* SET LOCAL */
1558 /* ----------------------
1560 * ----------------------
1563 typedef struct VariableShowStmt
1569 /* ----------------------
1571 * ----------------------
1574 typedef struct VariableResetStmt
1578 } VariableResetStmt;
1580 /* ----------------------
1582 * ----------------------
1584 typedef struct LockStmt
1587 List *relations; /* relations to lock */
1588 int mode; /* lock mode */
1591 /* ----------------------
1592 * SET CONSTRAINTS Statement
1593 * ----------------------
1595 typedef struct ConstraintsSetStmt
1598 List *constraints; /* List of names as Value strings */
1600 } ConstraintsSetStmt;
1602 /* ----------------------
1604 * ----------------------
1606 typedef struct ReindexStmt
1609 ObjectType kind; /* OBJECT_INDEX, OBJECT_TABLE,
1610 * OBJECT_DATABASE */
1611 RangeVar *relation; /* Table or index to reindex */
1612 const char *name; /* name of database to reindex */
1617 /* ----------------------
1618 * CREATE CONVERSION Statement
1619 * ----------------------
1621 typedef struct CreateConversionStmt
1624 List *conversion_name; /* Name of the conversion */
1625 char *for_encoding_name; /* source encoding name */
1626 char *to_encoding_name; /* destiname encoding name */
1627 List *func_name; /* qualified conversion function name */
1628 bool def; /* is this a default conversion? */
1629 } CreateConversionStmt;
1631 /* ----------------------
1632 * CREATE CAST Statement
1633 * ----------------------
1635 typedef struct CreateCastStmt
1638 TypeName *sourcetype;
1639 TypeName *targettype;
1641 CoercionContext context;
1644 /* ----------------------
1645 * DROP CAST Statement
1646 * ----------------------
1648 typedef struct DropCastStmt
1651 TypeName *sourcetype;
1652 TypeName *targettype;
1653 DropBehavior behavior;
1657 /* ----------------------
1659 * ----------------------
1661 typedef struct PrepareStmt
1664 char *name; /* Name of plan, arbitrary */
1665 List *argtypes; /* Types of parameters (TypeNames) */
1666 List *argtype_oids; /* Types of parameters (OIDs) */
1667 Query *query; /* The query itself */
1671 /* ----------------------
1673 * ----------------------
1676 typedef struct ExecuteStmt
1679 char *name; /* The name of the plan to execute */
1680 RangeVar *into; /* Optional table to store results in */
1681 List *params; /* Values to assign to parameters */
1685 /* ----------------------
1686 * DEALLOCATE Statement
1687 * ----------------------
1689 typedef struct DeallocateStmt
1692 char *name; /* The name of the plan to remove */
1695 #endif /* PARSENODES_H */