parsenodes.h 45.2 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * parsenodes.h
4
 *	  definitions for parse tree nodes
5 6
 *
 *
Bruce Momjian's avatar
Bruce Momjian committed
7
 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
Bruce Momjian's avatar
Add:  
Bruce Momjian committed
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
10
 * $Id: parsenodes.h,v 1.187 2002/07/16 22:12:20 tgl Exp $
11 12 13
 *
 *-------------------------------------------------------------------------
 */
14 15
#ifndef PARSENODES_H
#define PARSENODES_H
16

17
#include "nodes/primnodes.h"
18

19

20
/*****************************************************************************
21
 *	Query Tree
22 23 24 25
 *****************************************************************************/

/*
 * Query -
26 27 28 29
 *	  all statments are turned into a Query tree (via transformStmt)
 *	  for further processing by the optimizer
 *	  utility statements (i.e. non-optimizable statements)
 *	  have the *utilityStmt field set.
30 31 32 33
 *
 * we need the isPortal flag because portal names can be null too; can
 * get rid of it if we support CURSOR as a commandType.
 */
34 35
typedef struct Query
{
36
	NodeTag		type;
37

38
	CmdType		commandType;	/* select|insert|update|delete|utility */
39

40
	Node	   *utilityStmt;	/* non-null if this is a non-optimizable
41 42
								 * statement */

43
	int			resultRelation; /* target relation (index into rtable) */
44
	RangeVar   *into;			/* target relation or portal (cursor) 
45
								 * for portal just name is meaningful */
46 47
	bool		isPortal;		/* is this a retrieve into portal? */
	bool		isBinary;		/* binary portal? */
48

49
	bool		hasAggs;		/* has aggregates in tlist or havingQual */
50
	bool		hasSubLinks;	/* has subquery SubLink */
51

52 53
	bool		originalQuery;	/* marks original query through rewriting */

54
	List	   *rtable;			/* list of range table entries */
55 56
	FromExpr   *jointree;		/* table join tree (FROM and WHERE
								 * clauses) */
57

58 59
	List	   *rowMarks;		/* integer list of RT indexes of relations
								 * that are selected FOR UPDATE */
60

61
	List	   *targetList;		/* target list (of TargetEntry) */
62

63 64 65
	List	   *groupClause;	/* a list of GroupClause's */

	Node	   *havingQual;		/* qualifications applied to groups */
Bruce Momjian's avatar
Hi!  
Bruce Momjian committed
66

67 68 69
	List	   *distinctClause; /* a list of SortClause's */

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

Bruce Momjian's avatar
Bruce Momjian committed
71 72
	Node	   *limitOffset;	/* # of result tuples to skip */
	Node	   *limitCount;		/* # of result tuples to return */
Bruce Momjian's avatar
Bruce Momjian committed
73

74 75 76
	Node	   *setOperations;	/* set-operation tree if this is top level
								 * of a UNION/INTERSECT/EXCEPT query */

77 78 79 80 81 82 83 84
	/*
	 * 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.
	 */
85
	List	   *resultRelations;	/* integer list of RT indexes, or NIL */
86

87
	/* internal to planner */
88
	List	   *base_rel_list;	/* list of base-relation RelOptInfos */
89
	List	   *other_rel_list; /* list of other 1-relation RelOptInfos */
90
	List	   *join_rel_list;	/* list of join-relation RelOptInfos */
91 92
	List	   *equi_key_list;	/* list of lists of equijoined
								 * PathKeyItems */
93
	List	   *query_pathkeys; /* pathkeys for query_planner()'s result */
94
} Query;
95 96


97 98
/****************************************************************************
 *	Supporting data structures for Parse Trees
99
 *
100 101 102 103
 *	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.
 ****************************************************************************/
104

105 106
/*
 * TypeName - specifies a type in definitions
107 108 109 110 111 112 113 114
 *
 * 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
 * the type of that field.  Otherwise (the normal case), names is a type
 * name possibly qualified with schema and database name.
115
 */
116
typedef struct TypeName
117
{
118
	NodeTag		type;
119 120
	List	   *names;			/* qualified name (list of Value strings) */
	Oid			typeid;			/* type identified by OID */
121 122
	bool		timezone;		/* timezone specified? */
	bool		setof;			/* is a set? */
123
	bool		pct_type;		/* %TYPE specified? */
124 125 126
	int32		typmod;			/* type modifier */
	List	   *arrayBounds;	/* array bounds */
} TypeName;
127

128
/*
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
 * 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
145
 */
146
typedef struct ParamRef
147 148
{
	NodeTag		type;
149
	int			number;			/* the number of the parameter */
150 151 152
	List	   *fields;			/* field names (list of Value strings) */
	List	   *indirection;	/* subscripts (list of A_Indices) */
} ParamRef;
153

154 155 156 157
/*
 * A_Expr - binary expressions
 */
typedef struct A_Expr
158
{
159
	NodeTag		type;
160
	int			oper;			/* type of operation (OP,OR,AND,NOT) */
161
	List	   *name;			/* possibly-qualified name of operator */
162 163 164
	Node	   *lexpr;			/* left argument */
	Node	   *rexpr;			/* right argument */
} A_Expr;
165

