parsenodes.h 53.5 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * parsenodes.h
4
 *	  definitions for parse tree nodes
5 6
 *
 *
7
 * Portions Copyright (c) 1996-2005, 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
 * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.272 2005/01/27 03:18:42 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
/* 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 */
28
} QuerySource;
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/*
 * Grantable rights are encoded so that we can OR them together in a bitmask.
 * The present representation of AclItem limits us to 15 distinct rights,
 * even though AclMode is defined as uint32.  See utils/acl.h.
 *
 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
 */
typedef uint32 AclMode;			/* a bitmask of privilege bits */

#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
/* Currently, SELECT ... FOR UPDATE requires UPDATE privileges */
#define ACL_SELECT_FOR_UPDATE	ACL_UPDATE

56

57
/*****************************************************************************
58
 *	Query Tree
59 60 61 62
 *****************************************************************************/

/*
 * Query -
63
 *	  all statements are turned into a Query tree (via transformStmt)
64 65 66
 *	  for further processing by the optimizer
 *	  utility statements (i.e. non-optimizable statements)
 *	  have the *utilityStmt field set.
67
 */
68 69
typedef struct Query
{
70
	NodeTag		type;
71

72
	CmdType		commandType;	/* select|insert|update|delete|utility */
73

Bruce Momjian's avatar
Bruce Momjian committed
74
	QuerySource querySource;	/* where did I come from? */
75

76 77
	bool		canSetTag;		/* do I set the command result tag? */

78
	Node	   *utilityStmt;	/* non-null if this is a non-optimizable
79 80
								 * statement */

81
	int			resultRelation; /* target relation (index into rtable) */
82 83

	RangeVar   *into;			/* target relation for SELECT INTO */
84
	bool		intoHasOids;	/* should target relation contain OIDs? */
85

86
	bool		hasAggs;		/* has aggregates in tlist or havingQual */
87
	bool		hasSubLinks;	/* has subquery SubLink */
88

89
	List	   *rtable;			/* list of range table entries */
90 91
	FromExpr   *jointree;		/* table join tree (FROM and WHERE
								 * clauses) */
92

93 94
	List	   *rowMarks;		/* integer list of RT indexes of relations
								 * that are selected FOR UPDATE */
95

96
	List	   *targetList;		/* target list (of TargetEntry) */
97

98 99 100
	List	   *groupClause;	/* a list of GroupClause's */

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

102 103 104
	List	   *distinctClause; /* a list of SortClause's */

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

Bruce Momjian's avatar
Bruce Momjian committed
106 107
	Node	   *limitOffset;	/* # of result tuples to skip */
	Node	   *limitCount;		/* # of result tuples to return */
Bruce Momjian's avatar
Bruce Momjian committed
108

109 110 111
	Node	   *setOperations;	/* set-operation tree if this is top level
								 * of a UNION/INTERSECT/EXCEPT query */

112 113 114 115 116 117 118 119
	/*
	 * 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.
	 */
120
	List	   *resultRelations;	/* integer list of RT indexes, or NIL */
121

122
	/* internal to planner */
123
	List	   *base_rel_list;	/* list of base-relation RelOptInfos */
124
	List	   *other_rel_list; /* list of other 1-relation RelOptInfos */
125
	List	   *join_rel_list;	/* list of join-relation RelOptInfos */
126 127
	List	   *equi_key_list;	/* list of lists of equijoined
								 * PathKeyItems */
128
	List	   *in_info_list;	/* list of InClauseInfos */
129
	List	   *query_pathkeys; /* desired pathkeys for query_planner() */
130
	bool		hasJoinRTEs;	/* true if any RTEs are RTE_JOIN kind */
131
} Query;
132 133


134 135
/****************************************************************************
 *	Supporting data structures for Parse Trees
136
 *
137 138 139 140
 *	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.
 ****************************************************************************/
141

142 143
/*
 * TypeName - specifies a type in definitions
144 145 146 147 148 149
 *
 * 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
Bruce Momjian's avatar
Bruce Momjian committed
150
 * the type of that field.	Otherwise (the normal case), names is a type
151
 * name possibly qualified with schema and database name.
152
 */
153
typedef struct TypeName
154
{
155
	NodeTag		type;
156 157
	List	   *names;			/* qualified name (list of Value strings) */
	Oid			typeid;			/* type identified by OID */
158 159
	bool		timezone;		/* timezone specified? */
	bool		setof;			/* is a set? */
160
	bool		pct_type;		/* %TYPE specified? */
161 162 163
	int32		typmod;			/* type modifier */
	List	   *arrayBounds;	/* array bounds */
} TypeName;
164

165
/*
166 167 168
 * ColumnRef - specifies a reference to a column, or possibly a whole tuple
 *
 *		The "fields" list must be nonempty; its last component may be "*"
169 170 171 172 173 174
 *		instead of a regular field name.
 *
 * Note: any array subscripting or selection of fields from composite columns
 * is represented by an A_Indirection node above the ColumnRef.  However,
 * for simplicity in the normal case, initial field selection from a table
 * name is represented within ColumnRef and not by adding A_Indirection.
175 176 177 178 179 180 181 182
 */
typedef struct ColumnRef
{
	NodeTag		type;
	List	   *fields;			/* field names (list of Value strings) */
} ColumnRef;

/*
183
 * ParamRef - specifies a $n parameter reference
184
 */
185
typedef struct ParamRef
186 187
{
	NodeTag		type;
188
	int			number;			/* the number of the parameter */
189
} ParamRef;
190

191
/*
192
 * A_Expr - infix, prefix, and postfix expressions
193
 */
194 195 196 197 198 199
typedef enum A_Expr_Kind
{
	AEXPR_OP,					/* normal operator */
	AEXPR_AND,					/* booleans - name field is unused */
	AEXPR_OR,
	AEXPR_NOT,
200 201
	AEXPR_OP_ANY,				/* scalar op ANY (array) */
	AEXPR_OP_ALL,				/* scalar op ALL (array) */
202
	AEXPR_DISTINCT,				/* IS DISTINCT FROM - name must be "=" */
203
	AEXPR_NULLIF,				/* NULLIF - name must be "=" */
204
	AEXPR_OF					/* IS (not) OF - name must be "=" or "!=" */
205
} A_Expr_Kind;
206

207
typedef struct A_Expr
208
{
209
	NodeTag		type;
Bruce Momjian's avatar
Bruce Momjian committed
210
	A_Expr_Kind kind;			/* see above */
211
	List	   *name;			/* possibly-qualified name of operator */
212 213
	Node	   *lexpr;			/* left argument, or NULL if none */
	Node	   *rexpr;			/* right argument, or NULL if none */
214
} A_Expr;
215

