parsenodes.h 49.3 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * parsenodes.h
4
 *	  definitions for parse tree nodes
5 6
 *
 *
B
Bruce Momjian 已提交
7
 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
10
 * $Id: parsenodes.h,v 1.237 2003/05/02 20:54:36 tgl Exp $
11 12 13
 *
 *-------------------------------------------------------------------------
 */
14 15
#ifndef PARSENODES_H
#define PARSENODES_H
16

17
#include "nodes/primnodes.h"
18

19

20 21 22 23 24 25 26 27 28 29 30
/* Possible sources of a Query */
typedef enum QuerySource
{
	QSRC_ORIGINAL,				/* original parsetree (explicit query) */
	QSRC_PARSER,				/* added by parse analysis */
	QSRC_INSTEAD_RULE,			/* added by unconditional INSTEAD rule */
	QSRC_QUAL_INSTEAD_RULE,		/* added by conditional INSTEAD rule */
	QSRC_NON_INSTEAD_RULE		/* added by non-INSTEAD rule */
} QuerySource;


31
/*****************************************************************************
32
 *	Query Tree
33 34 35 36
 *****************************************************************************/

/*
 * Query -
37
 *	  all statements are turned into a Query tree (via transformStmt)
38 39 40
 *	  for further processing by the optimizer
 *	  utility statements (i.e. non-optimizable statements)
 *	  have the *utilityStmt field set.
41
 */
42 43
typedef struct Query
{
44
	NodeTag		type;
45

46
	CmdType		commandType;	/* select|insert|update|delete|utility */
47

48 49
	QuerySource	querySource;	/* where did I come from? */

50 51
	bool		canSetTag;		/* do I set the command result tag? */

52
	Node	   *utilityStmt;	/* non-null if this is a non-optimizable
53 54
								 * statement */

55
	int			resultRelation; /* target relation (index into rtable) */
56 57

	RangeVar   *into;			/* target relation for SELECT INTO */
58

59
	bool		hasAggs;		/* has aggregates in tlist or havingQual */
60
	bool		hasSubLinks;	/* has subquery SubLink */
61

62
	List	   *rtable;			/* list of range table entries */
B
Bruce Momjian 已提交
63 64
	FromExpr   *jointree;		/* table join tree (FROM and WHERE
								 * clauses) */
65

66 67
	List	   *rowMarks;		/* integer list of RT indexes of relations
								 * that are selected FOR UPDATE */
68

69
	List	   *targetList;		/* target list (of TargetEntry) */
70

71 72 73
	List	   *groupClause;	/* a list of GroupClause's */

	Node	   *havingQual;		/* qualifications applied to groups */
B
Hi!  
Bruce Momjian 已提交
74

75 76 77
	List	   *distinctClause; /* a list of SortClause's */

	List	   *sortClause;		/* a list of SortClause's */
78

B
Bruce Momjian 已提交
79 80
	Node	   *limitOffset;	/* # of result tuples to skip */
	Node	   *limitCount;		/* # of result tuples to return */
B
Bruce Momjian 已提交
81

82 83 84
	Node	   *setOperations;	/* set-operation tree if this is top level
								 * of a UNION/INTERSECT/EXCEPT query */

85 86 87 88 89 90 91 92
	/*
	 * If the resultRelation turns out to be the parent of an inheritance
	 * tree, the planner will add all the child tables to the rtable and
	 * store a list of the rtindexes of all the result relations here.
	 * This is done at plan time, not parse time, since we don't want to
	 * commit to the exact set of child tables at parse time.  This field
	 * ought to go in some sort of TopPlan plan node, not in the Query.
	 */
93
	List	   *resultRelations;	/* integer list of RT indexes, or NIL */
94

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 100
	List	   *equi_key_list;	/* list of lists of equijoined
								 * PathKeyItems */
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 */
104
} Query;
105 106


107 108
/****************************************************************************
 *	Supporting data structures for Parse Trees
109
 *
110 111 112 113
 *	Most of these node types appear in raw parsetrees output by the grammar,
 *	and get transformed to something else by the analyzer.	A few of them
 *	are used as-is in transformed querytrees.
 ****************************************************************************/
114

115 116
/*
 * TypeName - specifies a type in definitions
117 118 119 120 121 122
 *
 * For TypeName structures generated internally, it is often easier to
 * specify the type by OID than by name.  If "names" is NIL then the
 * actual type OID is given by typeid, otherwise typeid is unused.
 *
 * If pct_type is TRUE, then names is actually a field name and we look up
B
Bruce Momjian 已提交
123
 * the type of that field.	Otherwise (the normal case), names is a type
124
 * name possibly qualified with schema and database name.
125
 */
126
typedef struct TypeName
127
{
128
	NodeTag		type;
129 130
	List	   *names;			/* qualified name (list of Value strings) */
	Oid			typeid;			/* type identified by OID */
131 132
	bool		timezone;		/* timezone specified? */
	bool		setof;			/* is a set? */
133
	bool		pct_type;		/* %TYPE specified? */
134 135 136
	int32		typmod;			/* type modifier */
	List	   *arrayBounds;	/* array bounds */
} TypeName;
137

138
/*
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
 * ColumnRef - specifies a reference to a column, or possibly a whole tuple
 *
 *		The "fields" list must be nonempty; its last component may be "*"
 *		instead of a field name.  Subscripts are optional.
 */
typedef struct ColumnRef
{
	NodeTag		type;
	List	   *fields;			/* field names (list of Value strings) */
	List	   *indirection;	/* subscripts (list of A_Indices) */
} ColumnRef;

/*
 * ParamRef - specifies a parameter reference
 *
 *		The parameter could be qualified with field names and/or subscripts
155
 */
156
typedef struct ParamRef
157 158
{
	NodeTag		type;
159
	int			number;			/* the number of the parameter */
160 161 162
	List	   *fields;			/* field names (list of Value strings) */
	List	   *indirection;	/* subscripts (list of A_Indices) */
} ParamRef;
163

164
/*
165
 * A_Expr - infix, prefix, and postfix expressions
166
 */
167 168 169 170 171 172 173
typedef enum A_Expr_Kind
{
	AEXPR_OP,					/* normal operator */
	AEXPR_AND,					/* booleans - name field is unused */
	AEXPR_OR,
	AEXPR_NOT,
	AEXPR_DISTINCT,				/* IS DISTINCT FROM - name must be "=" */
174
	AEXPR_NULLIF,				/* NULLIF - name must be "=" */
175 176 177
	AEXPR_OF					/* IS (not) OF - name must be "=" or "!=" */
} A_Expr_Kind;

178
typedef struct A_Expr
179
{
180
	NodeTag		type;
181
	A_Expr_Kind	kind;			/* see above */
182
	List	   *name;			/* possibly-qualified name of operator */
183 184
	Node	   *lexpr;			/* left argument, or NULL if none */
	Node	   *rexpr;			/* right argument, or NULL if none */
185
} A_Expr;
186

187 188 189 190
/*
 * A_Const - a constant expression
 */
typedef struct A_Const
191 192
{
	NodeTag		type;
193 194 195
	Value		val;			/* the value (with the tag) */
	TypeName   *typename;		/* typecast */
} A_Const;
196

197 198 199
/*
 * TypeCast - a CAST expression
 *
200
 * NOTE: for mostly historical reasons, A_Const parsenodes contain
201
 * room for a TypeName; we only generate a separate TypeCast node if the
202 203 204
 * argument to be casted is not a constant.  In theory either representation
 * would work, but it is convenient to have the target type immediately
 * available while resolving a constant's datatype.
205
 */
206
typedef struct TypeCast
207
{
208
	NodeTag		type;
209 210 211
	Node	   *arg;			/* the expression being casted */
	TypeName   *typename;		/* the target type */
} TypeCast;
212

213 214 215 216 217 218 219 220 221
/*
 * FuncCall - a function or aggregate invocation
 *
 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
 * indicates we saw 'foo(DISTINCT ...)'.  In either case, the construct
 * *must* be an aggregate call.  Otherwise, it might be either an
 * aggregate or some other kind of function.
 */