166 167 168 169
/*
 * A_Const - a constant expression
 */
typedef struct A_Const
170 171
{
	NodeTag		type;
172 173 174
	Value		val;			/* the value (with the tag) */
	TypeName   *typename;		/* typecast */
} A_Const;
175

176 177 178
/*
 * TypeCast - a CAST expression
 *
179
 * NOTE: for mostly historical reasons, A_Const parsenodes contain
180
 * room for a TypeName; we only generate a separate TypeCast node if the
181 182 183
 * 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.
184
 */
185
typedef struct TypeCast
186
{
187
	NodeTag		type;
188 189 190
	Node	   *arg;			/* the expression being casted */
	TypeName   *typename;		/* the target type */
} TypeCast;
191

192 193
/*
 * CaseExpr - a CASE expression
194
 */
195
typedef struct CaseExpr
196
{
197
	NodeTag		type;
198 199 200 201 202
	Oid			casetype;
	Node	   *arg;			/* implicit equality comparison argument */
	List	   *args;			/* the arguments (list of WHEN clauses) */
	Node	   *defresult;		/* the default result (ELSE clause) */
} CaseExpr;
203

204 205
/*
 * CaseWhen - an argument to a CASE expression
206
 */
207
typedef struct CaseWhen
208
{
209
	NodeTag		type;
210 211 212
	Node	   *expr;			/* comparison expression */
	Node	   *result;			/* substitution result */
} CaseWhen;
213

214 215
/* ----------------
 * NullTest
216
 *
217 218 219 220 221
 * NullTest represents the operation of testing a value for NULLness.
 * Currently, we only support scalar input values, but eventually a
 * row-constructor input should be supported.
 * The appropriate test is performed and returned as a boolean Datum.
 * ----------------
222 223
 */

224
typedef enum NullTestType
225
{
226 227
	IS_NULL, IS_NOT_NULL
} NullTestType;
228

229
typedef struct NullTest
230
{
231
	NodeTag		type;
232 233 234
	Node	   *arg;			/* input expression */
	NullTestType nulltesttype;	/* IS NULL, IS NOT NULL */
} NullTest;
Jan Wieck's avatar
Jan Wieck committed
235

236 237 238 239 240 241 242 243
/* ----------------
 * BooleanTest
 *
 * BooleanTest represents the operation of determining whether a boolean
 * is TRUE, FALSE, or UNKNOWN (ie, NULL).  All six meaningful combinations
 * are supported.  Note that a NULL input does *not* cause a NULL result.
 * The appropriate test is performed and returned as a boolean Datum.
 * ----------------
Jan Wieck's avatar
Jan Wieck committed
244 245
 */

246
typedef enum BoolTestType
Jan Wieck's avatar
Jan Wieck committed
247
{
248 249
	IS_TRUE, IS_NOT_TRUE, IS_FALSE, IS_NOT_FALSE, IS_UNKNOWN, IS_NOT_UNKNOWN
} BoolTestType;
250

251
typedef struct BooleanTest
252
{
253
	NodeTag		type;
254 255 256
	Node	   *arg;			/* input expression */
	BoolTestType booltesttype;	/* test type */
} BooleanTest;
257

258 259 260 261 262 263 264 265 266 267 268 269 270 271
/*
 * 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.
272 273 274 275
 *
 * 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.
276 277
 */
typedef struct ColumnDef
278
{
279
	NodeTag		type;
280 281 282 283 284 285 286
	char	   *colname;		/* name of column */
	TypeName   *typename;		/* type of column */
	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 */
287
	RangeVar   *support;		/* supporting relation, if any */
288
} ColumnDef;
289

290 291
/*
 * Ident -
292 293
 *	  an unqualified identifier.  This is currently used only in the context
 *	  of column name lists.
294
 */
295
typedef struct Ident
296 297
{
	NodeTag		type;
298 299
	char	   *name;			/* its name */
} Ident;
300

301 302 303 304 305 306 307 308 309
/*
 * 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
310 311
{
	NodeTag		type;
312
	List	   *funcname;		/* qualified name of function */
313 314 315 316
	List	   *args;			/* the arguments (list of exprs) */
	bool		agg_star;		/* argument was really '*' */
	bool		agg_distinct;	/* arguments were labeled DISTINCT */
} FuncCall;
317

318 319
/*
 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
320
 */
321
typedef struct A_Indices
322
{
323
	NodeTag		type;
324 325 326
	Node	   *lidx;			/* could be NULL */
	Node	   *uidx;
} A_Indices;
327

328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
/*
 * 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;

343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
/*
 * 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
358 359
{
	NodeTag		type;
360 361 362 363 364 365
	char	   *name;			/* column name or NULL */
	List	   *indirection;	/* subscripts for destination column, or
								 * NIL */
	Node	   *val;			/* the value expression to compute or
								 * assign */
} ResTarget;
366

Bruce Momjian's avatar
Bruce Momjian committed
367 368 369 370 371 372 373 374
/*
 * Empty node used as a marker for Default Columns
 */
typedef struct InsertDefault
{
	NodeTag		type;
} InsertDefault;

375 376 377 378
/*
 * SortGroupBy - for ORDER BY clause
 */