216 217 218 219
/*
 * A_Const - a constant expression
 */
typedef struct A_Const
220 221
{
	NodeTag		type;
222 223 224
	Value		val;			/* the value (with the tag) */
	TypeName   *typename;		/* typecast */
} A_Const;
225

226 227 228
/*
 * TypeCast - a CAST expression
 *
229
 * NOTE: for mostly historical reasons, A_Const parsenodes contain
230
 * room for a TypeName; we only generate a separate TypeCast node if the
231 232 233
 * 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.
234
 */
235
typedef struct TypeCast
236
{
237
	NodeTag		type;
238 239 240
	Node	   *arg;			/* the expression being casted */
	TypeName   *typename;		/* the target type */
} TypeCast;
241

242 243 244 245 246 247 248 249 250
/*
 * 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
251 252
{
	NodeTag		type;
253
	List	   *funcname;		/* qualified name of function */
254 255 256 257
	List	   *args;			/* the arguments (list of exprs) */
	bool		agg_star;		/* argument was really '*' */
	bool		agg_distinct;	/* arguments were labeled DISTINCT */
} FuncCall;
258

259 260
/*
 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
261
 */
262
typedef struct A_Indices
263
{
264
	NodeTag		type;
265 266 267
	Node	   *lidx;			/* could be NULL */
	Node	   *uidx;
} A_Indices;
268

269
/*
270
 * A_Indirection - select a field and/or array element from an expression
271
 *
272 273 274 275 276 277 278 279
 * The indirection list can contain both A_Indices nodes (representing
 * subscripting) and string Value nodes (representing field selection
 * --- the string value is the name of the field to select).  For example,
 * a complex selection operation like
 *				(foo).field1[42][7].field2
 * would be represented with a single A_Indirection node having a 4-element
 * indirection list.
 *
280
 * Note: as of Postgres 8.0, we don't support arrays of composite values,
281
 * so cases in which a field select follows a subscript aren't actually
Bruce Momjian's avatar
Bruce Momjian committed
282
 * semantically legal.	However the parser is prepared to handle such.
283
 */
284
typedef struct A_Indirection
285 286 287
{
	NodeTag		type;
	Node	   *arg;			/* the thing being selected from */
288 289
	List	   *indirection;	/* subscripts and/or field names */
} A_Indirection;
290

291 292
/*
 * ResTarget -
293
 *	  result target (used in target list of pre-transformed parse trees)
294
 *
295 296 297
 * In a SELECT or INSERT target list, 'name' is the column label from an
 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
 * value expression itself.  The 'indirection' field is not used.
298
 *
299 300
 * INSERT has a second ResTarget list which is the target-column-names list.
 * Here, 'val' is not used, 'name' is the name of the destination column,
301
 * and 'indirection' stores any subscripts attached to the destination.
302 303 304 305 306 307
 *
 * In an UPDATE target list, 'name' is the name of the destination column,
 * 'indirection' stores any subscripts attached to the destination, and
 * 'val' is the expression to assign.
 *
 * See A_Indirection for more info about what can appear in 'indirection'.
308 309
 */
typedef struct ResTarget
310 311
{
	NodeTag		type;
312
	char	   *name;			/* column name or NULL */
313
	List	   *indirection;	/* subscripts and field names, or NIL */
314 315 316
	Node	   *val;			/* the value expression to compute or
								 * assign */
} ResTarget;
317

318
/*
319
 * SortBy - for ORDER BY clause
320
 */
321 322 323 324 325
#define SORTBY_ASC		1
#define SORTBY_DESC		2
#define SORTBY_USING	3

typedef struct SortBy
326 327
{
	NodeTag		type;
328 329 330 331
	int			sortby_kind;	/* see codes above */
	List	   *useOp;			/* name of op to use, if SORTBY_USING */
	Node	   *node;			/* expression to sort on */
} SortBy;
332

333 334
/*
 * RangeSubselect - subquery appearing in a FROM clause
335
 */
336
typedef struct RangeSubselect
337
{
338
	NodeTag		type;
339
	Node	   *subquery;		/* the untransformed sub-select clause */
340
	Alias	   *alias;			/* table alias & optional column aliases */
341
} RangeSubselect;
342

343 344 345 346 347 348 349 350
/*
 * 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 */
351 352
	List	   *coldeflist;		/* list of ColumnDef nodes for runtime
								 * assignment of RECORD TupleDesc */
353 354
} RangeFunction;

355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
/*
 * 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;

Bruce Momjian's avatar
Bruce Momjian committed
389 390 391 392 393 394 395 396
/*
 * inhRelation - Relations a CREATE TABLE is to inherit attributes of
 */
typedef struct InhRelation
{
	NodeTag		type;
	RangeVar   *relation;
	bool		including_defaults;
397
} InhRelation;
Bruce Momjian's avatar
Bruce Momjian committed
398

399 400 401
/*
 * IndexElem - index parameters (used in CREATE INDEX)
 *
402 403 404
 * For a plain index attribute, 'name' is the name of the table column to
 * index, and 'expr' is NULL.  For an index expression, 'name' is NULL and
 * 'expr' is the expression tree.
405 406
 */
typedef struct IndexElem
407
{
408
	NodeTag		type;
409
	char	   *name;			/* name of attribute to index, or NULL */
410
	Node	   *expr;			/* expression to index, or NULL */
411
	List	   *opclass;		/* name of desired opclass; NIL = default */
412
} IndexElem;
413

414 415 416 417 418
/*
 * DefElem -
 *	  a definition (used in definition lists in the form of defname = arg)
 */
typedef struct DefElem
419
{
420
	NodeTag		type;
421 422 423
	char	   *defname;
	Node	   *arg;			/* a (Value *) or a (TypeName *) */
} DefElem;
424

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

426 427 428
/****************************************************************************
 *	Nodes for a Query tree
 ****************************************************************************/
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
429