typedef struct FuncCall
222 223
{
	NodeTag		type;
224
	List	   *funcname;		/* qualified name of function */
225 226 227 228
	List	   *args;			/* the arguments (list of exprs) */
	bool		agg_star;		/* argument was really '*' */
	bool		agg_distinct;	/* arguments were labeled DISTINCT */
} FuncCall;
229

230 231
/*
 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
232
 */
233
typedef struct A_Indices
234
{
235
	NodeTag		type;
236 237 238
	Node	   *lidx;			/* could be NULL */
	Node	   *uidx;
} A_Indices;
239

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
/*
 * ExprFieldSelect - select a field and/or array element from an expression
 *
 *		This is used in the raw parsetree to represent selection from an
 *		arbitrary expression (not a column or param reference).  Either
 *		fields or indirection may be NIL if not used.
 */
typedef struct ExprFieldSelect
{
	NodeTag		type;
	Node	   *arg;			/* the thing being selected from */
	List	   *fields;			/* field names (list of Value strings) */
	List	   *indirection;	/* subscripts (list of A_Indices) */
} ExprFieldSelect;

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
/*
 * ResTarget -
 *	  result target (used in target list of pre-transformed Parse trees)
 *
 * In a SELECT or INSERT target list, 'name' is either NULL or
 * the column name assigned to the value.  (If there is an 'AS ColumnLabel'
 * clause, the grammar sets 'name' from it; otherwise 'name' is initially NULL
 * and is filled in during the parse analysis phase.)
 * The 'indirection' field is not used at all.
 *
 * In an UPDATE target list, 'name' is the name of the destination column,
 * and 'indirection' stores any subscripts attached to the destination.
 * That is, our representation is UPDATE table SET name [indirection] = val.
 */
typedef struct ResTarget
270 271
{
	NodeTag		type;
272 273 274 275 276 277
	char	   *name;			/* column name or NULL */
	List	   *indirection;	/* subscripts for destination column, or
								 * NIL */
	Node	   *val;			/* the value expression to compute or
								 * assign */
} ResTarget;
278

B
Bruce Momjian 已提交
279 280 281 282 283 284 285 286
/*
 * Empty node used as a marker for Default Columns
 */
typedef struct InsertDefault
{
	NodeTag		type;
} InsertDefault;

287 288 289 290
/*
 * SortGroupBy - for ORDER BY clause
 */
typedef struct SortGroupBy
291 292
{
	NodeTag		type;
293
	List	   *useOp;			/* operator to use */
294 295
	Node	   *node;			/* Expression  */
} SortGroupBy;
296

297 298
/*
 * RangeSubselect - subquery appearing in a FROM clause
299
 */
300
typedef struct RangeSubselect
301
{
302
	NodeTag		type;
303
	Node	   *subquery;		/* the untransformed sub-select clause */
304
	Alias	   *alias;			/* table alias & optional column aliases */
305
} RangeSubselect;
306

307 308 309 310 311 312 313 314
/*
 * RangeFunction - function call appearing in a FROM clause
 */
typedef struct RangeFunction
{
	NodeTag		type;
	Node	   *funccallnode;	/* untransformed function call tree */
	Alias	   *alias;			/* table alias & optional column aliases */
315 316
	List	   *coldeflist;		/* list of ColumnDef nodes for runtime
								 * assignment of RECORD TupleDesc */
317 318
} RangeFunction;

319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
/*
 * ColumnDef - column definition (used in various creates)
 *
 * If the column has a default value, we may have the value expression
 * in either "raw" form (an untransformed parse tree) or "cooked" form
 * (the nodeToString representation of an executable expression tree),
 * depending on how this ColumnDef node was created (by parsing, or by
 * inheritance from an existing relation).	We should never have both
 * in the same node!
 *
 * The constraints list may contain a CONSTR_DEFAULT item in a raw
 * parsetree produced by gram.y, but transformCreateStmt will remove
 * the item and set raw_default instead.  CONSTR_DEFAULT items
 * should not appear in any subsequent processing.
 *
 * The "support" field, if not null, denotes a supporting relation that
 * should be linked by an internal dependency to the column.  Currently
 * this is only used to link a SERIAL column's sequence to the column.
 */
typedef struct ColumnDef
{
	NodeTag		type;
	char	   *colname;		/* name of column */
	TypeName   *typename;		/* type of column */
	int			inhcount;		/* number of times column is inherited */
	bool		is_local;		/* column has local (non-inherited) def'n */
	bool		is_not_null;	/* NOT NULL constraint specified? */
	Node	   *raw_default;	/* default value (untransformed parse
								 * tree) */
	char	   *cooked_default; /* nodeToString representation */
	List	   *constraints;	/* other constraints on column */
	RangeVar   *support;		/* supporting relation, if any */
} ColumnDef;

353 354 355
/*
 * IndexElem - index parameters (used in CREATE INDEX)
 *
356 357
 * For a plain index, each 'name' is an attribute name in the heap relation;
 * 'funcname' and 'args' are NIL.  For a functional index, only one IndexElem
B
Bruce Momjian 已提交
358
 * is allowed.	It has name = NULL, funcname = name of function and args =
359
 * list of attribute names that are the function's arguments.
360 361
 */
typedef struct IndexElem
362
{
363
	NodeTag		type;
364 365
	char	   *name;			/* name of attribute to index, or NULL */
	List	   *funcname;		/* qualified name of function */
366
	List	   *args;			/* list of names of function arguments */
367
	List	   *opclass;		/* name of desired opclass; NIL = default */
368
} IndexElem;
369

370 371 372 373 374
/*
 * DefElem -
 *	  a definition (used in definition lists in the form of defname = arg)
 */
typedef struct DefElem
375
{
376
	NodeTag		type;
377 378 379
	char	   *defname;
	Node	   *arg;			/* a (Value *) or a (TypeName *) */
} DefElem;
380

V
Vadim B. Mikheev 已提交
381

382 383 384
/****************************************************************************
 *	Nodes for a Query tree
 ****************************************************************************/
V
Vadim B. Mikheev 已提交
385

386 387 388 389
/*--------------------
 * RangeTblEntry -
 *	  A range table is a List of RangeTblEntry nodes.
 *
390 391 392 393 394 395
 *	  A range table entry may represent a plain relation, a sub-select in
 *	  FROM, or the result of a JOIN clause.  (Only explicit JOIN syntax
 *	  produces an RTE, not the implicit join resulting from multiple FROM
 *	  items.  This is because we only need the RTE to deal with SQL features
 *	  like outer joins and join-output-column aliasing.)  Other special
 *	  RTE types also exist, as indicated by RTEKind.
396
 *
397
 *	  alias is an Alias node representing the AS alias-clause attached to the
398 399 400 401 402
 *	  FROM expression, or NULL if no clause.
 *
 *	  eref is the table reference name and column reference names (either
 *	  real or aliases).  Note that system columns (OID etc) are not included
 *	  in the column list.
403
 *	  eref->aliasname is required to be present, and should generally be used
404 405 406 407
 *	  to identify the RTE for error messages etc.
 *
 *	  inh is TRUE for relation references that should be expanded to include
 *	  inheritance children, if the rel has any.  This *must* be FALSE for
408
 *	  RTEs other than RTE_RELATION entries.
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
 *
 *	  inFromCl marks those range variables that are listed in the FROM clause.
 *	  In SQL, the query can only refer to range variables listed in the
 *	  FROM clause, but POSTQUEL allows you to refer to tables not listed,
 *	  in which case a range table entry will be generated.	We still support
 *	  this POSTQUEL feature, although there is some doubt whether it's
 *	  convenient or merely confusing.  The flag is needed since an
 *	  implicitly-added RTE shouldn't change the namespace for unqualified
 *	  column names processed later, and it also shouldn't affect the
 *	  expansion of '*'.
 *
 *	  checkForRead, checkForWrite, and checkAsUser control run-time access
 *	  permissions checks.  A rel will be checked for read or write access
 *	  (or both, or neither) per checkForRead and checkForWrite.  If
 *	  checkAsUser is not InvalidOid, then do the permissions checks using
 *	  the access rights of that user, not the current effective user ID.
 *	  (This allows rules to act as setuid gateways.)
 *--------------------
427
 */