typedef struct SortGroupBy
379 380
{
	NodeTag		type;
381
	List	   *useOp;			/* operator to use */
382 383
	Node	   *node;			/* Expression  */
} SortGroupBy;
384

385 386
/*
 * RangeSubselect - subquery appearing in a FROM clause
387
 */
388
typedef struct RangeSubselect
389
{
390
	NodeTag		type;
391
	Node	   *subquery;		/* the untransformed sub-select clause */
392
	Alias	   *alias;			/* table alias & optional column aliases */
393
} RangeSubselect;
394

395 396 397 398 399 400 401 402 403 404
/*
 * 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 */
} RangeFunction;

405 406 407
/*
 * IndexElem - index parameters (used in CREATE INDEX)
 *
408 409 410 411
 * 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
 * is allowed.  It has name = NULL, funcname = name of function and args =
 * list of attribute names that are the function's arguments.
412 413
 */
typedef struct IndexElem
414
{
415
	NodeTag		type;
416 417
	char	   *name;			/* name of attribute to index, or NULL */
	List	   *funcname;		/* qualified name of function */
418
	List	   *args;			/* list of names of function arguments */
419
	List	   *opclass;		/* name of desired opclass; NIL = default */
420
} IndexElem;
421

422 423 424 425 426
/*
 * DefElem -
 *	  a definition (used in definition lists in the form of defname = arg)
 */
typedef struct DefElem
427
{
428
	NodeTag		type;
429 430 431
	char	   *defname;
	Node	   *arg;			/* a (Value *) or a (TypeName *) */
} DefElem;
432

Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
433

434 435 436
/****************************************************************************
 *	Nodes for a Query tree
 ****************************************************************************/
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
437

438 439 440 441 442 443
/*
 * TargetEntry -
 *	   a target  entry (used in the transformed target list)
 *
 * one of resdom or fjoin is not NULL. a target list is
 *		((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
444
 */
445
typedef struct TargetEntry
446
{
447
	NodeTag		type;
448 449 450 451
	Resdom	   *resdom;			/* fjoin overload this to be a list?? */
	Fjoin	   *fjoin;
	Node	   *expr;
} TargetEntry;
452

453 454 455 456
/*--------------------
 * RangeTblEntry -
 *	  A range table is a List of RangeTblEntry nodes.
 *
457 458 459 460 461 462
 *	  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.
463
 *
464
 *	  alias is an Alias node representing the AS alias-clause attached to the
465 466 467 468 469
 *	  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.
470
 *	  eref->aliasname is required to be present, and should generally be used
471 472 473 474
 *	  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
475
 *	  RTEs other than RTE_RELATION entries.
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
 *
 *	  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.)
 *--------------------
494
 */
495 496 497 498 499
typedef enum RTEKind
{
	RTE_RELATION,				/* ordinary relation reference */
	RTE_SUBQUERY,				/* subquery in FROM */
	RTE_JOIN,					/* join */
500 501
	RTE_SPECIAL,				/* special rule relation (NEW or OLD) */
	RTE_FUNCTION				/* function in FROM */
502 503
} RTEKind;

504
typedef struct RangeTblEntry
505
{
506
	NodeTag		type;
507

508 509
	RTEKind		rtekind;		/* see above */

510
	/*
511 512 513 514 515 516
	 * 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
	 * a lot of code that is being actively worked on.  FIXME later.
	 */

	/*
517
	 * Fields valid for a plain relation RTE (else zero):
518 519
	 */
	Oid			relid;			/* OID of the relation */
520

521 522 523 524
	/*
	 * Fields valid for a subquery RTE (else NULL):
	 */
	Query	   *subquery;		/* the sub-query */
525

526 527 528 529 530
	/*
	 * Fields valid for a function RTE (else NULL):
	 */
	Node	   *funcexpr;		/* expression tree for func call */

531
	/*
532
	 * Fields valid for a join RTE (else NULL/zero):
533
	 *
534 535 536 537 538
	 * 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
	 * joinaliasvars --- but to simplify the task of reverse-listing aliases
	 * correctly, we do not do that until planning time.
539 540
	 */
	JoinType	jointype;		/* type of join */
541
	List	   *joinaliasvars;	/* list of alias-var expansions */
542

543 544 545
	/*
	 * Fields valid in all RTEs:
	 */
546 547
	Alias	   *alias;			/* user-written alias clause, if any */
	Alias	   *eref;			/* expanded reference names */
548 549 550 551 552 553
	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;
554

555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
/*
 * 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
571
{
572
	NodeTag		type;
573 574 575
	Index		tleSortGroupRef;	/* reference into targetlist */
	Oid			sortop;			/* the sort operator to use */
} SortClause;
576

577 578 579 580 581 582 583
/*
 * 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.
584
 */
585 586 587 588 589 590
typedef SortClause GroupClause;


/*****************************************************************************
 *		Optimizable Statements
 *****************************************************************************/
591 592

/* ----------------------
593
 *		Insert Statement
594 595
 * ----------------------
 */