430 431 432 433
/*--------------------
 * RangeTblEntry -
 *	  A range table is a List of RangeTblEntry nodes.
 *
434 435 436 437 438 439
 *	  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.
440
 *
441
 *	  alias is an Alias node representing the AS alias-clause attached to the
442 443 444 445 446
 *	  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.
447
 *	  eref->aliasname is required to be present, and should generally be used
448 449
 *	  to identify the RTE for error messages etc.
 *
450 451
 *	  In RELATION RTEs, the colnames in both alias and eref are indexed by
 *	  physical attribute number; this means there must be colname entries for
Bruce Momjian's avatar
Bruce Momjian committed
452 453
 *	  dropped columns.	When building an RTE we insert empty strings ("") for
 *	  dropped columns.	Note however that a stored rule may have nonempty
454 455 456 457 458 459 460
 *	  colnames for columns dropped since the rule was created (and for that
 *	  matter the colnames might be out of date due to column renamings).
 *	  The same comments apply to FUNCTION RTEs when the function's return type
 *	  is a named composite type.
 *
 *	  In JOIN RTEs, the colnames in both alias and eref are one-to-one with
 *	  joinaliasvars entries.  A JOIN RTE will omit columns of its inputs when
Bruce Momjian's avatar
Bruce Momjian committed
461
 *	  those columns are known to be dropped at parse time.	Again, however,
462
 *	  a stored rule might contain entries for columns dropped since the rule
Bruce Momjian's avatar
Bruce Momjian committed
463
 *	  was created.	(This is only possible for columns not actually referenced
464 465
 *	  in the rule.)
 *
466 467
 *	  inh is TRUE for relation references that should be expanded to include
 *	  inheritance children, if the rel has any.  This *must* be FALSE for
468
 *	  RTEs other than RTE_RELATION entries.
469 470 471 472 473 474 475 476 477 478 479
 *
 *	  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 '*'.
 *
480
 *	  requiredPerms and checkAsUser specify run-time access permissions
Bruce Momjian's avatar
Bruce Momjian committed
481
 *	  checks to be performed at query startup.	The user must have *all*
482 483 484 485 486
 *	  of the permissions that are OR'd together in requiredPerms (zero
 *	  indicates no permissions checking).  If checkAsUser is not zero,
 *	  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.)
487
 *--------------------
488
 */
489 490 491 492 493
typedef enum RTEKind
{
	RTE_RELATION,				/* ordinary relation reference */
	RTE_SUBQUERY,				/* subquery in FROM */
	RTE_JOIN,					/* join */
494 495
	RTE_SPECIAL,				/* special rule relation (NEW or OLD) */
	RTE_FUNCTION				/* function in FROM */
496 497
} RTEKind;

498
typedef struct RangeTblEntry
499
{
500
	NodeTag		type;
501

502 503
	RTEKind		rtekind;		/* see above */

504
	/*
505 506
	 * 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
Bruce Momjian's avatar
Bruce Momjian committed
507
	 * a lot of code that is being actively worked on.	FIXME later.
508 509 510
	 */

	/*
511
	 * Fields valid for a plain relation RTE (else zero):
512 513
	 */
	Oid			relid;			/* OID of the relation */
514

515 516 517 518
	/*
	 * Fields valid for a subquery RTE (else NULL):
	 */
	Query	   *subquery;		/* the sub-query */
519

520 521 522 523
	/*
	 * Fields valid for a function RTE (else NULL):
	 */
	Node	   *funcexpr;		/* expression tree for func call */
524 525
	List	   *coldeflist;		/* list of ColumnDef nodes for runtime
								 * assignment of RECORD TupleDesc */
526

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

539 540 541
	/*
	 * Fields valid in all RTEs:
	 */
542 543
	Alias	   *alias;			/* user-written alias clause, if any */
	Alias	   *eref;			/* expanded reference names */
544 545
	bool		inh;			/* inheritance requested? */
	bool		inFromCl;		/* present in FROM clause */
546 547
	AclMode		requiredPerms;	/* bitmask of required access permissions */
	AclId		checkAsUser;	/* if not zero, check access as this user */
548
} RangeTblEntry;
549

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

572 573 574 575 576 577 578
/*
 * 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.
579
 */
580 581 582 583 584 585
typedef SortClause GroupClause;


/*****************************************************************************
 *		Optimizable Statements
 *****************************************************************************/
586 587

/* ----------------------
588
 *		Insert Statement
589 590
 * ----------------------
 */
591
typedef struct InsertStmt
592
{
593
	NodeTag		type;
594
	RangeVar   *relation;		/* relation to insert into */
595 596 597 598 599 600 601 602 603 604
	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;
605

606
/* ----------------------
607
 *		Delete Statement
608 609
 * ----------------------
 */
610
typedef struct DeleteStmt
611
{
612
	NodeTag		type;
613
	RangeVar   *relation;		/* relation to delete from */
614 615
	Node	   *whereClause;	/* qualifications */
} DeleteStmt;
616 617

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

/* ----------------------
631 632 633 634 635 636 637 638 639 640
 *		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.
641 642
 * ----------------------
 */
643 644 645 646 647 648 649 650
typedef enum SetOperation
{
	SETOP_NONE = 0,
	SETOP_UNION,
	SETOP_INTERSECT,
	SETOP_EXCEPT
} SetOperation;

651 652 653 654 655 656
typedef enum ContainsOids
{
	MUST_HAVE_OIDS,				/* WITH OIDS explicitely specified */
	MUST_NOT_HAVE_OIDS,			/* WITHOUT OIDS explicitely specified */
	DEFAULT_OIDS				/* neither specified; use the default,
								 * which is the value of the
Bruce Momjian's avatar
Bruce Momjian committed
657
								 * default_with_oids GUC var */
658 659
} ContainsOids;

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

	/*
	 * These fields are used only in "leaf" SelectStmts.
666
	 *
Bruce Momjian's avatar
Bruce Momjian committed
667 668
	 * into, intoColNames and intoHasOids are a kluge; they belong somewhere
	 * else...
669 670 671 672
	 */
	List	   *distinctClause; /* NULL, list of DISTINCT ON exprs, or
								 * lcons(NIL,NIL) for all (SELECT
								 * DISTINCT) */
673
	RangeVar   *into;			/* target table (for select into table) */
674
	List	   *intoColNames;	/* column names for into table */
675
	ContainsOids intoHasOids;	/* should target table have OIDs? */
676 677 678 679 680 681 682 683
	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
684
	 * SelectStmts.
685
	 */
686
	List	   *sortClause;		/* sort clause (a list of SortBy's) */
687 688 689 690 691 692 693 694 695 696 697 698 699
	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;
700 701

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

734 735 736 737 738 739
/*
 * When a command can act on several kinds of objects with only one
 * parse structure required, use these constants to designate the
 * object type.
 */

Bruce Momjian's avatar
Bruce Momjian committed
740 741
typedef enum ObjectType
{
742 743 744 745 746 747 748 749 750 751 752
	OBJECT_AGGREGATE,
	OBJECT_CAST,
	OBJECT_COLUMN,
	OBJECT_CONSTRAINT,
	OBJECT_CONVERSION,
	OBJECT_DATABASE,
	OBJECT_DOMAIN,
	OBJECT_FUNCTION,
	OBJECT_GROUP,
	OBJECT_INDEX,
	OBJECT_LANGUAGE,
753
	OBJECT_LARGEOBJECT,
754 755 756 757 758 759
	OBJECT_OPCLASS,
	OBJECT_OPERATOR,
	OBJECT_RULE,
	OBJECT_SCHEMA,
	OBJECT_SEQUENCE,
	OBJECT_TABLE,
760
	OBJECT_TABLESPACE,
761 762 763 764
	OBJECT_TRIGGER,
	OBJECT_TYPE,
	OBJECT_USER,
	OBJECT_VIEW
765
} ObjectType;
766

767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
/* ----------------------
 *		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;

783 784 785 786 787 788
typedef enum DropBehavior
{
	DROP_RESTRICT,				/* drop fails if any dependent objects */
	DROP_CASCADE				/* remove dependent objects too */
} DropBehavior;