428 429 430 431 432
typedef enum RTEKind
{
	RTE_RELATION,				/* ordinary relation reference */
	RTE_SUBQUERY,				/* subquery in FROM */
	RTE_JOIN,					/* join */
433 434
	RTE_SPECIAL,				/* special rule relation (NEW or OLD) */
	RTE_FUNCTION				/* function in FROM */
435 436
} RTEKind;

437
typedef struct RangeTblEntry
438
{
439
	NodeTag		type;
440

441 442
	RTEKind		rtekind;		/* see above */

443
	/*
444 445
	 * XXX the fields applicable to only some rte kinds should be merged
	 * into a union.  I didn't do this yet because the diffs would impact
B
Bruce Momjian 已提交
446
	 * a lot of code that is being actively worked on.	FIXME later.
447 448 449
	 */

	/*
450
	 * Fields valid for a plain relation RTE (else zero):
451 452
	 */
	Oid			relid;			/* OID of the relation */
453

454 455 456 457
	/*
	 * Fields valid for a subquery RTE (else NULL):
	 */
	Query	   *subquery;		/* the sub-query */
458

459 460 461 462
	/*
	 * Fields valid for a function RTE (else NULL):
	 */
	Node	   *funcexpr;		/* expression tree for func call */
463 464
	List	   *coldeflist;		/* list of ColumnDef nodes for runtime
								 * assignment of RECORD TupleDesc */
465

466
	/*
467
	 * Fields valid for a join RTE (else NULL/zero):
468
	 *
469 470 471
	 * joinaliasvars is a list of Vars or COALESCE expressions corresponding
	 * to the columns of the join result.  An alias Var referencing column
	 * K of the join result can be replaced by the K'th element of
B
Bruce Momjian 已提交
472 473
	 * joinaliasvars --- but to simplify the task of reverse-listing
	 * aliases correctly, we do not do that until planning time.
474 475
	 */
	JoinType	jointype;		/* type of join */
476
	List	   *joinaliasvars;	/* list of alias-var expansions */
477

478 479 480
	/*
	 * Fields valid in all RTEs:
	 */
481 482
	Alias	   *alias;			/* user-written alias clause, if any */
	Alias	   *eref;			/* expanded reference names */
483 484 485 486 487 488
	bool		inh;			/* inheritance requested? */
	bool		inFromCl;		/* present in FROM clause */
	bool		checkForRead;	/* check rel for read access */
	bool		checkForWrite;	/* check rel for write access */
	Oid			checkAsUser;	/* if not zero, check access as this user */
} RangeTblEntry;
489

490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
/*
 * SortClause -
 *	   representation of ORDER BY clauses
 *
 * tleSortGroupRef must match ressortgroupref of exactly one Resdom of the
 * associated targetlist; that is the expression to be sorted (or grouped) by.
 * sortop is the OID of the ordering operator.
 *
 * SortClauses are also used to identify Resdoms that we will do a "Unique"
 * filter step on (for SELECT DISTINCT and SELECT DISTINCT ON).  The
 * distinctClause list is simply a copy of the relevant members of the
 * sortClause list.  Note that distinctClause can be a subset of sortClause,
 * but cannot have members not present in sortClause; and the members that
 * do appear must be in the same order as in sortClause.
 */
typedef struct SortClause
506
{
507
	NodeTag		type;
508 509 510
	Index		tleSortGroupRef;	/* reference into targetlist */
	Oid			sortop;			/* the sort operator to use */
} SortClause;
511

512 513 514 515 516 517 518
/*
 * GroupClause -
 *	   representation of GROUP BY clauses
 *
 * GroupClause is exactly like SortClause except for the nodetag value
 * (it's probably not even really necessary to have two different
 * nodetags...).  We have routines that operate interchangeably on both.
519
 */
520 521 522 523 524 525
typedef SortClause GroupClause;


/*****************************************************************************
 *		Optimizable Statements
 *****************************************************************************/
526 527

/* ----------------------
528
 *		Insert Statement
529 530
 * ----------------------
 */
531
typedef struct InsertStmt
532
{
533
	NodeTag		type;
534
	RangeVar   *relation;		/* relation to insert into */
535 536 537 538 539 540 541 542 543 544
	List	   *cols;			/* optional: names of the target columns */

	/*
	 * An INSERT statement has *either* VALUES or SELECT, never both. If
	 * VALUES, a targetList is supplied (empty for DEFAULT VALUES). If
	 * SELECT, a complete SelectStmt (or set-operation tree) is supplied.
	 */
	List	   *targetList;		/* the target list (of ResTarget) */
	Node	   *selectStmt;		/* the source SELECT */
} InsertStmt;
545

546
/* ----------------------
547
 *		Delete Statement
548 549
 * ----------------------
 */
550
typedef struct DeleteStmt
551
{
552
	NodeTag		type;
553
	RangeVar   *relation;		/* relation to delete from */
554 555
	Node	   *whereClause;	/* qualifications */
} DeleteStmt;
556 557

/* ----------------------
558
 *		Update Statement
559 560
 * ----------------------
 */
561
typedef struct UpdateStmt
562
{
563
	NodeTag		type;
564
	RangeVar   *relation;		/* relation to update */
565 566
	List	   *targetList;		/* the target list (of ResTarget) */
	Node	   *whereClause;	/* qualifications */
567
	List	   *fromClause;		/* optional from clause for more tables */
568
} UpdateStmt;
569 570

/* ----------------------
571 572 573 574 575 576 577 578 579 580
 *		Select Statement
 *
 * A "simple" SELECT is represented in the output of gram.y by a single
 * SelectStmt node.  A SELECT construct containing set operators (UNION,
 * INTERSECT, EXCEPT) is represented by a tree of SelectStmt nodes, in
 * which the leaf nodes are component SELECTs and the internal nodes
 * represent UNION, INTERSECT, or EXCEPT operators.  Using the same node
 * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
 * LIMIT, etc, clause values into a SELECT statement without worrying
 * whether it is a simple or compound SELECT.
581 582
 * ----------------------
 */
583 584 585 586 587 588 589 590 591
typedef enum SetOperation
{
	SETOP_NONE = 0,
	SETOP_UNION,
	SETOP_INTERSECT,
	SETOP_EXCEPT
} SetOperation;

typedef struct SelectStmt
592
{
593
	NodeTag		type;
594 595 596

	/*
	 * These fields are used only in "leaf" SelectStmts.
597 598
	 *
	 * into and intoColNames are a kluge; they belong somewhere else...
599 600 601 602
	 */
	List	   *distinctClause; /* NULL, list of DISTINCT ON exprs, or
								 * lcons(NIL,NIL) for all (SELECT
								 * DISTINCT) */
603
	RangeVar   *into;			/* target table (for select into table) */
604 605 606 607 608 609 610 611 612
	List	   *intoColNames;	/* column names for into table */
	List	   *targetList;		/* the target list (of ResTarget) */
	List	   *fromClause;		/* the FROM clause */
	Node	   *whereClause;	/* WHERE qualification */
	List	   *groupClause;	/* GROUP BY clauses */
	Node	   *havingClause;	/* HAVING conditional-expression */

	/*
	 * These fields are used in both "leaf" SelectStmts and upper-level
613
	 * SelectStmts.
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
	 */
	List	   *sortClause;		/* sort clause (a list of SortGroupBy's) */
	Node	   *limitOffset;	/* # of result tuples to skip */
	Node	   *limitCount;		/* # of result tuples to return */
	List	   *forUpdate;		/* FOR UPDATE clause */

	/*
	 * These fields are used only in upper-level SelectStmts.
	 */
	SetOperation op;			/* type of set op */
	bool		all;			/* ALL specified? */
	struct SelectStmt *larg;	/* left child */
	struct SelectStmt *rarg;	/* right child */
	/* Eventually add fields for CORRESPONDING spec here */
} SelectStmt;
629 630