596
typedef struct InsertStmt
597
{
598
	NodeTag		type;
599
	RangeVar   *relation;		/* relation to insert into */
600 601 602 603 604 605 606 607 608 609
	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;
610

611
/* ----------------------
612
 *		Delete Statement
613 614
 * ----------------------
 */
615
typedef struct DeleteStmt
616
{
617
	NodeTag		type;
618
	RangeVar   *relation;		/* relation to delete from */
619 620
	Node	   *whereClause;	/* qualifications */
} DeleteStmt;
621 622

/* ----------------------
623
 *		Update Statement
624 625
 * ----------------------
 */
626
typedef struct UpdateStmt
627
{
628
	NodeTag		type;
629
	RangeVar   *relation;		/* relation to update */
630 631
	List	   *targetList;		/* the target list (of ResTarget) */
	Node	   *whereClause;	/* qualifications */
632
	List	   *fromClause;		/* optional from clause for more tables */
633
} UpdateStmt;
634 635

/* ----------------------
636 637 638 639 640 641 642 643 644 645
 *		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.
646 647
 * ----------------------
 */
648 649 650 651 652 653 654 655 656
typedef enum SetOperation
{
	SETOP_NONE = 0,
	SETOP_UNION,
	SETOP_INTERSECT,
	SETOP_EXCEPT
} SetOperation;

typedef struct SelectStmt
657
{
658
	NodeTag		type;
659 660 661 662 663 664 665

	/*
	 * These fields are used only in "leaf" SelectStmts.
	 */
	List	   *distinctClause; /* NULL, list of DISTINCT ON exprs, or
								 * lcons(NIL,NIL) for all (SELECT
								 * DISTINCT) */
666
	RangeVar   *into;			/* target table (for select into table) */
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
	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
	 * SelectStmts.  portalname/binary may only be set at the top level.
	 */
	List	   *sortClause;		/* sort clause (a list of SortGroupBy's) */
	char	   *portalname;		/* the portal (cursor) to create */
	bool		binary;			/* a binary (internal) portal? */
	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;
694 695

/* ----------------------
696 697 698 699 700 701 702
 *		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.
703 704
 * ----------------------
 */
705
typedef struct SetOperationStmt
706
{
707
	NodeTag		type;
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
	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: */
	List	   *colTypes;		/* integer list of OIDs of output column
								 * types */
} 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.
 *****************************************************************************/
728

729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
/* ----------------------
 *		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;

745 746 747 748 749 750
typedef enum DropBehavior
{
	DROP_RESTRICT,				/* drop fails if any dependent objects */
	DROP_CASCADE				/* remove dependent objects too */
} DropBehavior;

751
/* ----------------------
752 753 754 755
 *	Alter Table
 *
 * The fields are used in different ways by the different variants of
 * this command.
756 757
 * ----------------------
 */
758
typedef struct AlterTableStmt
759
{
760
	NodeTag		type;
761 762 763
	char		subtype;		/*------------
								 *	A = add column
								 *	T = alter column default
764 765
								 *	N = alter column drop not null
								 *	O = alter column set not null
766 767 768 769
								 *	S = alter column statistics
								 *  M = alter column storage
								 *	D = drop column
								 *	C = add constraint
770 771
								 *	c = pre-processed add constraint
								 *		(local in parser/analyze.c)
772 773 774 775 776
								 *	X = drop constraint
								 *	E = create toast table
								 *	U = change owner
								 *------------
								 */
777
	RangeVar   *relation;		/* table to work on */
778 779 780
	char	   *name;			/* column or constraint name to act on, or
								 * new owner */
	Node	   *def;			/* definition of new column or constraint */
781
	DropBehavior behavior;		/* RESTRICT or CASCADE for DROP cases */
782
} AlterTableStmt;
783

784
/* ----------------------
785
 *		Grant|Revoke Statement
786 787
 * ----------------------
 */
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
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.
 * The present representation of AclItem limits us to 30 distinct rights.
 * 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 */
#define ACL_CREATE_TEMP	(1<<10)	/* for databases */
#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
816 817

typedef struct GrantStmt
818
{
819
	NodeTag		type;
820 821 822 823
	bool		is_grant;		/* true = GRANT, false = REVOKE */
	GrantObjectType objtype;	/* kind of object being operated on */
	List	   *objects;		/* list of RangeVar nodes, FuncWithArgs nodes,
								 * or plain names (as Value strings) */
824 825 826
	List	   *privileges;		/* integer list of privilege codes */
	List	   *grantees;		/* list of PrivGrantee nodes */
} GrantStmt;
827

828
typedef struct PrivGrantee
829
{
830
	NodeTag		type;
831 832 833
	char	   *username;		/* if both are NULL then PUBLIC */
	char	   *groupname;
} PrivGrantee;
834

835
typedef struct FuncWithArgs
836
{
837
	NodeTag		type;
838
	List	   *funcname;		/* qualified name of function */
839 840
	List	   *funcargs;		/* list of Typename nodes */
} FuncWithArgs;
841

842 843
/* This is only used internally in gram.y. */
typedef struct PrivTarget
844
{
845
	NodeTag		type;
846
	GrantObjectType objtype;
847 848 849
	List	   *objs;
} PrivTarget;

850
/* ----------------------
851
 *		Close Portal Statement
852 853
 * ----------------------
 */
854
typedef struct ClosePortalStmt
855
{
856
	NodeTag		type;
857 858
	char	   *portalname;		/* name of the portal (cursor) */
} ClosePortalStmt;
859 860

/* ----------------------
861
 *		Copy Statement
862 863
 * ----------------------
 */
864
typedef struct CopyStmt
865
{
866
	NodeTag		type;
867
	RangeVar   *relation;		/* the relation to copy */
868
	bool		is_from;		/* TO or FROM */
869
	char	   *filename;		/* if NULL, use stdin/stdout */
870
	List	   *options;		/* List of DefElem nodes */
871
} CopyStmt;
872 873

/* ----------------------
874 875 876 877 878 879 880
 *		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).
881 882
 * ----------------------
 */
883
typedef struct CreateStmt
884 885
{
	NodeTag		type;
886
	RangeVar   *relation;		/* relation to create */
887
	List	   *tableElts;		/* column definitions (list of ColumnDef) */
888
	List	   *inhRelations;	/* relations to inherit from */
889 890 891
	List	   *constraints;	/* constraints (list of Constraint nodes) */
	bool		hasoids;		/* should it have OIDs? */
} CreateStmt;
892

893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
/* ----------
 * 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).
 * ----------
910
 */
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927

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
928
{
929
	NodeTag		type;
930 931 932 933 934 935
	ConstrType	contype;
	char	   *name;			/* name, or NULL if unnamed */
	Node	   *raw_expr;		/* expr, as untransformed parse tree */
	char	   *cooked_expr;	/* expr, as nodeToString representation */
	List	   *keys;			/* Ident nodes naming referenced column(s) */
} Constraint;
936

937 938
/* ----------
 * Definitions for FOREIGN KEY constraints in CreateStmt
939 940 941 942 943 944 945 946 947 948
 *
 * 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
 * for the constraint.  This is currently used only during CREATE TABLE
 * (when we know the table must be empty).
949
 * ----------
950
 */
951 952 953 954 955
#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'
956

957 958 959
#define FKCONSTR_MATCH_FULL			'f'
#define FKCONSTR_MATCH_PARTIAL		'p'
#define FKCONSTR_MATCH_UNSPECIFIED	'u'
960 961

typedef struct FkConstraint
962
{
963
	NodeTag		type;
964
	char	   *constr_name;	/* Constraint name, or NULL if unnamed */
965
	RangeVar   *pktable;		/* Primary key table */
966 967
	List	   *fk_attrs;		/* Attributes of foreign key */
	List	   *pk_attrs;		/* Corresponding attrs in PK table */
968 969 970
	char		fk_matchtype;	/* FULL, PARTIAL, UNSPECIFIED */
	char		fk_upd_action;	/* ON UPDATE action */
	char		fk_del_action;	/* ON DELETE action */
971 972
	bool		deferrable;		/* DEFERRABLE */
	bool		initdeferred;	/* INITIALLY DEFERRED */
973
	bool		skip_validation; /* skip validation of existing rows? */
974
} FkConstraint;
975 976

/* ----------------------
977
 *		Create/Drop TRIGGER Statements
978 979
 * ----------------------
 */
980 981

typedef struct CreateTrigStmt
982
{
983
	NodeTag		type;
984 985 986 987
	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 */
988 989 990 991 992 993 994
	bool		before;			/* BEFORE/AFTER */
	bool		row;			/* ROW/STATEMENT */
	char		actions[4];		/* Insert, Update, Delete */
	char	   *lang;			/* currently not used, always NULL */
	char	   *text;			/* AS 'text' */
	List	   *attr;			/* UPDATE OF a, b,... (NI) or NULL */
	char	   *when;			/* WHEN 'a > 10 ...' (NI) or NULL */
995

996 997 998 999 1000
	/* 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} */
1001
	RangeVar   *constrrel;		/* opposite relation */
1002 1003
} CreateTrigStmt;

1004
/* ----------------------
1005
 *		Create/Drop PROCEDURAL LANGUAGE Statement
1006 1007
 * ----------------------
 */
1008
typedef struct CreatePLangStmt
1009 1010
{
	NodeTag		type;
1011
	char	   *plname;			/* PL name */
1012
	List	   *plhandler;		/* PL call handler function (qual. name) */
1013
	List	   *plvalidator;	/* optional validator function (qual. name) */
1014 1015 1016
	char	   *plcompiler;		/* lancompiler text */
	bool		pltrusted;		/* PL is trusted */
} CreatePLangStmt;
1017

1018
typedef struct DropPLangStmt
1019
{
1020
	NodeTag		type;
1021
	char	   *plname;			/* PL name */
1022
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1023
} DropPLangStmt;
1024 1025

/* ----------------------
1026
 *	Create/Alter/Drop User Statements
1027 1028
 * ----------------------
 */
1029
typedef struct CreateUserStmt
1030
{
1031
	NodeTag		type;
1032 1033 1034
	char	   *user;			/* PostgreSQL user login name */
	List	   *options;		/* List of DefElem nodes */
} CreateUserStmt;
1035

1036
typedef struct AlterUserStmt
1037
{
1038
	NodeTag		type;
1039 1040 1041
	char	   *user;			/* PostgreSQL user login name */
	List	   *options;		/* List of DefElem nodes */
} AlterUserStmt;
1042

1043
typedef struct AlterUserSetStmt
1044
{
1045
	NodeTag		type;
1046 1047 1048 1049
	char	   *user;
	char	   *variable;
	List	   *value;
} AlterUserSetStmt;
1050

1051
typedef struct DropUserStmt
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
1052 1053
{
	NodeTag		type;
1054 1055
	List	   *users;			/* List of users to remove */
} DropUserStmt;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
1056

1057
/* ----------------------
1058
 *		Create/Alter/Drop Group Statements
1059 1060
 * ----------------------
 */
1061
typedef struct CreateGroupStmt
1062
{
1063
	NodeTag		type;
1064 1065 1066
	char	   *name;			/* name of the new group */
	List	   *options;		/* List of DefElem nodes */
} CreateGroupStmt;
1067

1068 1069 1070 1071 1072 1073 1074
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;
1075

1076
typedef struct DropGroupStmt
1077
{
1078 1079
	NodeTag		type;
	char	   *name;
1080
} DropGroupStmt;
1081 1082

/* ----------------------
1083
 *		Create SEQUENCE Statement
1084 1085 1086
 * ----------------------
 */

1087
typedef struct CreateSeqStmt
1088
{
1089
	NodeTag		type;
1090
	RangeVar   *sequence;		/* the sequence to create */
1091 1092
	List	   *options;
} CreateSeqStmt;
1093

1094
/* ----------------------
1095
 *		Create {Operator|Type|Aggregate} Statement
1096 1097
 * ----------------------
 */
1098
typedef struct DefineStmt
1099 1100
{
	NodeTag		type;
Tom Lane's avatar
Tom Lane committed
1101
	int			defType;		/* OPERATOR|TYPE_P|AGGREGATE */
1102
	List	   *defnames;		/* qualified name (list of Value strings) */
1103 1104
	List	   *definition;		/* a list of DefElem */
} DefineStmt;
1105

Tom Lane's avatar
Tom Lane committed
1106 1107 1108 1109 1110 1111 1112
/* ----------------------
 *		Create Domain Statement
 * ----------------------
 */
typedef struct CreateDomainStmt
{
	NodeTag		type;
1113 1114 1115
	List	   *domainname;		/* qualified name (list of Value strings) */
	TypeName   *typename;		/* the base type */
	List	   *constraints;	/* constraints (list of Constraint nodes) */
Tom Lane's avatar
Tom Lane committed
1116 1117
} CreateDomainStmt;

Hiroshi Inoue's avatar
Hiroshi Inoue committed
1118
/* ----------------------
1119
 *		Drop Table|Sequence|View|Index|Type|Domain Statement
Hiroshi Inoue's avatar
Hiroshi Inoue committed
1120 1121 1122
 * ----------------------
 */

1123 1124 1125 1126
#define DROP_TABLE	  1
#define DROP_SEQUENCE 2
#define DROP_VIEW	  3
#define DROP_INDEX	  4
1127 1128
#define DROP_TYPE     5
#define DROP_DOMAIN	  6
1129
#define DROP_CONVERSION	  7
1130

1131 1132 1133
typedef struct DropStmt
{
	NodeTag		type;
1134
	List	   *objects;		/* list of sublists of names (as Values) */
1135 1136
	int			removeType;		/* see #defines above */
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1137
} DropStmt;
1138

1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
/* ----------------------
 *		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 */
1155 1156
	int			removeType;		/* see #defines above */
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1157 1158
} DropPropertyStmt;