789
/* ----------------------
790
 *	Alter Table
791 792
 * ----------------------
 */
793
typedef struct AlterTableStmt
794
{
795
	NodeTag		type;
796
	RangeVar   *relation;		/* table to work on */
797
	List	   *cmds;			/* list of subcommands */
798
	ObjectType	relkind;		/* type of object */
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
} AlterTableStmt;

typedef enum AlterTableType
{
	AT_AddColumn,				/* add column */
	AT_ColumnDefault,			/* alter column default */
	AT_DropNotNull,				/* alter column drop not null */
	AT_SetNotNull,				/* alter column set not null */
	AT_SetStatistics,			/* alter column statistics */
	AT_SetStorage,				/* alter column storage */
	AT_DropColumn,				/* drop column */
	AT_DropColumnRecurse,		/* internal to commands/tablecmds.c */
	AT_AddIndex,				/* add index */
	AT_ReAddIndex,				/* internal to commands/tablecmds.c */
	AT_AddConstraint,			/* add constraint */
Bruce Momjian's avatar
Bruce Momjian committed
814 815
	AT_ProcessedConstraint,		/* pre-processed add constraint (local in
								 * parser/analyze.c) */
816 817 818 819 820 821 822
	AT_DropConstraint,			/* drop constraint */
	AT_DropConstraintQuietly,	/* drop constraint, no error/warning
								 * (local in commands/tablecmds.c) */
	AT_AlterColumnType,			/* alter column type */
	AT_ToastTable,				/* create toast table */
	AT_ChangeOwner,				/* change owner */
	AT_ClusterOn,				/* CLUSTER ON */
823
	AT_DropCluster,				/* SET WITHOUT CLUSTER */
824 825
	AT_DropOids,				/* SET WITHOUT OIDS */
	AT_SetTableSpace			/* SET TABLESPACE */
826 827 828 829 830 831
} AlterTableType;

typedef struct AlterTableCmd	/* one subcommand of an ALTER TABLE */
{
	NodeTag		type;
	AlterTableType subtype;		/* Type of table alteration to apply */
832
	char	   *name;			/* column or constraint name to act on, or
833
								 * new owner or tablespace */
834 835 836
	Node	   *def;			/* definition of new column, column type,
								 * index, or constraint */
	Node	   *transform;		/* transformation expr for ALTER TYPE */
837
	DropBehavior behavior;		/* RESTRICT or CASCADE for DROP cases */
838 839
} AlterTableCmd;

840

841 842 843 844
/* ----------------------
 *	Alter Domain
 *
 * The fields are used in different ways by the different variants of
845
 * this command.
846 847 848 849 850 851 852 853 854 855 856 857 858
 * ----------------------
 */
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
								 *------------
								 */
859
	List	   *typename;		/* domain to work on */
860
	char	   *name;			/* column or constraint name to act on */
861 862
	Node	   *def;			/* definition of default or constraint */
	DropBehavior behavior;		/* RESTRICT or CASCADE for DROP cases */
863
} AlterDomainStmt;
864 865


866
/* ----------------------
867
 *		Grant|Revoke Statement
868 869
 * ----------------------
 */
870 871 872 873 874 875
typedef enum GrantObjectType
{
	ACL_OBJECT_RELATION,		/* table, view, sequence */
	ACL_OBJECT_DATABASE,		/* database */
	ACL_OBJECT_FUNCTION,		/* function */
	ACL_OBJECT_LANGUAGE,		/* procedural language */
876 877
	ACL_OBJECT_NAMESPACE,		/* namespace */
	ACL_OBJECT_TABLESPACE		/* tablespace */
878 879
} GrantObjectType;

880
typedef struct GrantStmt
881
{
882
	NodeTag		type;
883 884
	bool		is_grant;		/* true = GRANT, false = REVOKE */
	GrantObjectType objtype;	/* kind of object being operated on */
Bruce Momjian's avatar
Bruce Momjian committed
885 886 887
	List	   *objects;		/* list of RangeVar nodes, FuncWithArgs
								 * nodes, or plain names (as Value
								 * strings) */
888 889
	List	   *privileges;		/* integer list of privilege codes */
	List	   *grantees;		/* list of PrivGrantee nodes */
890 891
	bool		grant_option;	/* grant or revoke grant option */
	DropBehavior behavior;		/* drop behavior (for REVOKE) */
892
} GrantStmt;
893

894
typedef struct PrivGrantee
895
{
896
	NodeTag		type;
897 898 899
	char	   *username;		/* if both are NULL then PUBLIC */
	char	   *groupname;
} PrivGrantee;
900

901
typedef struct FuncWithArgs
902
{
903
	NodeTag		type;
904
	List	   *funcname;		/* qualified name of function */
905 906
	List	   *funcargs;		/* list of Typename nodes */
} FuncWithArgs;
907

908 909
/* This is only used internally in gram.y. */
typedef struct PrivTarget
910
{
911
	NodeTag		type;
912
	GrantObjectType objtype;
913 914 915
	List	   *objs;
} PrivTarget;

916
/* ----------------------
917
 *		Copy Statement
918 919
 * ----------------------
 */
920
typedef struct CopyStmt
921
{
922
	NodeTag		type;
923
	RangeVar   *relation;		/* the relation to copy */
Bruce Momjian's avatar
Bruce Momjian committed
924 925
	List	   *attlist;		/* List of column names (as Strings), or
								 * NIL for all columns */
926
	bool		is_from;		/* TO or FROM */
927
	char	   *filename;		/* if NULL, use stdin/stdout */
928
	List	   *options;		/* List of DefElem nodes */
929
} CopyStmt;
930 931

/* ----------------------
932 933 934 935 936 937 938
 *		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).
939 940
 * ----------------------
 */
941 942 943 944 945 946 947 948

/* 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 */
949
} OnCommitAction;
950