/* ----------------------
631 632 633 634 635 636 637
 *		Set Operation node for post-analysis query trees
 *
 * After parse analysis, a SELECT with set operations is represented by a
 * top-level Query node containing the leaf SELECTs as subqueries in its
 * range table.  Its setOperations field shows the tree of set operations,
 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
 * nodes replaced by SetOperationStmt nodes.
638 639
 * ----------------------
 */
640
typedef struct SetOperationStmt
641
{
642
	NodeTag		type;
643 644 645 646 647 648 649
	SetOperation op;			/* type of set op */
	bool		all;			/* ALL specified? */
	Node	   *larg;			/* left child */
	Node	   *rarg;			/* right child */
	/* Eventually add fields for CORRESPONDING spec here */

	/* Fields derived during parse analysis: */
650
	List	   *colTypes;		/* list of OIDs of output column types */
651 652 653 654 655 656 657 658 659 660 661
} SetOperationStmt;


/*****************************************************************************
 *		Other Statements (no optimizations required)
 *
 *		Some of them require a little bit of transformation (which is also
 *		done by transformStmt). The whole structure is then passed on to
 *		ProcessUtility (by-passing the optimization step) as the utilityStmt
 *		field in Query.
 *****************************************************************************/
662

663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
/* ----------------------
 *		Create Schema Statement
 *
 * NOTE: the schemaElts list contains raw parsetrees for component statements
 * of the schema, such as CREATE TABLE, GRANT, etc.  These are analyzed and
 * executed after the schema itself is created.
 * ----------------------
 */
typedef struct CreateSchemaStmt
{
	NodeTag		type;
	char	   *schemaname;		/* the name of the schema to create */
	char	   *authid;			/* the owner of the created schema */
	List	   *schemaElts;		/* schema components (list of parsenodes) */
} CreateSchemaStmt;

679 680 681 682 683 684
typedef enum DropBehavior
{
	DROP_RESTRICT,				/* drop fails if any dependent objects */
	DROP_CASCADE				/* remove dependent objects too */
} DropBehavior;

685
/* ----------------------
686 687 688 689
 *	Alter Table
 *
 * The fields are used in different ways by the different variants of
 * this command.
690 691
 * ----------------------
 */
692
typedef struct AlterTableStmt
693
{
694
	NodeTag		type;
695 696 697
	char		subtype;		/*------------
								 *	A = add column
								 *	T = alter column default
698
								 *	N = alter column drop not null
B
Bruce Momjian 已提交
699
								 *	n = alter column set not null
700
								 *	S = alter column statistics
B
Bruce Momjian 已提交
701
								 *	M = alter column storage
702 703
								 *	D = drop column
								 *	C = add constraint
704 705
								 *	c = pre-processed add constraint
								 *		(local in parser/analyze.c)
706 707 708
								 *	X = drop constraint
								 *	E = create toast table
								 *	U = change owner
709
								 *	L = CLUSTER ON
B
Bruce Momjian 已提交
710
								 *  o = DROP OIDS
711 712
								 *------------
								 */
713
	RangeVar   *relation;		/* table to work on */
714 715 716
	char	   *name;			/* column or constraint name to act on, or
								 * new owner */
	Node	   *def;			/* definition of new column or constraint */
717
	DropBehavior behavior;		/* RESTRICT or CASCADE for DROP cases */
718
} AlterTableStmt;
719

B
Bruce Momjian 已提交
720 721 722 723
/* ----------------------
 *	Alter Domain
 *
 * The fields are used in different ways by the different variants of
T
Tom Lane 已提交
724
 * this command. Subtypes should match AlterTable subtypes where possible.
B
Bruce Momjian 已提交
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
 * ----------------------
 */
typedef struct AlterDomainStmt
{
	NodeTag		type;
	char		subtype;		/*------------
								 *	T = alter column default
								 *	N = alter column drop not null
								 *	O = alter column set not null
								 *	C = add constraint
								 *	X = drop constraint
								 *	U = change owner
								 *------------
								 */
	List	   *typename;		/* table to work on */
	char	   *name;			/* column or constraint name to act on, or
								 * new owner */
	Node	   *def;			/* definition of default or constraint */
	DropBehavior behavior;		/* RESTRICT or CASCADE for DROP cases */
} AlterDomainStmt;


747
/* ----------------------
748
 *		Grant|Revoke Statement
749 750
 * ----------------------
 */
751 752 753 754 755 756 757 758 759 760 761
typedef enum GrantObjectType
{
	ACL_OBJECT_RELATION,		/* table, view, sequence */
	ACL_OBJECT_DATABASE,		/* database */
	ACL_OBJECT_FUNCTION,		/* function */
	ACL_OBJECT_LANGUAGE,		/* procedural language */
	ACL_OBJECT_NAMESPACE		/* namespace */
} GrantObjectType;

/*
 * Grantable rights are encoded so that we can OR them together in a bitmask.
762
 * The present representation of AclItem limits us to 15 distinct rights.
763 764 765 766 767 768 769 770 771 772 773 774
 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
 */
#define ACL_INSERT		(1<<0)	/* for relations */
#define ACL_SELECT		(1<<1)
#define ACL_UPDATE		(1<<2)
#define ACL_DELETE		(1<<3)
#define ACL_RULE		(1<<4)
#define ACL_REFERENCES	(1<<5)
#define ACL_TRIGGER		(1<<6)
#define ACL_EXECUTE		(1<<7)	/* for functions */
#define ACL_USAGE		(1<<8)	/* for languages and namespaces */
#define ACL_CREATE		(1<<9)	/* for namespaces and databases */
B
Bruce Momjian 已提交
775
#define ACL_CREATE_TEMP (1<<10) /* for databases */
776 777 778
#define N_ACL_RIGHTS	11		/* 1 plus the last 1<<x */
#define ACL_ALL_RIGHTS	(-1)	/* all-privileges marker in GRANT list */
#define ACL_NO_RIGHTS	0
779 780

typedef struct GrantStmt
781
{
782
	NodeTag		type;
783 784
	bool		is_grant;		/* true = GRANT, false = REVOKE */
	GrantObjectType objtype;	/* kind of object being operated on */
B
Bruce Momjian 已提交
785 786 787
	List	   *objects;		/* list of RangeVar nodes, FuncWithArgs
								 * nodes, or plain names (as Value
								 * strings) */
788 789
	List	   *privileges;		/* integer list of privilege codes */
	List	   *grantees;		/* list of PrivGrantee nodes */
790 791
	bool		grant_option;	/* grant or revoke grant option */
	DropBehavior behavior;		/* drop behavior (for REVOKE) */
792
} GrantStmt;
793

794
typedef struct PrivGrantee
795
{
796
	NodeTag		type;
797 798 799
	char	   *username;		/* if both are NULL then PUBLIC */
	char	   *groupname;
} PrivGrantee;
800

801
typedef struct FuncWithArgs
802
{
803
	NodeTag		type;
804
	List	   *funcname;		/* qualified name of function */
805 806
	List	   *funcargs;		/* list of Typename nodes */
} FuncWithArgs;
807

808 809
/* This is only used internally in gram.y. */
typedef struct PrivTarget
810
{
811
	NodeTag		type;
812
	GrantObjectType objtype;
813 814 815
	List	   *objs;
} PrivTarget;

816
/* ----------------------
817
 *		Copy Statement
818 819
 * ----------------------
 */
820
typedef struct CopyStmt
821
{
822
	NodeTag		type;
823
	RangeVar   *relation;		/* the relation to copy */
B
Bruce Momjian 已提交
824 825
	List	   *attlist;		/* List of column names (as Strings), or
								 * NIL for all columns */
826
	bool		is_from;		/* TO or FROM */
827
	char	   *filename;		/* if NULL, use stdin/stdout */
828
	List	   *options;		/* List of DefElem nodes */
829
} CopyStmt;
M
 