1159
/* ----------------------
1160
 *				Truncate Table Statement
1161 1162
 * ----------------------
 */
1163
typedef struct TruncateStmt
1164
{
1165
	NodeTag		type;
1166
	RangeVar   *relation;		/* relation to be truncated */
1167
} TruncateStmt;
1168 1169

/* ----------------------
1170
 *				Comment On Statement
1171 1172
 * ----------------------
 */
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
#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

1188
typedef struct CommentStmt
1189
{
1190
	NodeTag		type;
1191
	int			objtype;		/* Object's type, see codes above */
1192 1193 1194
	List	   *objname;		/* Qualified name of the object */
	List	   *objargs;		/* Arguments if needed (eg, for functions) */
	char	   *comment;		/* Comment to insert, or NULL to remove */
1195
} CommentStmt;
1196 1197

/* ----------------------
1198
 *		Begin Recipe Statement
1199 1200
 * ----------------------
 */
1201
typedef struct RecipeStmt
1202
{
1203
	NodeTag		type;
1204 1205
	char	   *recipeName;		/* name of the recipe */
} RecipeStmt;
1206 1207

/* ----------------------
1208
 *		Fetch Statement
1209 1210
 * ----------------------
 */
1211
typedef struct FetchStmt
1212
{
1213
	NodeTag		type;
1214 1215 1216 1217 1218
	int			direction;		/* FORWARD or BACKWARD */
	int			howMany;		/* amount to fetch ("ALL" --> 0) */
	char	   *portalname;		/* name of portal (cursor) */
	bool		ismove;			/* TRUE if MOVE */
} FetchStmt;
1219