951
typedef struct CreateStmt
952 953
{
	NodeTag		type;
954
	RangeVar   *relation;		/* relation to create */
955
	List	   *tableElts;		/* column definitions (list of ColumnDef) */
Bruce Momjian's avatar
Bruce Momjian committed
956 957
	List	   *inhRelations;	/* relations to inherit from (list of
								 * inhRelation) */
958
	List	   *constraints;	/* constraints (list of Constraint nodes) */
Bruce Momjian's avatar
Bruce Momjian committed
959
	ContainsOids hasoids;		/* should it have OIDs? */
960
	OnCommitAction oncommit;	/* what do we do at COMMIT? */
Bruce Momjian's avatar
Bruce Momjian committed
961
	char	   *tablespacename; /* table space to use, or NULL */
962
} CreateStmt;
963

964 965 966 967
/* ----------
 * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
 *
 * XXX probably these ought to be unified with FkConstraints at some point?
968 969
 * To this end we include CONSTR_FOREIGN in the ConstrType enum, even though
 * the parser does not generate it.
970 971 972 973 974 975 976 977 978 979 980 981 982
 *
 * 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).
 * ----------
983
 */
984 985 986 987 988 989 990 991

typedef enum ConstrType			/* types of constraints */
{
	CONSTR_NULL,				/* not SQL92, but a lot of people expect
								 * it */
	CONSTR_NOTNULL,
	CONSTR_DEFAULT,
	CONSTR_CHECK,
992
	CONSTR_FOREIGN,
993 994 995 996 997 998 999 1000 1001
	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
1002
{
1003
	NodeTag		type;
1004 1005 1006 1007
	ConstrType	contype;
	char	   *name;			/* name, or NULL if unnamed */
	Node	   *raw_expr;		/* expr, as untransformed parse tree */
	char	   *cooked_expr;	/* expr, as nodeToString representation */
Bruce Momjian's avatar
Bruce Momjian committed
1008 1009
	List	   *keys;			/* String nodes naming referenced
								 * column(s) */
1010 1011
	char	   *indexspace;		/* index tablespace for PKEY/UNIQUE
								 * constraints; NULL for default */
1012
} Constraint;
1013

1014 1015
/* ----------
 * Definitions for FOREIGN KEY constraints in CreateStmt
1016 1017 1018 1019 1020 1021 1022 1023
 *
 * 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
Bruce Momjian's avatar
Bruce Momjian committed
1024
 * for the constraint.	This is currently used only during CREATE TABLE
1025
 * (when we know the table must be empty).
1026
 * ----------
1027
 */
1028 1029 1030 1031 1032
#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'
1033

1034 1035 1036
#define FKCONSTR_MATCH_FULL			'f'
#define FKCONSTR_MATCH_PARTIAL		'p'
#define FKCONSTR_MATCH_UNSPECIFIED	'u'
1037 1038

typedef struct FkConstraint
1039
{
1040
	NodeTag		type;
1041
	char	   *constr_name;	/* Constraint name, or NULL if unnamed */
1042
	RangeVar   *pktable;		/* Primary key table */
1043 1044
	List	   *fk_attrs;		/* Attributes of foreign key */
	List	   *pk_attrs;		/* Corresponding attrs in PK table */
1045 1046 1047
	char		fk_matchtype;	/* FULL, PARTIAL, UNSPECIFIED */
	char		fk_upd_action;	/* ON UPDATE action */
	char		fk_del_action;	/* ON DELETE action */
1048 1049
	bool		deferrable;		/* DEFERRABLE */
	bool		initdeferred;	/* INITIALLY DEFERRED */
Bruce Momjian's avatar
Bruce Momjian committed
1050
	bool		skip_validation;	/* skip validation of existing rows? */
1051
} FkConstraint;
1052

1053 1054

/* ----------------------
Bruce Momjian's avatar
Bruce Momjian committed
1055
 *		Create/Drop Table Space Statements
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
 * ----------------------
 */

typedef struct CreateTableSpaceStmt
{
	NodeTag		type;
	char	   *tablespacename;
	char	   *owner;
	char	   *location;
} CreateTableSpaceStmt;

typedef struct DropTableSpaceStmt
{
	NodeTag		type;
	char	   *tablespacename;
} DropTableSpaceStmt;

1073
/* ----------------------
1074
 *		Create/Drop TRIGGER Statements
1075 1076
 * ----------------------
 */
1077 1078

typedef struct CreateTrigStmt
1079
{
1080
	NodeTag		type;
1081 1082 1083 1084
	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 */
1085 1086
	bool		before;			/* BEFORE/AFTER */
	bool		row;			/* ROW/STATEMENT */
1087
	char		actions[4];		/* 1 to 3 of 'i', 'u', 'd', + trailing \0 */
1088

1089 1090 1091 1092 1093
	/* 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} */
1094
	RangeVar   *constrrel;		/* opposite relation */
1095 1096
} CreateTrigStmt;

1097
/* ----------------------
1098
 *		Create/Drop PROCEDURAL LANGUAGE Statement
1099 1100
 * ----------------------
 */
1101
typedef struct CreatePLangStmt
1102 1103
{
	NodeTag		type;
1104
	char	   *plname;			/* PL name */
1105
	List	   *plhandler;		/* PL call handler function (qual. name) */
Bruce Momjian's avatar
Bruce Momjian committed
1106 1107
	List	   *plvalidator;	/* optional validator function (qual.
								 * name) */
1108 1109
	bool		pltrusted;		/* PL is trusted */
} CreatePLangStmt;
1110

1111
typedef struct DropPLangStmt
1112
{
1113
	NodeTag		type;
1114
	char	   *plname;			/* PL name */
1115
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1116
} DropPLangStmt;
1117 1118

/* ----------------------
1119
 *	Create/Alter/Drop User Statements
1120 1121
 * ----------------------
 */
1122
typedef struct CreateUserStmt
1123
{
1124
	NodeTag		type;
1125 1126 1127
	char	   *user;			/* PostgreSQL user login name */
	List	   *options;		/* List of DefElem nodes */
} CreateUserStmt;
1128

1129
typedef struct AlterUserStmt
1130
{
1131
	NodeTag		type;
1132 1133 1134
	char	   *user;			/* PostgreSQL user login name */
	List	   *options;		/* List of DefElem nodes */
} AlterUserStmt;
1135

1136
typedef struct AlterUserSetStmt
1137
{
1138
	NodeTag		type;
1139 1140 1141 1142
	char	   *user;
	char	   *variable;
	List	   *value;
} AlterUserSetStmt;
1143

1144
typedef struct DropUserStmt
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
1145 1146
{
	NodeTag		type;
1147 1148
	List	   *users;			/* List of users to remove */
} DropUserStmt;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
1149

1150
/* ----------------------
1151
 *		Create/Alter/Drop Group Statements
1152 1153
 * ----------------------
 */
1154
typedef struct CreateGroupStmt
1155
{
1156
	NodeTag		type;
1157 1158 1159
	char	   *name;			/* name of the new group */
	List	   *options;		/* List of DefElem nodes */
} CreateGroupStmt;
1160

1161 1162 1163 1164 1165 1166 1167
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;
1168

1169
typedef struct DropGroupStmt
1170
{
1171 1172
	NodeTag		type;
	char	   *name;
1173
} DropGroupStmt;
1174 1175

/* ----------------------
Bruce Momjian's avatar
Bruce Momjian committed
1176
 *		{Create|Alter} SEQUENCE Statement
1177 1178 1179
 * ----------------------
 */

1180
typedef struct CreateSeqStmt
1181
{
1182
	NodeTag		type;
1183
	RangeVar   *sequence;		/* the sequence to create */
1184 1185
	List	   *options;
} CreateSeqStmt;
1186

Bruce Momjian's avatar
Bruce Momjian committed
1187 1188 1189 1190 1191
typedef struct AlterSeqStmt
{
	NodeTag		type;
	RangeVar   *sequence;		/* the sequence to alter */
	List	   *options;
1192
} AlterSeqStmt;
Bruce Momjian's avatar
Bruce Momjian committed
1193

1194
/* ----------------------
1195
 *		Create {Aggregate|Operator|Type} Statement
1196 1197
 * ----------------------
 */
1198
typedef struct DefineStmt
1199 1200
{
	NodeTag		type;
1201
	ObjectType	kind;			/* aggregate, operator, type */
1202
	List	   *defnames;		/* qualified name (list of Value strings) */
1203 1204
	List	   *definition;		/* a list of DefElem */
} DefineStmt;
1205

Tom Lane's avatar
Tom Lane committed
1206 1207 1208 1209 1210 1211 1212
/* ----------------------
 *		Create Domain Statement
 * ----------------------
 */
typedef struct CreateDomainStmt
{
	NodeTag		type;
1213 1214 1215
	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
1216 1217
} CreateDomainStmt;

1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
/* ----------------------
 *		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;

Hiroshi Inoue's avatar
Hiroshi Inoue committed
1249
/* ----------------------
1250
 *		Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
Hiroshi Inoue's avatar
Hiroshi Inoue committed
1251 1252 1253
 * ----------------------
 */

1254 1255 1256
typedef struct DropStmt
{
	NodeTag		type;
1257
	List	   *objects;		/* list of sublists of names (as Values) */
1258
	ObjectType	removeType;		/* object type */
1259
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1260
} DropStmt;
1261

1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
/* ----------------------
 *		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.
 * ----------------------
 */

typedef struct DropPropertyStmt
{
	NodeTag		type;
	RangeVar   *relation;		/* owning relation */
	char	   *property;		/* name of rule, trigger, etc */
1275
	ObjectType	removeType;		/* OBJECT_RULE or OBJECT_TRIGGER */
1276
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1277 1278
} DropPropertyStmt;

1279
/* ----------------------
1280
 *				Truncate Table Statement
1281 1282
 * ----------------------
 */
1283
typedef struct TruncateStmt
1284
{
1285
	NodeTag		type;
1286
	List	   *relations;		/* relations (RangeVars) to be truncated */
1287
} TruncateStmt;
1288 1289

/* ----------------------
1290
 *				Comment On Statement
1291 1292
 * ----------------------
 */
1293
typedef struct CommentStmt
1294
{
1295
	NodeTag		type;
1296
	ObjectType	objtype;		/* Object's type */
1297 1298 1299
	List	   *objname;		/* Qualified name of the object */
	List	   *objargs;		/* Arguments if needed (eg, for functions) */
	char	   *comment;		/* Comment to insert, or NULL to remove */
1300
} CommentStmt;
1301 1302

/* ----------------------
1303 1304 1305 1306 1307
 *		Declare Cursor Statement
 * ----------------------
 */
#define CURSOR_OPT_BINARY		0x0001
#define CURSOR_OPT_SCROLL		0x0002
1308 1309 1310
#define CURSOR_OPT_NO_SCROLL	0x0004
#define CURSOR_OPT_INSENSITIVE	0x0008
#define CURSOR_OPT_HOLD			0x0010
1311 1312 1313 1314 1315 1316 1317

typedef struct DeclareCursorStmt
{
	NodeTag		type;
	char	   *portalname;		/* name of the portal (cursor) */
	int			options;		/* bitmask of options (see above) */
	Node	   *query;			/* the SELECT query */
1318
} DeclareCursorStmt;
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331

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

/* ----------------------
 *		Fetch Statement (also Move)
1332 1333
 * ----------------------
 */
1334 1335
typedef enum FetchDirection
{
1336
	/* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
1337
	FETCH_FORWARD,
1338 1339 1340 1341
	FETCH_BACKWARD,
	/* for these, howMany indicates a position; only one row is fetched */
	FETCH_ABSOLUTE,
	FETCH_RELATIVE
1342
} FetchDirection;
1343

1344 1345
#define FETCH_ALL	LONG_MAX

1346
typedef struct FetchStmt
1347
{
1348
	NodeTag		type;
1349
	FetchDirection direction;	/* see above */
1350
	long		howMany;		/* number of rows, or position argument */
1351 1352 1353
	char	   *portalname;		/* name of portal (cursor) */
	bool		ismove;			/* TRUE if MOVE */
} FetchStmt;
1354

1355
/* ----------------------
1356
 *		Create Index Statement
1357 1358
 * ----------------------
 */
1359
typedef struct IndexStmt
1360 1361
{
	NodeTag		type;
1362
	char	   *idxname;		/* name of new index, or NULL for default */
1363
	RangeVar   *relation;		/* relation to build index on */
1364
	char	   *accessMethod;	/* name of access method (eg. btree) */
1365
	char	   *tableSpace;		/* tablespace, or NULL to use parent's */
1366 1367
	List	   *indexParams;	/* a list of IndexElem */
	Node	   *whereClause;	/* qualification (partial-index predicate) */
Bruce Momjian's avatar
Bruce Momjian committed
1368 1369 1370
	List	   *rangetable;		/* range table for qual and/or
								 * expressions, filled in by
								 * transformStmt() */
1371 1372
	bool		unique;			/* is index unique? */
	bool		primary;		/* is index on primary key? */
1373
	bool		isconstraint;	/* is it from a CONSTRAINT clause? */
1374
} IndexStmt;
1375

1376 1377 1378
/* ----------------------
 *		Create Function Statement
 * ----------------------
1379
 */
1380
typedef struct CreateFunctionStmt
1381
{
1382
	NodeTag		type;
1383
	bool		replace;		/* T => replace if already exists */
1384
	List	   *funcname;		/* qualified name of function to create */
1385
	List	   *parameters;		/* a list of FunctionParameter */
1386
	TypeName   *returnType;		/* the return type */
1387
	List	   *options;		/* a list of DefElem */
1388
	List	   *withClause;		/* a list of DefElem */
1389
} CreateFunctionStmt;
1390

1391 1392 1393 1394 1395 1396 1397 1398
typedef struct FunctionParameter
{
	NodeTag		type;
	char	   *name;			/* parameter name, or NULL if not given */
	TypeName   *argType;		/* TypeName for parameter type */
	/* someday add IN/OUT/INOUT indicator here */
} FunctionParameter;

1399 1400 1401
/* ----------------------
 *		Drop Aggregate Statement
 * ----------------------
1402
 */
1403
typedef struct RemoveAggrStmt
1404
{
1405
	NodeTag		type;
1406
	List	   *aggname;		/* aggregate to drop */
1407
	TypeName   *aggtype;		/* TypeName for input datatype, or NULL */
1408
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1409
} RemoveAggrStmt;
1410

1411 1412 1413
/* ----------------------
 *		Drop Function Statement
 * ----------------------
1414
 */
1415
typedef struct RemoveFuncStmt
1416
{
1417
	NodeTag		type;
1418
	List	   *funcname;		/* function to drop */
1419
	List	   *args;			/* types of the arguments */
1420
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1421
} RemoveFuncStmt;
1422

1423 1424 1425
/* ----------------------
 *		Drop Operator Statement
 * ----------------------
1426
 */
1427
typedef struct RemoveOperStmt
1428
{
1429
	NodeTag		type;
1430
	List	   *opname;			/* operator to drop */
1431
	List	   *args;			/* types of the arguments */
1432
	DropBehavior behavior;		/* RESTRICT or CASCADE behavior */
1433
} RemoveOperStmt;
1434

1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
/* ----------------------
 *		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;

1447
/* ----------------------
1448
 *		Alter Object Rename Statement
1449
 * ----------------------
1450
 */
1451
typedef struct RenameStmt
1452
{
1453
	NodeTag		type;
1454 1455 1456
	RangeVar   *relation;		/* in case it's a table */
	List	   *object;			/* in case it's some other object */
	List	   *objarg;			/* argument types, if applicable */
Bruce Momjian's avatar
Bruce Momjian committed
1457 1458
	char	   *subname;		/* name of contained object (column, rule,
								 * trigger, etc) */
1459
	char	   *newname;		/* the new name */
1460
	ObjectType	renameType;		/* OBJECT_TABLE, OBJECT_COLUMN, etc */
1461
} RenameStmt;
1462

1463
/* ----------------------
Bruce Momjian's avatar
Bruce Momjian committed
1464
 *		Alter Object Owner Statement
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478
 * ----------------------
 */
typedef struct AlterOwnerStmt
{
	NodeTag		type;
	RangeVar   *relation;		/* in case it's a table */
	List	   *object;			/* in case it's some other object */
	List	   *objarg;			/* argument types, if applicable */
	char	   *addname;		/* additional name if needed */
	char	   *newowner;		/* the new owner */
	ObjectType	objectType;		/* OBJECT_TABLE, OBJECT_TYPE, etc */
} AlterOwnerStmt;


1479 1480 1481
/* ----------------------
 *		Create Rule Statement
 * ----------------------
1482
 */
1483
typedef struct RuleStmt
1484 1485
{
	NodeTag		type;
1486
	RangeVar   *relation;		/* relation the rule is for */
1487 1488
	char	   *rulename;		/* name of the rule */
	Node	   *whereClause;	/* qualifications */
1489
	CmdType		event;			/* SELECT, INSERT, etc */
1490 1491
	bool		instead;		/* is a 'do instead'? */
	List	   *actions;		/* the action statements */
1492
	bool		replace;		/* OR REPLACE */
1493
} RuleStmt;
1494

1495 1496 1497
/* ----------------------
 *		Notify Statement
 * ----------------------
1498
 */
1499
typedef struct NotifyStmt
1500 1501
{
	NodeTag		type;
1502
	RangeVar   *relation;		/* qualified name to notify */
1503
} NotifyStmt;
1504

1505 1506 1507
/* ----------------------
 *		Listen Statement
 * ----------------------
1508
 */
1509
typedef struct ListenStmt
1510 1511
{
	NodeTag		type;
1512
	RangeVar   *relation;		/* qualified name to listen on */
1513
} ListenStmt;
1514

1515 1516 1517
/* ----------------------
 *		Unlisten Statement
 * ----------------------
1518
 */
1519
typedef struct UnlistenStmt
1520
{
1521
	NodeTag		type;
1522
	RangeVar   *relation;		/* qualified name to unlisten on, or '*' */
1523
} UnlistenStmt;
1524

1525
/* ----------------------
1526
 *		{Begin|Commit|Rollback} Transaction Statement
1527 1528
 * ----------------------
 */
1529 1530 1531 1532 1533
typedef enum TransactionStmtKind
{
	TRANS_STMT_BEGIN,
	TRANS_STMT_START,			/* semantically identical to BEGIN */
	TRANS_STMT_COMMIT,
1534 1535 1536 1537
	TRANS_STMT_ROLLBACK,
	TRANS_STMT_SAVEPOINT,
	TRANS_STMT_RELEASE,
	TRANS_STMT_ROLLBACK_TO
1538
} TransactionStmtKind;
1539

1540
typedef struct TransactionStmt
1541
{
1542
	NodeTag		type;
1543
	TransactionStmtKind kind;	/* see above */
1544
	List	   *options;		/* for BEGIN/START and savepoint commands */
1545
} TransactionStmt;
1546

Bruce Momjian's avatar
Bruce Momjian committed
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
/* ----------------------
 *		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;


1559 1560 1561
/* ----------------------
 *		Create View Statement
 * ----------------------
1562
 */
1563
typedef struct ViewStmt
1564
{
1565
	NodeTag		type;
1566
	RangeVar   *view;			/* the view to be created */
1567 1568
	List	   *aliases;		/* target column names */
	Query	   *query;			/* the SQL statement */
1569
	bool		replace;		/* replace an existing view? */
1570
} ViewStmt;
1571

1572 1573 1574 1575 1576
/* ----------------------
 *		Load Statement
 * ----------------------
 */
typedef struct LoadStmt
1577
{
1578
	NodeTag		type;
1579 1580
	char	   *filename;		/* file to load */
} LoadStmt;
1581

1582 1583 1584
/* ----------------------
 *		Createdb Statement
 * ----------------------
1585
 */
1586
typedef struct CreatedbStmt
1587
{
1588
	NodeTag		type;
1589
	char	   *dbname;			/* name of database to create */
1590
	List	   *options;		/* List of DefElem nodes */
1591
} CreatedbStmt;
1592

1593 1594 1595
/* ----------------------
 *	Alter Database
 * ----------------------
1596
 */
1597
typedef struct AlterDatabaseSetStmt
1598
{
1599
	NodeTag		type;
1600 1601 1602 1603
	char	   *dbname;
	char	   *variable;
	List	   *value;
} AlterDatabaseSetStmt;
1604

1605 1606 1607
/* ----------------------
 *		Dropdb Statement
 * ----------------------
1608
 */
1609
typedef struct DropdbStmt
1610
{
1611
	NodeTag		type;
1612 1613
	char	   *dbname;			/* database to drop */
} DropdbStmt;
1614

1615 1616 1617
/* ----------------------
 *		Cluster Statement (support pbrown's cluster index implementation)
 * ----------------------
1618
 */
1619
typedef struct ClusterStmt
1620
{
1621
	NodeTag		type;
1622
	RangeVar   *relation;		/* relation being indexed, or NULL if all */
1623 1624
	char	   *indexname;		/* original index defined */
} ClusterStmt;
1625

1626 1627
/* ----------------------
 *		Vacuum and Analyze Statements
1628
 *
1629 1630 1631
 * Even though these are nominally two statements, it's convenient to use
 * just one node type for both.
 * ----------------------
1632
 */
1633
typedef struct VacuumStmt
1634
{
1635
	NodeTag		type;
1636 1637 1638 1639 1640
	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 */
1641
	RangeVar   *relation;		/* single table to process, or NULL */
1642 1643
	List	   *va_cols;		/* list of column names, or NIL for all */
} VacuumStmt;
1644

1645 1646 1647
/* ----------------------
 *		Explain Statement
 * ----------------------
1648
 */
1649
typedef struct ExplainStmt
1650 1651
{
	NodeTag		type;
1652 1653 1654 1655
	Query	   *query;			/* the query */
	bool		verbose;		/* print plan info */
	bool		analyze;		/* get statistics by executing plan */
} ExplainStmt;
1656

1657 1658 1659
/* ----------------------
 * Checkpoint Statement
 * ----------------------
1660
 */
1661
typedef struct CheckPointStmt
1662
{
1663
	NodeTag		type;
1664
} CheckPointStmt;
1665

1666 1667 1668
/* ----------------------
 * Set Statement
 * ----------------------
1669
 */
1670 1671

typedef struct VariableSetStmt
1672 1673
{
	NodeTag		type;
1674 1675
	char	   *name;
	List	   *args;
1676
	bool		is_local;		/* SET LOCAL */
1677
} VariableSetStmt;
1678

1679 1680 1681
/* ----------------------
 * Show Statement
 * ----------------------
1682
 */
1683 1684

typedef struct VariableShowStmt
1685
{
1686
	NodeTag		type;
1687 1688
	char	   *name;
} VariableShowStmt;
1689

1690 1691 1692
/* ----------------------
 * Reset Statement
 * ----------------------
1693
 */
1694 1695

typedef struct VariableResetStmt
1696
{
1697
	NodeTag		type;
1698 1699
	char	   *name;
} VariableResetStmt;
1700

1701 1702 1703
/* ----------------------
 *		LOCK Statement
 * ----------------------
1704
 */
1705
typedef struct LockStmt
1706
{
1707
	NodeTag		type;
1708
	List	   *relations;		/* relations to lock */
1709
	int			mode;			/* lock mode */
Bruce Momjian's avatar
Bruce Momjian committed
1710
	bool		nowait;			/* no wait mode */
1711
} LockStmt;
1712

1713 1714 1715
/* ----------------------
 *		SET CONSTRAINTS Statement
 * ----------------------
1716
 */
1717
typedef struct ConstraintsSetStmt
1718
{
1719
	NodeTag		type;
1720 1721 1722
	List	   *constraints;	/* List of names as Value strings */
	bool		deferred;
} ConstraintsSetStmt;
1723

1724 1725 1726
/* ----------------------
 *		REINDEX Statement
 * ----------------------
1727
 */
1728
typedef struct ReindexStmt
1729
{
1730
	NodeTag		type;
Bruce Momjian's avatar
Bruce Momjian committed
1731 1732
	ObjectType	kind;			/* OBJECT_INDEX, OBJECT_TABLE,
								 * OBJECT_DATABASE */
1733 1734
	RangeVar   *relation;		/* Table or index to reindex */
	const char *name;			/* name of database to reindex */
1735 1736 1737
	bool		force;
	bool		all;
} ReindexStmt;
1738

1739 1740 1741 1742 1743 1744 1745
/* ----------------------
 *		CREATE CONVERSION Statement
 * ----------------------
 */
typedef struct CreateConversionStmt
{
	NodeTag		type;
Bruce Momjian's avatar
Bruce Momjian committed
1746 1747
	List	   *conversion_name;	/* Name of the conversion */
	char	   *for_encoding_name;		/* source encoding name */
Tatsuo Ishii's avatar
Tatsuo Ishii committed
1748
	char	   *to_encoding_name;		/* destination encoding name */
Bruce Momjian's avatar
Bruce Momjian committed
1749 1750
	List	   *func_name;		/* qualified conversion function name */
	bool		def;			/* is this a default conversion? */
1751 1752
} CreateConversionStmt;

1753 1754 1755 1756 1757 1758 1759 1760 1761 1762
/* ----------------------
 *	CREATE CAST Statement
 * ----------------------
 */
typedef struct CreateCastStmt
{
	NodeTag		type;
	TypeName   *sourcetype;
	TypeName   *targettype;
	FuncWithArgs *func;
1763
	CoercionContext context;
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778
} CreateCastStmt;

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


1779 1780 1781 1782 1783 1784
/* ----------------------
 *		PREPARE Statement
 * ----------------------
 */
typedef struct PrepareStmt
{
Bruce Momjian's avatar
Bruce Momjian committed
1785 1786 1787 1788 1789
	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 */
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799
} PrepareStmt;


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

typedef struct ExecuteStmt
{
Bruce Momjian's avatar
Bruce Momjian committed
1800 1801 1802 1803
	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 */
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816
} ExecuteStmt;


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

1817
#endif   /* PARSENODES_H */