Marc G. Fournier 已提交
830 831

/* ----------------------
832 833 834 835 836 837 838
 *		Create Table Statement
 *
 * NOTE: in the raw gram.y output, ColumnDef, Constraint, and FkConstraint
 * nodes are intermixed in tableElts, and constraints is NIL.  After parse
 * analysis, tableElts contains just ColumnDefs, and constraints contains
 * just Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
 * implementation).
M
 
Marc G. Fournier 已提交
839 840
 * ----------------------
 */
841 842 843 844 845 846 847 848 849 850

/* What to do at commit time for temporary relations */
typedef enum OnCommitAction
{
	ONCOMMIT_NOOP,				/* No ON COMMIT clause (do nothing) */
	ONCOMMIT_PRESERVE_ROWS,		/* ON COMMIT PRESERVE ROWS (do nothing) */
	ONCOMMIT_DELETE_ROWS,		/* ON COMMIT DELETE ROWS */
	ONCOMMIT_DROP				/* ON COMMIT DROP */
} OnCommitAction;

851
typedef struct CreateStmt
M
 
Marc G. Fournier 已提交
852 853
{
	NodeTag		type;
854
	RangeVar   *relation;		/* relation to create */
855
	List	   *tableElts;		/* column definitions (list of ColumnDef) */
856
	List	   *inhRelations;	/* relations to inherit from */
857 858
	List	   *constraints;	/* constraints (list of Constraint nodes) */
	bool		hasoids;		/* should it have OIDs? */
859
	OnCommitAction oncommit;	/* what do we do at COMMIT? */
860
} CreateStmt;
861

862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
/* ----------
 * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
 *
 * XXX probably these ought to be unified with FkConstraints at some point?
 *
 * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
 * we may have the expression in either "raw" form (an untransformed
 * parse tree) or "cooked" form (the nodeToString representation of
 * an executable expression tree), depending on how this Constraint
 * node was created (by parsing, or by inheritance from an existing
 * relation).  We should never have both in the same node!
 *
 * Constraint attributes (DEFERRABLE etc) are initially represented as
 * separate Constraint nodes for simplicity of parsing.  analyze.c makes
 * a pass through the constraints list to attach the info to the appropriate
 * FkConstraint node (and, perhaps, someday to other kinds of constraints).
 * ----------
879
 */
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896

typedef enum ConstrType			/* types of constraints */
{
	CONSTR_NULL,				/* not SQL92, but a lot of people expect
								 * it */
	CONSTR_NOTNULL,
	CONSTR_DEFAULT,
	CONSTR_CHECK,
	CONSTR_PRIMARY,
	CONSTR_UNIQUE,
	CONSTR_ATTR_DEFERRABLE,		/* attributes for previous constraint node */
	CONSTR_ATTR_NOT_DEFERRABLE,
	CONSTR_ATTR_DEFERRED,
	CONSTR_ATTR_IMMEDIATE
} ConstrType;

typedef struct Constraint
897
{
898
	NodeTag		type;
899 900 901 902
	ConstrType	contype;
	char	   *name;			/* name, or NULL if unnamed */
	Node	   *raw_expr;		/* expr, as untransformed parse tree */
	char	   *cooked_expr;	/* expr, as nodeToString representation */
B
Bruce Momjian 已提交
903 904
	List	   *keys;			/* String nodes naming referenced
								 * column(s) */
905
} Constraint;
906

907 908
/* ----------
 * Definitions for FOREIGN KEY constraints in CreateStmt
909 910 911 912 913 914 915 916
 *
 * Note: FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
 * stored into pg_constraint.confmatchtype.  Changing the code values may
 * require an initdb!
 *
 * If skip_validation is true then we skip checking that the existing rows
 * in the table satisfy the constraint, and just install the catalog entries
B
Bruce Momjian 已提交
917
 * for the constraint.	This is currently used only during CREATE TABLE
918
 * (when we know the table must be empty).
919
 * ----------
920
 */
921 922 923 924 925
#define FKCONSTR_ACTION_NOACTION	'a'
#define FKCONSTR_ACTION_RESTRICT	'r'
#define FKCONSTR_ACTION_CASCADE		'c'
#define FKCONSTR_ACTION_SETNULL		'n'
#define FKCONSTR_ACTION_SETDEFAULT	'd'
926

927 928 929
#define FKCONSTR_MATCH_FULL			'f'
#define FKCONSTR_MATCH_PARTIAL		'p'
#define FKCONSTR_MATCH_UNSPECIFIED	'u'
930 931

typedef struct FkConstraint
932
{
933
	NodeTag		type;
934
	char	   *constr_name;	/* Constraint name, or NULL if unnamed */
935
	RangeVar   *pktable;		/* Primary key table */
936 937
	List	   *fk_attrs;		/* Attributes of foreign key */
	List	   *pk_attrs;		/* Corresponding attrs in PK table */
938 939 940
	char		fk_matchtype;	/* FULL, PARTIAL, UNSPECIFIED */
	char		fk_upd_action;	/* ON UPDATE action */
	char		fk_del_action;	/* ON DELETE action */
941 942
	bool		deferrable;		/* DEFERRABLE */
	bool		initdeferred;	/* INITIALLY DEFERRED */
B
Bruce Momjian 已提交
943
	bool		skip_validation;	/* skip validation of existing rows? */
944
} FkConstraint;
945 946

/* ----------------------
947
 *		Create/Drop TRIGGER Statements
948 949
 * ----------------------
 */
950 951

typedef struct CreateTrigStmt
952
{
953
	NodeTag		type;
954 955 956 957
	char	   *trigname;		/* TRIGGER's name */
	RangeVar   *relation;		/* relation trigger is on */
	List	   *funcname;		/* qual. name of function to call */
	List	   *args;			/* list of (T_String) Values or NIL */
958 959
	bool		before;			/* BEFORE/AFTER */
	bool		row;			/* ROW/STATEMENT */
960
	char		actions[4];		/* 1 to 3 of 'i', 'u', 'd', + trailing \0 */
961

962 963 964 965 966
	/* The following are used for referential */
	/* integrity constraint triggers */
	bool		isconstraint;	/* This is an RI trigger */
	bool		deferrable;		/* [NOT] DEFERRABLE */
	bool		initdeferred;	/* INITIALLY {DEFERRED|IMMEDIATE} */
967
	RangeVar   *constrrel;		/* opposite relation */
968 969
} CreateTrigStmt;

970
/* ----------------------
971
 *		Create/Drop PROCEDURAL LANGUAGE Statement
972 973
 * ----------------------
 */
974
typedef struct CreatePLangStmt
975 976
{
	NodeTag		type;
977
	char	   *plname;			/* PL name */
978
	List	   *plhandler;		/* PL call handler function (qual. name) */
B
Bruce Momjian 已提交
979 980
	List	   *plvalidator;	/* optional validator function (qual.
								 * name) */
981 982
	bool		pltrusted;		/* PL is trusted */
} CreatePLangStmt;
983

984
typedef struct DropPLangStmt
985
{
986
	NodeTag		type;
987
	char	   *plname;			/* PL name */
988
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
989
} DropPLangStmt;
990 991

/* ----------------------
992
 *	Create/Alter/Drop User Statements
993 994
 * ----------------------
 */
995
typedef struct CreateUserStmt
996
{
997
	NodeTag		type;
998 999 1000
	char	   *user;			/* PostgreSQL user login name */
	List	   *options;		/* List of DefElem nodes */
} CreateUserStmt;
1001

1002
typedef struct AlterUserStmt
1003
{
1004
	NodeTag		type;
1005 1006 1007
	char	   *user;			/* PostgreSQL user login name */
	List	   *options;		/* List of DefElem nodes */
} AlterUserStmt;
1008