1220
/* ----------------------
1221
 *		Create Index Statement
1222 1223
 * ----------------------
 */
1224
typedef struct IndexStmt
1225 1226
{
	NodeTag		type;
1227
	char	   *idxname;		/* name of the index */
1228
	RangeVar   *relation;		/* relation to build index on */
1229 1230 1231 1232 1233 1234 1235
	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? */
1236
	bool		isconstraint;	/* is it from a CONSTRAINT clause? */
1237
} IndexStmt;
1238

1239 1240 1241
/* ----------------------
 *		Create Function Statement
 * ----------------------
1242
 */
1243
typedef struct CreateFunctionStmt
1244
{
1245
	NodeTag		type;
1246
	bool		replace;		/* T => replace if already exists */
1247
	List	   *funcname;		/* qualified name of function to create */
1248
	List	   *argTypes;		/* list of argument types (TypeName nodes) */
1249
	TypeName   *returnType;		/* the return type */
1250
	List	   *options;		/* a list of DefElem */
1251
	List	   *withClause;		/* a list of DefElem */
1252
} CreateFunctionStmt;
1253

1254 1255 1256
/* ----------------------
 *		Drop Aggregate Statement
 * ----------------------
1257
 */
1258
typedef struct RemoveAggrStmt
1259
{
1260
	NodeTag		type;
1261
	List	   *aggname;		/* aggregate to drop */
1262
	TypeName   *aggtype;		/* TypeName for input datatype, or NULL */
1263
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1264
} RemoveAggrStmt;
1265