1009
typedef struct AlterUserSetStmt
1010
{
1011
	NodeTag		type;
1012 1013 1014 1015
	char	   *user;
	char	   *variable;
	List	   *value;
} AlterUserSetStmt;
1016

1017
typedef struct DropUserStmt
V
Vadim B. Mikheev 已提交
1018 1019
{
	NodeTag		type;
1020 1021
	List	   *users;			/* List of users to remove */
} DropUserStmt;
V
Vadim B. Mikheev 已提交
1022

1023
/* ----------------------
1024
 *		Create/Alter/Drop Group Statements
1025 1026
 * ----------------------
 */
1027
typedef struct CreateGroupStmt
1028
{
1029
	NodeTag		type;
1030 1031 1032
	char	   *name;			/* name of the new group */
	List	   *options;		/* List of DefElem nodes */
} CreateGroupStmt;
1033

1034 1035 1036 1037 1038 1039 1040
typedef struct AlterGroupStmt
{
	NodeTag		type;
	char	   *name;			/* name of group to alter */
	int			action;			/* +1 = add, -1 = drop user */
	List	   *listUsers;		/* list of users to add/drop */
} AlterGroupStmt;
1041

1042
typedef struct DropGroupStmt
1043
{
1044 1045
	NodeTag		type;
	char	   *name;
1046
} DropGroupStmt;
1047 1048

/* ----------------------
B
Bruce Momjian 已提交
1049
 *		{Create|Alter} SEQUENCE Statement
1050 1051 1052
 * ----------------------
 */

1053
typedef struct CreateSeqStmt
1054
{
1055
	NodeTag		type;
1056
	RangeVar   *sequence;		/* the sequence to create */
1057 1058
	List	   *options;
} CreateSeqStmt;
1059

B
Bruce Momjian 已提交
1060 1061 1062 1063 1064 1065 1066
typedef struct AlterSeqStmt
{
	NodeTag		type;
	RangeVar   *sequence;		/* the sequence to alter */
	List	   *options;
} AlterSeqStmt;

1067
/* ----------------------
1068
 *		Create {Aggregate|Operator|Type} Statement
1069 1070
 * ----------------------
 */
1071 1072 1073 1074 1075 1076 1077
typedef enum DefineStmtKind
{
	DEFINE_STMT_AGGREGATE,
	DEFINE_STMT_OPERATOR,
	DEFINE_STMT_TYPE
} DefineStmtKind;

1078
typedef struct DefineStmt
1079 1080
{
	NodeTag		type;
1081
	DefineStmtKind kind;		/* see above */
1082
	List	   *defnames;		/* qualified name (list of Value strings) */
1083 1084
	List	   *definition;		/* a list of DefElem */
} DefineStmt;
1085

T
Tom Lane 已提交
1086 1087 1088 1089 1090 1091 1092
/* ----------------------
 *		Create Domain Statement
 * ----------------------
 */
typedef struct CreateDomainStmt
{
	NodeTag		type;
1093 1094 1095
	List	   *domainname;		/* qualified name (list of Value strings) */
	TypeName   *typename;		/* the base type */
	List	   *constraints;	/* constraints (list of Constraint nodes) */
T
Tom Lane 已提交
1096 1097
} CreateDomainStmt;

1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
/* ----------------------
 *		Create Operator Class Statement
 * ----------------------
 */
typedef struct CreateOpClassStmt
{
	NodeTag		type;
	List	   *opclassname;	/* qualified name (list of Value strings) */
	char	   *amname;			/* name of index AM opclass is for */
	TypeName   *datatype;		/* datatype of indexed column */
	List	   *items;			/* List of CreateOpClassItem nodes */
	bool		isDefault;		/* Should be marked as default for type? */
} CreateOpClassStmt;

#define OPCLASS_ITEM_OPERATOR		1
#define OPCLASS_ITEM_FUNCTION		2
#define OPCLASS_ITEM_STORAGETYPE	3

typedef struct CreateOpClassItem
{
	NodeTag		type;
	int			itemtype;		/* see codes above */
	/* fields used for an operator or function item: */
	List	   *name;			/* operator or function name */
	List	   *args;			/* argument types */
	int			number;			/* strategy num or support proc num */
	bool		recheck;		/* only used for operators */
	/* fields used for a storagetype item: */
	TypeName   *storedtype;		/* datatype stored in index */
} CreateOpClassItem;

H
Hiroshi Inoue 已提交
1129
/* ----------------------
1130
 *		Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
H
Hiroshi Inoue 已提交
1131 1132 1133
 * ----------------------
 */

1134 1135 1136 1137
#define DROP_TABLE	  1
#define DROP_SEQUENCE 2
#define DROP_VIEW	  3
#define DROP_INDEX	  4
B
Bruce Momjian 已提交
1138 1139 1140 1141
#define DROP_TYPE	  5
#define DROP_DOMAIN   6
#define DROP_CONVERSION   7
#define DROP_SCHEMA   8
1142

1143 1144 1145
typedef struct DropStmt
{
	NodeTag		type;
1146
	List	   *objects;		/* list of sublists of names (as Values) */
1147 1148
	int			removeType;		/* see #defines above */
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1149
} DropStmt;
1150

1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
/* ----------------------
 *		Drop Rule|Trigger Statement
 *
 * In general this may be used for dropping any property of a relation;
 * for example, someday soon we may have DROP ATTRIBUTE.
 * ----------------------
 */

#define DROP_RULE	  100
#define DROP_TRIGGER  101

typedef struct DropPropertyStmt
{
	NodeTag		type;
	RangeVar   *relation;		/* owning relation */
	char	   *property;		/* name of rule, trigger, etc */
1167 1168
	int			removeType;		/* see #defines above */
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1169 1170
} DropPropertyStmt;

1171
/* ----------------------
1172
 *				Truncate Table Statement
1173 1174
 * ----------------------
 */
1175
typedef struct TruncateStmt
1176
{
1177
	NodeTag		type;
1178
	RangeVar   *relation;		/* relation to be truncated */
1179
} TruncateStmt;
1180 1181

/* ----------------------
1182
 *				Comment On Statement
1183 1184
 * ----------------------
 */
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
#define COMMENT_ON_AGGREGATE	100
#define COMMENT_ON_COLUMN		101
#define COMMENT_ON_CONSTRAINT	102
#define COMMENT_ON_DATABASE		103
#define COMMENT_ON_FUNCTION		104
#define COMMENT_ON_INDEX		105
#define COMMENT_ON_OPERATOR		106
#define COMMENT_ON_RULE			107
#define COMMENT_ON_SCHEMA		108
#define COMMENT_ON_SEQUENCE		109
#define COMMENT_ON_TABLE		110
#define COMMENT_ON_TRIGGER		111
#define COMMENT_ON_TYPE			112
#define COMMENT_ON_VIEW			113

1200
typedef struct CommentStmt
1201
{
1202
	NodeTag		type;
1203
	int			objtype;		/* Object's type, see codes above */
1204 1205 1206
	List	   *objname;		/* Qualified name of the object */
	List	   *objargs;		/* Arguments if needed (eg, for functions) */
	char	   *comment;		/* Comment to insert, or NULL to remove */
1207
} CommentStmt;
1208 1209

/* ----------------------
1210 1211 1212 1213 1214
 *		Declare Cursor Statement
 * ----------------------
 */
#define CURSOR_OPT_BINARY		0x0001
#define CURSOR_OPT_SCROLL		0x0002
1215 1216 1217
#define CURSOR_OPT_NO_SCROLL	0x0004
#define CURSOR_OPT_INSENSITIVE	0x0008
#define CURSOR_OPT_HOLD			0x0010
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238

typedef struct DeclareCursorStmt
{
	NodeTag		type;
	char	   *portalname;		/* name of the portal (cursor) */
	int			options;		/* bitmask of options (see above) */
	Node	   *query;			/* the SELECT query */
} DeclareCursorStmt;

/* ----------------------
 *		Close Portal Statement
 * ----------------------
 */
typedef struct ClosePortalStmt
{
	NodeTag		type;
	char	   *portalname;		/* name of the portal (cursor) */
} ClosePortalStmt;

/* ----------------------
 *		Fetch Statement (also Move)
1239 1240
 * ----------------------
 */
1241 1242
typedef enum FetchDirection
{
1243
	/* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1244
	FETCH_FORWARD,
1245 1246 1247 1248
	FETCH_BACKWARD,
	/* for these, howMany indicates a position; only one row is fetched */
	FETCH_ABSOLUTE,
	FETCH_RELATIVE
1249 1250
} FetchDirection;

1251 1252
#define FETCH_ALL	LONG_MAX

1253
typedef struct FetchStmt
1254
{
1255
	NodeTag		type;
1256
	FetchDirection direction;	/* see above */
1257
	long		howMany;		/* number of rows, or position argument */
1258 1259 1260
	char	   *portalname;		/* name of portal (cursor) */
	bool		ismove;			/* TRUE if MOVE */
} FetchStmt;
1261

1262
/* ----------------------
1263
 *		Create Index Statement
1264 1265
 * ----------------------
 */
1266
typedef struct IndexStmt
1267 1268
{
	NodeTag		type;
1269
	char	   *idxname;		/* name of the index */
1270
	RangeVar   *relation;		/* relation to build index on */
1271 1272 1273 1274 1275 1276 1277
	char	   *accessMethod;	/* name of access method (eg. btree) */
	List	   *indexParams;	/* a list of IndexElem */
	Node	   *whereClause;	/* qualification (partial-index predicate) */
	List	   *rangetable;		/* range table for qual, filled in by
								 * transformStmt() */
	bool		unique;			/* is index unique? */
	bool		primary;		/* is index on primary key? */
1278
	bool		isconstraint;	/* is it from a CONSTRAINT clause? */
1279
} IndexStmt;
1280

1281 1282 1283
/* ----------------------
 *		Create Function Statement
 * ----------------------
1284
 */
1285
typedef struct CreateFunctionStmt
1286
{
1287
	NodeTag		type;
1288
	bool		replace;		/* T => replace if already exists */
1289
	List	   *funcname;		/* qualified name of function to create */
1290
	List	   *argTypes;		/* list of argument types (TypeName nodes) */
1291
	TypeName   *returnType;		/* the return type */
1292
	List	   *options;		/* a list of DefElem */
1293
	List	   *withClause;		/* a list of DefElem */
1294
} CreateFunctionStmt;
1295

1296 1297 1298
/* ----------------------
 *		Drop Aggregate Statement
 * ----------------------
1299
 */
1300
typedef struct RemoveAggrStmt
1301
{
1302
	NodeTag		type;
1303
	List	   *aggname;		/* aggregate to drop */
1304
	TypeName   *aggtype;		/* TypeName for input datatype, or NULL */
1305
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1306
} RemoveAggrStmt;
1307

1308 1309 1310
/* ----------------------
 *		Drop Function Statement
 * ----------------------
1311
 */
1312
typedef struct RemoveFuncStmt
1313
{
1314
	NodeTag		type;
1315
	List	   *funcname;		/* function to drop */
1316
	List	   *args;			/* types of the arguments */
1317
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1318
} RemoveFuncStmt;
1319

1320 1321 1322
/* ----------------------
 *		Drop Operator Statement
 * ----------------------
1323
 */
1324
typedef struct RemoveOperStmt
1325
{
1326
	NodeTag		type;
1327
	List	   *opname;			/* operator to drop */
1328
	List	   *args;			/* types of the arguments */
1329
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1330
} RemoveOperStmt;
1331

1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
/* ----------------------
 *		Drop Operator Class Statement
 * ----------------------
 */
typedef struct RemoveOpClassStmt
{
	NodeTag		type;
	List	   *opclassname;	/* qualified name (list of Value strings) */
	char	   *amname;			/* name of index AM opclass is for */
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
} RemoveOpClassStmt;

1344
/* ----------------------
1345
 *		Alter Object Rename Statement
1346
 * ----------------------
1347 1348
 * Currently supports renaming tables, table columns, and triggers.
 * If renaming a table, oldname is ignored.
1349
 */
1350 1351 1352 1353 1354
#define RENAME_TABLE	110
#define RENAME_COLUMN	111
#define RENAME_TRIGGER	112
#define RENAME_RULE		113

1355
typedef struct RenameStmt
1356
{
1357
	NodeTag		type;
1358 1359
	RangeVar   *relation;		/* owning relation */
	char	   *oldname;		/* name of rule, trigger, etc */
1360
	char	   *newname;		/* the new name */
1361
	int			renameType;		/* RENAME_TABLE, RENAME_COLUMN, etc */
1362
} RenameStmt;
1363

1364 1365 1366
/* ----------------------
 *		Create Rule Statement
 * ----------------------
1367
 */
1368
typedef struct RuleStmt
1369 1370
{
	NodeTag		type;
1371
	RangeVar   *relation;		/* relation the rule is for */
1372 1373
	char	   *rulename;		/* name of the rule */
	Node	   *whereClause;	/* qualifications */
1374
	CmdType		event;			/* SELECT, INSERT, etc */
1375 1376
	bool		instead;		/* is a 'do instead'? */
	List	   *actions;		/* the action statements */
1377
	bool		replace;		/* OR REPLACE */
1378
} RuleStmt;
1379

1380 1381 1382
/* ----------------------
 *		Notify Statement
 * ----------------------
T
Thomas G. Lockhart 已提交
1383
 */
1384
typedef struct NotifyStmt
T
Thomas G. Lockhart 已提交
1385 1386
{
	NodeTag		type;
1387
	RangeVar   *relation;		/* qualified name to notify */
1388
} NotifyStmt;
T
Thomas G. Lockhart 已提交
1389

1390 1391 1392
/* ----------------------
 *		Listen Statement
 * ----------------------
T
Thomas G. Lockhart 已提交
1393
 */
1394
typedef struct ListenStmt
T
Thomas G. Lockhart 已提交
1395 1396
{
	NodeTag		type;
1397
	RangeVar   *relation;		/* qualified name to listen on */
1398
} ListenStmt;
T
Thomas G. Lockhart 已提交
1399

1400 1401 1402
/* ----------------------
 *		Unlisten Statement
 * ----------------------
1403
 */
1404
typedef struct UnlistenStmt
1405
{
1406
	NodeTag		type;
1407
	RangeVar   *relation;		/* qualified name to unlisten on, or '*' */
1408
} UnlistenStmt;
1409

1410
/* ----------------------
1411
 *		{Begin|Commit|Rollback} Transaction Statement
1412 1413
 * ----------------------
 */
1414 1415 1416 1417 1418 1419 1420 1421
typedef enum TransactionStmtKind
{
	TRANS_STMT_BEGIN,
	TRANS_STMT_START,			/* semantically identical to BEGIN */
	TRANS_STMT_COMMIT,
	TRANS_STMT_ROLLBACK
} TransactionStmtKind;

1422
typedef struct TransactionStmt
1423
{
1424
	NodeTag		type;
1425 1426
	TransactionStmtKind kind;	/* see above */
	List	   *options;		/* for BEGIN/START only */
1427
} TransactionStmt;
1428

B
Bruce Momjian 已提交
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
/* ----------------------
 *		Create Type Statement, composite types
 * ----------------------
 */
typedef struct CompositeTypeStmt
{
	NodeTag		type;
	RangeVar   *typevar;		/* the composite type to be created */
	List	   *coldeflist;		/* list of ColumnDef nodes */
} CompositeTypeStmt;


1441 1442 1443
/* ----------------------
 *		Create View Statement
 * ----------------------
1444
 */
1445
typedef struct ViewStmt
1446
{
1447
	NodeTag		type;
1448
	RangeVar   *view;			/* the view to be created */
1449 1450
	List	   *aliases;		/* target column names */
	Query	   *query;			/* the SQL statement */
1451
	bool		replace;		/* replace an existing view? */
1452
} ViewStmt;
1453