1266 1267 1268
/* ----------------------
 *		Drop Function Statement
 * ----------------------
1269
 */
1270
typedef struct RemoveFuncStmt
1271
{
1272
	NodeTag		type;
1273
	List	   *funcname;		/* function to drop */
1274
	List	   *args;			/* types of the arguments */
1275
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1276
} RemoveFuncStmt;
1277

1278 1279 1280
/* ----------------------
 *		Drop Operator Statement
 * ----------------------
1281
 */
1282
typedef struct RemoveOperStmt
1283
{
1284
	NodeTag		type;
1285
	List	   *opname;			/* operator to drop */
1286
	List	   *args;			/* types of the arguments */
1287
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1288
} RemoveOperStmt;
1289

1290
/* ----------------------
1291
 *		Alter Object Rename Statement
1292
 * ----------------------
1293 1294
 * Currently supports renaming tables, table columns, and triggers.
 * If renaming a table, oldname is ignored.
1295
 */
1296 1297 1298 1299 1300
#define RENAME_TABLE	110
#define RENAME_COLUMN	111
#define RENAME_TRIGGER	112
#define RENAME_RULE		113

1301
typedef struct RenameStmt
1302
{
1303
	NodeTag		type;
1304 1305
	RangeVar   *relation;		/* owning relation */
	char	   *oldname;		/* name of rule, trigger, etc */
1306
	char	   *newname;		/* the new name */
1307
	int			renameType;		/* RENAME_TABLE, RENAME_COLUMN, etc */
1308
} RenameStmt;
1309

1310 1311 1312
/* ----------------------
 *		Create Rule Statement
 * ----------------------
1313
 */
1314
typedef struct RuleStmt
1315 1316
{
	NodeTag		type;
1317
	RangeVar   *relation;		/* relation the rule is for */
1318 1319
	char	   *rulename;		/* name of the rule */
	Node	   *whereClause;	/* qualifications */
1320
	CmdType		event;			/* SELECT, INSERT, etc */
1321 1322 1323
	bool		instead;		/* is a 'do instead'? */
	List	   *actions;		/* the action statements */
} RuleStmt;
1324

1325 1326 1327
/* ----------------------
 *		Notify Statement
 * ----------------------
1328
 */
1329
typedef struct NotifyStmt
1330 1331
{
	NodeTag		type;
1332
	RangeVar   *relation;		/* qualified name to notify */
1333
} NotifyStmt;
1334

1335 1336 1337
/* ----------------------
 *		Listen Statement
 * ----------------------
1338
 */
1339
typedef struct ListenStmt
1340 1341
{
	NodeTag		type;
1342
	RangeVar   *relation;		/* qualified name to listen on */
1343
} ListenStmt;
1344

1345 1346 1347
/* ----------------------
 *		Unlisten Statement
 * ----------------------
1348
 */
1349
typedef struct UnlistenStmt
1350
{
1351
	NodeTag		type;
1352
	RangeVar   *relation;		/* qualified name to unlisten on, or '*' */
1353
} UnlistenStmt;
1354

1355 1356 1357 1358 1359
/* ----------------------
 *		{Begin|Abort|End} Transaction Statement
 * ----------------------
 */
typedef struct TransactionStmt
1360
{
1361
	NodeTag		type;
1362 1363
	int			command;		/* BEGIN|END|ABORT */
} TransactionStmt;
1364

1365 1366 1367
/* ----------------------
 *		Create View Statement
 * ----------------------
1368
 */
1369
typedef struct ViewStmt
1370
{
1371
	NodeTag		type;
1372
	RangeVar   *view;			/* the view to be created */
1373 1374 1375
	List	   *aliases;		/* target column names */
	Query	   *query;			/* the SQL statement */
} ViewStmt;
1376

1377 1378 1379 1380 1381
/* ----------------------
 *		Load Statement
 * ----------------------
 */
typedef struct LoadStmt
1382
{
1383
	NodeTag		type;
1384 1385
	char	   *filename;		/* file to load */
} LoadStmt;
1386

1387 1388 1389
/* ----------------------
 *		Createdb Statement
 * ----------------------
1390
 */
1391
typedef struct CreatedbStmt
1392
{
1393
	NodeTag		type;
1394
	char	   *dbname;			/* name of database to create */
1395
	List	   *options;		/* List of DefElem nodes */
1396
} CreatedbStmt;
1397

1398 1399 1400
/* ----------------------
 *	Alter Database
 * ----------------------
1401
 */
1402
typedef struct AlterDatabaseSetStmt
1403
{
1404
	NodeTag		type;
1405 1406 1407 1408
	char	   *dbname;
	char	   *variable;
	List	   *value;
} AlterDatabaseSetStmt;
1409

1410 1411 1412
/* ----------------------
 *		Dropdb Statement
 * ----------------------
1413
 */
1414
typedef struct DropdbStmt
1415
{
1416
	NodeTag		type;
1417 1418
	char	   *dbname;			/* database to drop */
} DropdbStmt;
1419

1420 1421 1422
/* ----------------------
 *		Cluster Statement (support pbrown's cluster index implementation)
 * ----------------------
1423
 */
1424
typedef struct ClusterStmt
1425
{
1426
	NodeTag		type;
1427
	RangeVar   *relation;		/* relation being indexed */
1428 1429
	char	   *indexname;		/* original index defined */
} ClusterStmt;
1430

1431 1432
/* ----------------------
 *		Vacuum and Analyze Statements
1433
 *
1434 1435 1436
 * Even though these are nominally two statements, it's convenient to use
 * just one node type for both.
 * ----------------------
1437
 */
1438
typedef struct VacuumStmt
1439
{
1440
	NodeTag		type;
1441 1442 1443 1444 1445
	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 */
1446
	RangeVar   *relation;		/* single table to process, or NULL */
1447 1448
	List	   *va_cols;		/* list of column names, or NIL for all */
} VacuumStmt;
1449

1450 1451 1452
/* ----------------------
 *		Explain Statement
 * ----------------------
1453
 */
1454
typedef struct ExplainStmt
1455 1456
{
	NodeTag		type;
1457 1458 1459 1460
	Query	   *query;			/* the query */
	bool		verbose;		/* print plan info */
	bool		analyze;		/* get statistics by executing plan */
} ExplainStmt;
1461

1462 1463 1464
/* ----------------------
 * Checkpoint Statement
 * ----------------------
1465
 */
1466
typedef struct CheckPointStmt
1467
{
1468
	NodeTag		type;
1469
} CheckPointStmt;
1470

1471 1472 1473
/* ----------------------
 * Set Statement
 * ----------------------
1474
 */
1475 1476

typedef struct VariableSetStmt
1477 1478
{
	NodeTag		type;
1479 1480
	char	   *name;
	List	   *args;
1481
	bool		is_local;		/* SET LOCAL */
1482
} VariableSetStmt;
1483

1484 1485 1486
/* ----------------------
 * Show Statement
 * ----------------------
1487
 */
1488 1489

typedef struct VariableShowStmt
1490
{
1491
	NodeTag		type;
1492 1493
	char	   *name;
} VariableShowStmt;
1494

1495 1496 1497
/* ----------------------
 * Reset Statement
 * ----------------------
1498
 */
1499 1500

typedef struct VariableResetStmt
1501
{
1502
	NodeTag		type;
1503 1504
	char	   *name;
} VariableResetStmt;
1505

1506 1507 1508
/* ----------------------
 *		LOCK Statement
 * ----------------------
1509
 */
1510
typedef struct LockStmt
1511
{
1512
	NodeTag		type;
1513
	List	   *relations;		/* relations to lock */
1514 1515
	int			mode;			/* lock mode */
} LockStmt;
1516

1517 1518 1519
/* ----------------------
 *		SET CONSTRAINTS Statement
 * ----------------------
1520
 */
1521
typedef struct ConstraintsSetStmt
1522
{
1523
	NodeTag		type;
1524 1525 1526
	List	   *constraints;	/* List of names as Value strings */
	bool		deferred;
} ConstraintsSetStmt;
1527

1528 1529 1530
/* ----------------------
 *		REINDEX Statement
 * ----------------------
1531
 */
1532
typedef struct ReindexStmt
1533
{
1534
	NodeTag		type;
1535
	int			reindexType;	/* INDEX|TABLE|DATABASE */
1536 1537
	RangeVar   *relation;		/* Table or index to reindex */
	const char *name;			/* name of database to reindex */
1538 1539 1540
	bool		force;
	bool		all;
} ReindexStmt;
1541

1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
/* ----------------------
 *		CREATE CONVERSION Statement
 * ----------------------
 */
typedef struct CreateConversionStmt
{
	NodeTag		type;
	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? */
} CreateConversionStmt;

1556
#endif   /* PARSENODES_H */