1454 1455 1456 1457 1458
/* ----------------------
 *		Load Statement
 * ----------------------
 */
typedef struct LoadStmt
1459
{
1460
	NodeTag		type;
1461 1462
	char	   *filename;		/* file to load */
} LoadStmt;
1463

1464 1465 1466
/* ----------------------
 *		Createdb Statement
 * ----------------------
1467
 */
1468
typedef struct CreatedbStmt
1469
{
1470
	NodeTag		type;
1471
	char	   *dbname;			/* name of database to create */
1472
	List	   *options;		/* List of DefElem nodes */
1473
} CreatedbStmt;
1474

1475 1476 1477
/* ----------------------
 *	Alter Database
 * ----------------------
1478
 */
1479
typedef struct AlterDatabaseSetStmt
1480
{
1481
	NodeTag		type;
1482 1483 1484 1485
	char	   *dbname;
	char	   *variable;
	List	   *value;
} AlterDatabaseSetStmt;
1486

1487 1488 1489
/* ----------------------
 *		Dropdb Statement
 * ----------------------
1490
 */
1491
typedef struct DropdbStmt
1492
{
1493
	NodeTag		type;
1494 1495
	char	   *dbname;			/* database to drop */
} DropdbStmt;
1496

1497 1498 1499
/* ----------------------
 *		Cluster Statement (support pbrown's cluster index implementation)
 * ----------------------
1500
 */
1501
typedef struct ClusterStmt
1502
{
1503
	NodeTag		type;
1504
	RangeVar   *relation;		/* relation being indexed, or NULL if all */
1505 1506
	char	   *indexname;		/* original index defined */
} ClusterStmt;
1507

1508 1509
/* ----------------------
 *		Vacuum and Analyze Statements
1510
 *
1511 1512 1513
 * Even though these are nominally two statements, it's convenient to use
 * just one node type for both.
 * ----------------------
1514
 */
1515
typedef struct VacuumStmt
1516
{
1517
	NodeTag		type;
1518 1519 1520 1521 1522
	bool		vacuum;			/* do VACUUM step */
	bool		full;			/* do FULL (non-concurrent) vacuum */
	bool		analyze;		/* do ANALYZE step */
	bool		freeze;			/* early-freeze option */
	bool		verbose;		/* print progress info */
1523
	RangeVar   *relation;		/* single table to process, or NULL */
1524 1525
	List	   *va_cols;		/* list of column names, or NIL for all */
} VacuumStmt;
1526

1527 1528 1529
/* ----------------------
 *		Explain Statement
 * ----------------------
1530
 */
1531
typedef struct ExplainStmt
M
 
Marc G. Fournier 已提交
1532 1533
{
	NodeTag		type;
1534 1535 1536 1537
	Query	   *query;			/* the query */
	bool		verbose;		/* print plan info */
	bool		analyze;		/* get statistics by executing plan */
} ExplainStmt;
M
 
Marc G. Fournier 已提交
1538

1539 1540 1541
/* ----------------------
 * Checkpoint Statement
 * ----------------------
1542
 */
1543
typedef struct CheckPointStmt
1544
{
1545
	NodeTag		type;
1546
} CheckPointStmt;
1547

1548 1549 1550
/* ----------------------
 * Set Statement
 * ----------------------
1551
 */
1552 1553

typedef struct VariableSetStmt
1554 1555
{
	NodeTag		type;
1556 1557
	char	   *name;
	List	   *args;
1558
	bool		is_local;		/* SET LOCAL */
1559
} VariableSetStmt;
1560

1561 1562 1563
/* ----------------------
 * Show Statement
 * ----------------------
1564
 */
1565 1566

typedef struct VariableShowStmt
1567
{
1568
	NodeTag		type;
1569 1570
	char	   *name;
} VariableShowStmt;
1571

1572 1573 1574
/* ----------------------
 * Reset Statement
 * ----------------------
1575
 */
1576 1577

typedef struct VariableResetStmt
1578
{
1579
	NodeTag		type;
1580 1581
	char	   *name;
} VariableResetStmt;
1582

1583 1584 1585
/* ----------------------
 *		LOCK Statement
 * ----------------------
1586
 */
1587
typedef struct LockStmt
1588
{
1589
	NodeTag		type;
1590
	List	   *relations;		/* relations to lock */
1591 1592
	int			mode;			/* lock mode */
} LockStmt;
1593

1594 1595 1596
/* ----------------------
 *		SET CONSTRAINTS Statement
 * ----------------------
1597
 */
1598
typedef struct ConstraintsSetStmt
1599
{
1600
	NodeTag		type;
1601 1602 1603
	List	   *constraints;	/* List of names as Value strings */
	bool		deferred;
} ConstraintsSetStmt;
B
Bruce Momjian 已提交
1604

1605 1606 1607
/* ----------------------
 *		REINDEX Statement
 * ----------------------
1608
 */
1609 1610 1611 1612 1613 1614 1615
typedef enum ReindexStmtKind
{
	REINDEX_INDEX,
	REINDEX_TABLE,
	REINDEX_DATABASE
} ReindexStmtKind;

1616
typedef struct ReindexStmt
1617
{
1618
	NodeTag		type;
1619
	ReindexStmtKind kind;		/* see above */
1620 1621
	RangeVar   *relation;		/* Table or index to reindex */
	const char *name;			/* name of database to reindex */
1622 1623 1624
	bool		force;
	bool		all;
} ReindexStmt;
1625

1626 1627 1628 1629 1630 1631 1632
/* ----------------------
 *		CREATE CONVERSION Statement
 * ----------------------
 */
typedef struct CreateConversionStmt
{
	NodeTag		type;
B
Bruce Momjian 已提交
1633 1634 1635 1636 1637
	List	   *conversion_name;	/* Name of the conversion */
	char	   *for_encoding_name;		/* source encoding name */
	char	   *to_encoding_name;		/* destiname encoding name */
	List	   *func_name;		/* qualified conversion function name */
	bool		def;			/* is this a default conversion? */
1638 1639
} CreateConversionStmt;

1640 1641 1642 1643 1644 1645 1646 1647 1648 1649
/* ----------------------
 *	CREATE CAST Statement
 * ----------------------
 */
typedef struct CreateCastStmt
{
	NodeTag		type;
	TypeName   *sourcetype;
	TypeName   *targettype;
	FuncWithArgs *func;
1650
	CoercionContext context;
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
} CreateCastStmt;

/* ----------------------
 *	DROP CAST Statement
 * ----------------------
 */
typedef struct DropCastStmt
{
	NodeTag		type;
	TypeName   *sourcetype;
	TypeName   *targettype;
	DropBehavior behavior;
} DropCastStmt;


1666 1667 1668 1669 1670 1671
/* ----------------------
 *		PREPARE Statement
 * ----------------------
 */
typedef struct PrepareStmt
{
B
Bruce Momjian 已提交
1672 1673 1674 1675 1676
	NodeTag		type;
	char	   *name;			/* Name of plan, arbitrary */
	List	   *argtypes;		/* Types of parameters (TypeNames) */
	List	   *argtype_oids;	/* Types of parameters (OIDs) */
	Query	   *query;			/* The query itself */
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
} PrepareStmt;


/* ----------------------
 *		EXECUTE Statement
 * ----------------------
 */

typedef struct ExecuteStmt
{
B
Bruce Momjian 已提交
1687 1688 1689 1690
	NodeTag		type;
	char	   *name;			/* The name of the plan to execute */
	RangeVar   *into;			/* Optional table to store results in */
	List	   *params;			/* Values to assign to parameters */
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703
} ExecuteStmt;


/* ----------------------
 *		DEALLOCATE Statement
 * ----------------------
 */
typedef struct DeallocateStmt
{
	NodeTag		type;
	char	   *name;			/* The name of the plan to remove */
} DeallocateStmt;

1704
#endif   /* PARSENODES_H */