parsenodes.h 36.8 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * parsenodes.h
4
 *	  definitions for parse tree nodes
5 6
 *
 *
7
 * Portions Copyright (c) 1996-2001, 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.129 2001/05/21 18:42:08 momjian Exp $
11 12 13
 *
 *-------------------------------------------------------------------------
 */
14 15
#ifndef PARSENODES_H
#define PARSENODES_H
16

17
#include "nodes/primnodes.h"
18 19

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

/*
 * Query -
25 26 27 28
 *	  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.
29 30 31 32
 *
 * we need the isPortal flag because portal names can be null too; can
 * get rid of it if we support CURSOR as a commandType.
 */
33 34
typedef struct Query
{
35
	NodeTag		type;
36

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

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

42
	int			resultRelation; /* target relation (index into rtable) */
43 44 45
	char	   *into;			/* portal (cursor) name */
	bool		isPortal;		/* is this a retrieve into portal? */
	bool		isBinary;		/* binary portal? */
46
	bool		isTemp;			/* is 'into' a temp table? */
47

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

51
	List	   *rtable;			/* list of range table entries */
52 53
	FromExpr   *jointree;		/* table join tree (FROM and WHERE
								 * clauses) */
54

55 56
	List	   *rowMarks;		/* integer list of RT indexes of relations
								 * that are selected FOR UPDATE */
57

58
	List	   *targetList;		/* target list (of TargetEntry) */
59

60 61 62
	List	   *groupClause;	/* a list of GroupClause's */

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

64 65 66
	List	   *distinctClause; /* a list of SortClause's */

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

Bruce Momjian's avatar
Bruce Momjian committed
68 69
	Node	   *limitOffset;	/* # of result tuples to skip */
	Node	   *limitCount;		/* # of result tuples to return */
Bruce Momjian's avatar
Bruce Momjian committed
70

71 72 73
	Node	   *setOperations;	/* set-operation tree if this is top level
								 * of a UNION/INTERSECT/EXCEPT query */

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

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


94 95 96 97 98 99 100
typedef enum InhOption
{
	INH_NO,						/* Do NOT scan child tables */
	INH_YES,					/* DO scan child tables */
	INH_DEFAULT					/* Use current SQL_inheritance option */
} InhOption;

101
/*****************************************************************************
102
 *		Other Statements (no optimizations required)
103
 *
104 105 106 107
 *		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.
108 109 110
 *****************************************************************************/

/* ----------------------
111
 *	Alter Table
112 113 114
 *
 * The fields are used in different ways by the different variants of
 * this command.
115 116
 * ----------------------
 */
117
typedef struct AlterTableStmt
118
{
119
	NodeTag		type;
120 121
	char		subtype;		/*------------
								 * 	A = add column
122 123
								 *	T = alter column default
								 *	S = alter column statistics
124 125 126
								 *	D = drop column
								 *	C = add constraint
								 *	X = drop constraint
127
								 *	E = create toast table
128 129 130
								 *	U = change owner
								 *------------
								 */
131
	char	   *relname;		/* table to work on */
132
	InhOption	inhOpt;			/* recursively act on children? */
133 134
	char	   *name;			/* column or constraint name to act on, or
								 * new owner */
135 136
	Node	   *def;			/* definition of new column or constraint */
	int			behavior;		/* CASCADE or RESTRICT drop behavior */
137
} AlterTableStmt;
138 139

/* ----------------------
140
 *		Change ACL Statement
141 142
 * ----------------------
 */
143 144
typedef struct ChangeACLStmt
{
145 146
	NodeTag		type;
	List	   *relNames;
147
	char	   *aclString;
148
} ChangeACLStmt;
149 150

/* ----------------------
151
 *		Close Portal Statement
152 153
 * ----------------------
 */
154 155
typedef struct ClosePortalStmt
{
156 157
	NodeTag		type;
	char	   *portalname;		/* name of the portal (cursor) */
158
} ClosePortalStmt;
159 160

/* ----------------------
161
 *		Copy Statement
162 163
 * ----------------------
 */
164 165
typedef struct CopyStmt
{
166 167 168 169 170 171 172
	NodeTag		type;
	bool		binary;			/* is a binary copy? */
	char	   *relname;		/* the relation to copy */
	bool		oids;			/* copy oid's? */
	int			direction;		/* TO or FROM */
	char	   *filename;		/* if NULL, use stdin/stdout */
	char	   *delimiter;		/* delimiter character, \t by default */
173
	char	   *null_print;		/* how to print NULLs, `\N' by default */
174
} CopyStmt;
175 176

/* ----------------------
177
 *		Create Table Statement
178 179
 * ----------------------
 */
180 181
typedef struct CreateStmt
{
182
	NodeTag		type;
183
	bool		istemp;			/* is this a temp table? */
184 185 186 187
	char	   *relname;		/* name of relation to create */
	List	   *tableElts;		/* column definitions (list of ColumnDef) */
	List	   *inhRelnames;	/* relations to inherit from (list of
								 * T_String Values) */
188 189
	List	   *constraints;	/* constraints (list of Constraint and
								 * FkConstraint nodes) */
190
} CreateStmt;
191

192 193 194 195 196
/* ----------
 * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
 *
 * XXX probably these ought to be unified with FkConstraints at some point?
 *
197 198 199 200 201 202
 * 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!
203 204 205 206 207 208
 *
 * 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).
 * ----------
209 210
 */

211 212
typedef enum ConstrType			/* types of constraints */
{
213 214
	CONSTR_NULL,				/* not SQL92, but a lot of people expect
								 * it */
215 216 217 218 219 220 221 222 223 224 225
	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;

226
typedef struct Constraint
227
{
228 229
	NodeTag		type;
	ConstrType	contype;
230 231 232
	char	   *name;			/* name, or NULL if unnamed */
	Node	   *raw_expr;		/* expr, as untransformed parse tree */
	char	   *cooked_expr;	/* expr, as nodeToString representation */
Tom Lane's avatar
Tom Lane committed
233
	List	   *keys;			/* Ident nodes naming referenced column(s) */
234
} Constraint;
235

Jan Wieck's avatar
Jan Wieck committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255

/* ----------
 * Definitions for FOREIGN KEY constraints in CreateStmt
 * ----------
 */
#define FKCONSTR_ON_KEY_NOACTION		0x0000
#define FKCONSTR_ON_KEY_RESTRICT		0x0001
#define FKCONSTR_ON_KEY_CASCADE			0x0002
#define FKCONSTR_ON_KEY_SETNULL			0x0004
#define FKCONSTR_ON_KEY_SETDEFAULT		0x0008

#define FKCONSTR_ON_DELETE_MASK			0x000F
#define FKCONSTR_ON_DELETE_SHIFT		0

#define FKCONSTR_ON_UPDATE_MASK			0x00F0
#define FKCONSTR_ON_UPDATE_SHIFT		4

typedef struct FkConstraint
{
	NodeTag		type;
256 257 258 259 260 261 262 263
	char	   *constr_name;	/* Constraint name */
	char	   *pktable_name;	/* Primary key table name */
	List	   *fk_attrs;		/* Attributes of foreign key */
	List	   *pk_attrs;		/* Corresponding attrs in PK table */
	char	   *match_type;		/* FULL or PARTIAL */
	int32		actions;		/* ON DELETE/UPDATE actions */
	bool		deferrable;		/* DEFERRABLE */
	bool		initdeferred;	/* INITIALLY DEFERRED */
Jan Wieck's avatar
Jan Wieck committed
264 265 266
} FkConstraint;


267
/* ----------------------
268
 *		Create/Drop TRIGGER Statements
269 270 271
 * ----------------------
 */

272 273
typedef struct CreateTrigStmt
{
274 275 276 277 278 279 280 281
	NodeTag		type;
	char	   *trigname;		/* TRIGGER' name */
	char	   *relname;		/* triggered relation */
	char	   *funcname;		/* function to call (or NULL) */
	List	   *args;			/* list of (T_String) Values or NULL */
	bool		before;			/* BEFORE/AFTER */
	bool		row;			/* ROW/STATEMENT */
	char		actions[4];		/* Insert, Update, Delete */
282
	char	   *lang;			/* currently not used, always NULL */
283 284 285
	char	   *text;			/* AS 'text' */
	List	   *attr;			/* UPDATE OF a, b,... (NI) or NULL */
	char	   *when;			/* WHEN 'a > 10 ...' (NI) or NULL */
286

287 288
	/* The following are used for referential */
	/* integrity constraint triggers */
289 290 291 292
	bool		isconstraint;	/* This is an RI trigger */
	bool		deferrable;		/* [NOT] DEFERRABLE */
	bool		initdeferred;	/* INITIALLY {DEFERRED|IMMEDIATE} */
	char	   *constrrelname;	/* opposite relation */
293
} CreateTrigStmt;
294

295 296
typedef struct DropTrigStmt
{
297 298 299
	NodeTag		type;
	char	   *trigname;		/* TRIGGER' name */
	char	   *relname;		/* triggered relation */
300
} DropTrigStmt;
301 302 303 304 305 306 307 308 309 310 311 312 313


/* ----------------------
 *		Create/Drop PROCEDURAL LANGUAGE Statement
 * ----------------------
 */
typedef struct CreatePLangStmt
{
	NodeTag		type;
	char	   *plname;			/* PL name */
	char	   *plhandler;		/* PL call handler function */
	char	   *plcompiler;		/* lancompiler text */
	bool		pltrusted;		/* PL is trusted */
314
} CreatePLangStmt;
315 316 317 318 319

typedef struct DropPLangStmt
{
	NodeTag		type;
	char	   *plname;			/* PL name */
320
} DropPLangStmt;
321

322

323
/* ----------------------
324
 *				Create/Alter/Drop User Statements
325 326 327 328
 * ----------------------
 */
typedef struct CreateUserStmt
{
329 330 331
	NodeTag		type;
	char	   *user;			/* PostgreSQL user login			  */
	char	   *password;		/* PostgreSQL user password			  */
332 333 334
	int			sysid;			/* PgSQL system id (-1 if don't care) */
	bool		createdb;		/* Can the user create databases?	  */
	bool		createuser;		/* Can this user create users?		  */
335 336
	List	   *groupElts;		/* The groups the user is a member of */
	char	   *validUntil;		/* The time the login is valid until  */
337 338
} CreateUserStmt;

339 340 341 342 343
typedef struct AlterUserStmt
{
	NodeTag		type;
	char	   *user;			/* PostgreSQL user login			  */
	char	   *password;		/* PostgreSQL user password			  */
344 345
	int			createdb;		/* Can the user create databases?	  */
	int			createuser;		/* Can this user create users?		  */
346 347
	char	   *validUntil;		/* The time the login is valid until  */
} AlterUserStmt;
348 349 350

typedef struct DropUserStmt
{
351
	NodeTag		type;
352
	List	   *users;			/* List of users to remove */
353 354 355
} DropUserStmt;


356
/* ----------------------
357
 *		Create/Alter/Drop Group Statements
358 359 360 361
 * ----------------------
 */
typedef struct CreateGroupStmt
{
362 363 364 365
	NodeTag		type;
	char	   *name;			/* name of the new group */
	int			sysid;			/* group id (-1 if pick default) */
	List	   *initUsers;		/* list of initial users */
366 367 368 369
} CreateGroupStmt;

typedef struct AlterGroupStmt
{
370 371 372 373 374
	NodeTag		type;
	char	   *name;			/* name of group to alter */
	int			action;			/* +1 = add, -1 = drop user */
	int			sysid;			/* sysid change */
	List	   *listUsers;		/* list of users to add/drop */
375 376 377 378
} AlterGroupStmt;

typedef struct DropGroupStmt
{
379 380
	NodeTag		type;
	char	   *name;
381 382 383
} DropGroupStmt;


Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
384
/* ----------------------
385
 *		Create SEQUENCE Statement
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
386 387 388
 * ----------------------
 */

389 390
typedef struct CreateSeqStmt
{
391 392 393
	NodeTag		type;
	char	   *seqname;		/* the relation to create */
	List	   *options;
394
} CreateSeqStmt;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
395

396
/* ----------------------
397
 *		Create Version Statement
398 399
 * ----------------------
 */
400 401
typedef struct VersionStmt
{
402 403 404 405 406
	NodeTag		type;
	char	   *relname;		/* the new relation */
	int			direction;		/* FORWARD | BACKWARD */
	char	   *fromRelname;	/* relation to create a version */
	char	   *date;			/* date of the snapshot */
407
} VersionStmt;
408 409

/* ----------------------
410
 *		Create {Operator|Type|Aggregate} Statement
411 412
 * ----------------------
 */
413 414
typedef struct DefineStmt
{
415 416 417 418
	NodeTag		type;
	int			defType;		/* OPERATOR|P_TYPE|AGGREGATE */
	char	   *defname;
	List	   *definition;		/* a list of DefElem */
419
} DefineStmt;
420

421

422
/* ----------------------
423
 *		Drop Table|Sequence|View|Index|Rule|Type Statement
424 425
 * ----------------------
 */
426

427
#define DROP_TABLE	  1
428
#define DROP_SEQUENCE 2
429 430 431
#define DROP_VIEW	  3
#define DROP_INDEX	  4
#define DROP_RULE	  5
432 433
#define DROP_TYPE_P   6

434
typedef struct DropStmt
435
{
436
	NodeTag		type;
437 438
	List	   *names;
	int			removeType;
439
} DropStmt;
440

441
/* ----------------------
442
 *				Truncate Table Statement
443 444 445 446
 * ----------------------
 */
typedef struct TruncateStmt
{
447 448
	NodeTag		type;
	char	   *relName;		/* relation to be truncated */
449
} TruncateStmt;
450 451

/* ----------------------
452
 *				Comment On Statement
453 454 455 456
 * ----------------------
 */
typedef struct CommentStmt
{
457 458 459 460 461 462
	NodeTag		type;
	int			objtype;		/* Object's type */
	char	   *objname;		/* Name of the object */
	char	   *objproperty;	/* Property Id (such as column) */
	List	   *objlist;		/* Arguments for VAL objects */
	char	   *comment;		/* The comment to insert */
463
} CommentStmt;
464

465
/* ----------------------
466
 *		Extend Index Statement
467 468
 * ----------------------
 */
469 470
typedef struct ExtendStmt
{
471 472 473 474
	NodeTag		type;
	char	   *idxname;		/* name of the index */
	Node	   *whereClause;	/* qualifications */
	List	   *rangetable;		/* range table, filled in by
475
								 * transformStmt() */
476
} ExtendStmt;
477 478

/* ----------------------
479
 *		Begin Recipe Statement
480 481
 * ----------------------
 */
482 483
typedef struct RecipeStmt
{
484 485
	NodeTag		type;
	char	   *recipeName;		/* name of the recipe */
486
} RecipeStmt;
487 488

/* ----------------------
489
 *		Fetch Statement
490 491
 * ----------------------
 */
492 493
typedef struct FetchStmt
{
494 495 496 497
	NodeTag		type;
	int			direction;		/* FORWARD or BACKWARD */
	int			howMany;		/* amount to fetch ("ALL" --> 0) */
	char	   *portalname;		/* name of portal (cursor) */
498
	bool		ismove;			/* TRUE if MOVE */
499
} FetchStmt;
500 501

/* ----------------------
502
 *		Create Index Statement
503 504
 * ----------------------
 */
505 506
typedef struct IndexStmt
{
507 508 509
	NodeTag		type;
	char	   *idxname;		/* name of the index */
	char	   *relname;		/* name of relation to index on */
510
	char	   *accessMethod;	/* name of access method (eg. btree) */
511
	List	   *indexParams;	/* a list of IndexElem */
512
	List	   *withClause;		/* a list of DefElem */
513 514
	Node	   *whereClause;	/* qualification (partial-index predicate) */
	List	   *rangetable;		/* range table for qual, filled in by
515
								 * transformStmt() */
516
	bool		unique;			/* is index unique? */
517
	bool		primary;		/* is index on primary key? */
518
} IndexStmt;
519 520

/* ----------------------
521
 *		Create Function Statement
522 523
 * ----------------------
 */
524 525
typedef struct ProcedureStmt
{
526 527
	NodeTag		type;
	char	   *funcname;		/* name of function to create */
528 529
	List	   *argTypes;		/* list of argument types (TypeName nodes) */
	Node	   *returnType;		/* the return type (a TypeName node) */
530
	List	   *withClause;		/* a list of DefElem */
531 532
	List	   *as;				/* definition of function body */
	char	   *language;		/* C, SQL, etc */
533
} ProcedureStmt;
534

535
/* ----------------------
536
 *		Drop Aggregate Statement
537 538
 * ----------------------
 */
539 540
typedef struct RemoveAggrStmt
{
541 542
	NodeTag		type;
	char	   *aggname;		/* aggregate to drop */
543
	Node	   *aggtype;		/* TypeName for input datatype, or NULL */
544
} RemoveAggrStmt;
545

546
/* ----------------------
547
 *		Drop Function Statement
548 549
 * ----------------------
 */
550 551
typedef struct RemoveFuncStmt
{
552 553 554
	NodeTag		type;
	char	   *funcname;		/* function to drop */
	List	   *args;			/* types of the arguments */
555
} RemoveFuncStmt;
556 557

/* ----------------------
558
 *		Drop Operator Statement
559 560
 * ----------------------
 */
561 562
typedef struct RemoveOperStmt
{
563 564 565
	NodeTag		type;
	char	   *opname;			/* operator to drop */
	List	   *args;			/* types of the arguments */
566
} RemoveOperStmt;
567 568

/* ----------------------
569
 *		Alter Table Statement
570 571
 * ----------------------
 */
572 573
typedef struct RenameStmt
{
574 575
	NodeTag		type;
	char	   *relname;		/* relation to be altered */
576
	InhOption	inhOpt;			/* recursively act on children? */
577
	char	   *column;			/* if NULL, rename the relation name to
578 579
								 * the new name. Otherwise, rename this
								 * column name. */
580
	char	   *newname;		/* the new name */
581
} RenameStmt;
582 583

/* ----------------------
584
 *		Create Rule Statement
585 586
 * ----------------------
 */
587 588
typedef struct RuleStmt
{
589 590 591 592 593 594 595
	NodeTag		type;
	char	   *rulename;		/* name of the rule */
	Node	   *whereClause;	/* qualifications */
	CmdType		event;			/* RETRIEVE */
	struct Attr *object;		/* object affected */
	bool		instead;		/* is a 'do instead'? */
	List	   *actions;		/* the action statements */
596
} RuleStmt;
597 598

/* ----------------------
599
 *		Notify Statement
600 601
 * ----------------------
 */
602 603
typedef struct NotifyStmt
{
604 605
	NodeTag		type;
	char	   *relname;		/* relation to notify */
606
} NotifyStmt;
607 608

/* ----------------------
609
 *		Listen Statement
610 611
 * ----------------------
 */
612 613
typedef struct ListenStmt
{
614 615
	NodeTag		type;
	char	   *relname;		/* relation to listen on */
616
} ListenStmt;
617 618 619 620 621 622 623 624 625

/* ----------------------
 *		Unlisten Statement
 * ----------------------
 */
typedef struct UnlistenStmt
{
	NodeTag		type;
	char	   *relname;		/* relation to unlisten on */
626
} UnlistenStmt;
627 628

/* ----------------------
629
 *		{Begin|Abort|End} Transaction Statement
630 631
 * ----------------------
 */
632 633
typedef struct TransactionStmt
{
634 635
	NodeTag		type;
	int			command;		/* BEGIN|END|ABORT */
636
} TransactionStmt;
637 638

/* ----------------------
639
 *		Create View Statement
640 641
 * ----------------------
 */
642 643
typedef struct ViewStmt
{
644 645
	NodeTag		type;
	char	   *viewname;		/* name of the view */
646
	List	   *aliases;		/* target column names */
647
	Query	   *query;			/* the SQL statement */
648
} ViewStmt;
649 650

/* ----------------------
651
 *		Load Statement
652 653
 * ----------------------
 */
654 655
typedef struct LoadStmt
{
656 657
	NodeTag		type;
	char	   *filename;		/* file to load */
658
} LoadStmt;
659 660

/* ----------------------
661
 *		Createdb Statement
662 663
 * ----------------------
 */
664 665
typedef struct CreatedbStmt
{
666
	NodeTag		type;
667 668 669 670
	char	   *dbname;			/* name of database to create */
	char	   *dbpath;			/* location of database (NULL = default) */
	char	   *dbtemplate;		/* template to use (NULL = default) */
	int			encoding;		/* MULTIBYTE encoding (-1 = use default) */
671
} CreatedbStmt;
672 673

/* ----------------------
674
 *		Dropdb Statement
675 676
 * ----------------------
 */
677
typedef struct DropdbStmt
678
{
679 680
	NodeTag		type;
	char	   *dbname;			/* database to drop */
681
} DropdbStmt;
682 683

/* ----------------------
684
 *		Cluster Statement (support pbrown's cluster index implementation)
685 686
 * ----------------------
 */
687 688
typedef struct ClusterStmt
{
689 690 691
	NodeTag		type;
	char	   *relname;		/* relation being indexed */
	char	   *indexname;		/* original index defined */
692
} ClusterStmt;
693 694

/* ----------------------
695 696 697 698
 *		Vacuum and Analyze Statements
 *
 * Even though these are nominally two statements, it's convenient to use
 * just one node type for both.
699 700
 * ----------------------
 */
701 702
typedef struct VacuumStmt
{
703
	NodeTag		type;
704 705 706 707 708
	bool		vacuum;			/* do VACUUM step */
	bool		analyze;		/* do ANALYZE step */
	bool		verbose;		/* print progress info */
	char	   *vacrel;			/* name of single table to process, or NULL */
	List	   *va_cols;		/* list of column names, or NIL for all */
709
} VacuumStmt;
710 711

/* ----------------------
712
 *		Explain Statement
713 714
 * ----------------------
 */
715 716
typedef struct ExplainStmt
{
717 718 719
	NodeTag		type;
	Query	   *query;			/* the query */
	bool		verbose;		/* print plan info */
720
} ExplainStmt;
721

722
/* ----------------------
723
 * Checkpoint Statement
724 725
 * ----------------------
 */
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
726 727 728 729 730
typedef struct CheckPointStmt
{
	NodeTag		type;
} CheckPointStmt;

731 732 733 734 735
/* ----------------------
 * Set Statement
 * ----------------------
 */

736 737
typedef struct VariableSetStmt
{
738 739 740
	NodeTag		type;
	char	   *name;
	char	   *value;
741
} VariableSetStmt;
742 743 744 745 746 747

/* ----------------------
 * Show Statement
 * ----------------------
 */

748 749
typedef struct VariableShowStmt
{
750 751
	NodeTag		type;
	char	   *name;
752
} VariableShowStmt;
753 754 755 756 757 758

/* ----------------------
 * Reset Statement
 * ----------------------
 */

759 760
typedef struct VariableResetStmt
{
761 762
	NodeTag		type;
	char	   *name;
763
} VariableResetStmt;
764

765 766 767 768 769 770 771 772 773
/* ----------------------
 *		LOCK Statement
 * ----------------------
 */
typedef struct LockStmt
{
	NodeTag		type;
	char	   *relname;		/* relation to lock */
	int			mode;			/* lock mode */
774
} LockStmt;
775

776 777 778 779 780 781 782 783

/* ----------------------
 *		SET CONSTRAINTS Statement
 * ----------------------
 */
typedef struct ConstraintsSetStmt
{
	NodeTag		type;
784
	List	   *constraints;
785 786 787
	bool		deferred;
} ConstraintsSetStmt;

Hiroshi Inoue's avatar
Hiroshi Inoue committed
788 789 790 791 792 793 794
/* ----------------------
 *		REINDEX Statement
 * ----------------------
 */
typedef struct ReindexStmt
{
	NodeTag		type;
795 796
	int			reindexType;	/* INDEX|TABLE|DATABASE */
	const char *name;			/* name to reindex */
Hiroshi Inoue's avatar
Hiroshi Inoue committed
797 798 799 800
	bool		force;
	bool		all;
} ReindexStmt;

801

802
/*****************************************************************************
803
 *		Optimizable Statements
804 805 806
 *****************************************************************************/

/* ----------------------
807
 *		Insert Statement
808 809
 * ----------------------
 */
Bruce Momjian's avatar
Bruce Momjian committed
810
typedef struct InsertStmt
811
{
812 813
	NodeTag		type;
	char	   *relname;		/* relation to insert into */
814
	List	   *cols;			/* optional: names of the target columns */
815

816
	/*
817 818 819
	 * 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.
820
	 */
821
	List	   *targetList;		/* the target list (of ResTarget) */
822
	Node	   *selectStmt;		/* the source SELECT */
Bruce Momjian's avatar
Bruce Momjian committed
823
} InsertStmt;
824 825

/* ----------------------
826
 *		Delete Statement
827 828
 * ----------------------
 */
829 830
typedef struct DeleteStmt
{
831 832 833
	NodeTag		type;
	char	   *relname;		/* relation to delete from */
	Node	   *whereClause;	/* qualifications */
834
	InhOption	inhOpt;			/* recursively act on children? */
835
} DeleteStmt;
836 837

/* ----------------------
838
 *		Update Statement
839 840
 * ----------------------
 */
Bruce Momjian's avatar
Bruce Momjian committed
841
typedef struct UpdateStmt
842
{
843 844 845 846 847
	NodeTag		type;
	char	   *relname;		/* relation to update */
	List	   *targetList;		/* the target list (of ResTarget) */
	Node	   *whereClause;	/* qualifications */
	List	   *fromClause;		/* the from clause */
848
	InhOption	inhOpt;			/* recursively act on children? */
Bruce Momjian's avatar
Bruce Momjian committed
849
} UpdateStmt;
850 851

/* ----------------------
852
 *		Select Statement
853 854 855 856 857 858 859 860 861
 *
 * 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.
862 863
 * ----------------------
 */
864 865 866 867 868 869 870 871
typedef enum SetOperation
{
	SETOP_NONE = 0,
	SETOP_UNION,
	SETOP_INTERSECT,
	SETOP_EXCEPT
} SetOperation;

Bruce Momjian's avatar
Bruce Momjian committed
872
typedef struct SelectStmt
873
{
874
	NodeTag		type;
875

876 877 878
	/*
	 * These fields are used only in "leaf" SelectStmts.
	 */
879 880 881
	List	   *distinctClause; /* NULL, list of DISTINCT ON exprs, or
								 * lcons(NIL,NIL) for all (SELECT
								 * DISTINCT) */
882
	char	   *into;			/* name of table (for select into table) */
883
	bool		istemp;			/* into is a temp table? */
884
	List	   *targetList;		/* the target list (of ResTarget) */
885 886
	List	   *fromClause;		/* the FROM clause */
	Node	   *whereClause;	/* WHERE qualification */
887
	List	   *groupClause;	/* GROUP BY clauses */
888
	Node	   *havingClause;	/* HAVING conditional-expression */
889

890 891 892 893
	/*
	 * These fields are used in both "leaf" SelectStmts and upper-level
	 * SelectStmts.  portalname/binary may only be set at the top level.
	 */
894
	List	   *sortClause;		/* sort clause (a list of SortGroupBy's) */
895 896
	char	   *portalname;		/* the portal (cursor) to create */
	bool		binary;			/* a binary (internal) portal? */
Bruce Momjian's avatar
Bruce Momjian committed
897 898
	Node	   *limitOffset;	/* # of result tuples to skip */
	Node	   *limitCount;		/* # of result tuples to return */
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
899
	List	   *forUpdate;		/* FOR UPDATE clause */
900

901 902 903 904 905 906 907 908
	/*
	 * 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 */
Bruce Momjian's avatar
Bruce Momjian committed
909
} SelectStmt;
910

911
/* ----------------------
912
 *		Set Operation node for post-analysis query trees
913
 *
914 915 916 917 918
 * 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.
919 920 921 922 923 924 925 926 927 928 929
 * ----------------------
 */
typedef struct SetOperationStmt
{
	NodeTag		type;
	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 */

930
	/* Fields derived during parse analysis: */
931 932
	List	   *colTypes;		/* integer list of OIDs of output column
								 * types */
933 934
} SetOperationStmt;

935
/****************************************************************************
936
 *	Supporting data structures for Parse Trees
937 938
 *
 *	Most of these node types appear in raw parsetrees output by the grammar,
939
 *	and get transformed to something else by the analyzer.	A few of them
940
 *	are used as-is in transformed querytrees.
941 942 943 944 945
 ****************************************************************************/

/*
 * TypeName - specifies a type in definitions
 */
946 947
typedef struct TypeName
{
948 949 950 951
	NodeTag		type;
	char	   *name;			/* name of the type */
	bool		timezone;		/* timezone specified? */
	bool		setof;			/* is a set? */
952
	int32		typmod;			/* type modifier */
953
	List	   *arrayBounds;	/* array bounds */
954
} TypeName;
955 956 957 958

/*
 * ParamNo - specifies a parameter reference
 */
959 960
typedef struct ParamNo
{
961 962 963
	NodeTag		type;
	int			number;			/* the number of the parameter */
	TypeName   *typename;		/* the typecast */
964
	List	   *indirection;	/* array references */
965
} ParamNo;
966 967 968 969

/*
 * A_Expr - binary expressions
 */
970 971
typedef struct A_Expr
{
972 973
	NodeTag		type;
	int			oper;			/* type of operation
974
								 * {OP,OR,AND,NOT,ISNULL,NOTNULL} */
975 976 977
	char	   *opname;			/* name of operator/function */
	Node	   *lexpr;			/* left argument */
	Node	   *rexpr;			/* right argument */
Bruce Momjian's avatar
Bruce Momjian committed
978
} A_Expr;
979 980 981

/*
 * Attr -
982 983
 *	  specifies an Attribute (ie. a Column); could have nested dots or
 *	  array references.
984 985
 *
 */
986 987
typedef struct Attr
{
988 989 990 991
	NodeTag		type;
	char	   *relname;		/* name of relation (can be "*") */
	ParamNo    *paramNo;		/* or a parameter */
	List	   *attrs;			/* attributes (possibly nested); list of
992
								 * Values (strings) */
993
	List	   *indirection;	/* array refs (list of A_Indices') */
Bruce Momjian's avatar
Bruce Momjian committed
994
} Attr;
995 996 997 998

/*
 * A_Const - a constant expression
 */
999 1000
typedef struct A_Const
{
1001 1002 1003
	NodeTag		type;
	Value		val;			/* the value (with the tag) */
	TypeName   *typename;		/* typecast */
Bruce Momjian's avatar
Bruce Momjian committed
1004
} A_Const;
1005

1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
/*
 * TypeCast - a CAST expression
 *
 * NOTE: for mostly historical reasons, A_Const and ParamNo parsenodes contain
 * room for a TypeName; we only generate a separate TypeCast node if the
 * argument to be casted is neither of those kinds of nodes.  In theory either
 * representation would work, but it is convenient (especially for A_Const)
 * to have the target type immediately available.
 */
typedef struct TypeCast
{
	NodeTag		type;
	Node	   *arg;			/* the expression being casted */
	TypeName   *typename;		/* the target type */
} TypeCast;

1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
/*
 * CaseExpr - a CASE expression
 */
typedef struct CaseExpr
{
	NodeTag		type;
	Oid			casetype;
	Node	   *arg;			/* implicit equality comparison argument */
	List	   *args;			/* the arguments (list of WHEN clauses) */
	Node	   *defresult;		/* the default result (ELSE clause) */
1032
} CaseExpr;
1033 1034 1035 1036 1037 1038 1039 1040 1041

/*
 * CaseWhen - an argument to a CASE expression
 */
typedef struct CaseWhen
{
	NodeTag		type;
	Node	   *expr;			/* comparison expression */
	Node	   *result;			/* substitution result */
1042
} CaseWhen;
1043

1044 1045
/*
 * ColumnDef - column definition (used in various creates)
1046 1047 1048 1049 1050
 *
 * 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
1051
 * inheritance from an existing relation).	We should never have both
1052 1053 1054 1055 1056 1057
 * 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.
1058
 */
1059 1060
typedef struct ColumnDef
{
1061 1062 1063 1064
	NodeTag		type;
	char	   *colname;		/* name of column */
	TypeName   *typename;		/* type of column */
	bool		is_not_null;	/* flag to NOT NULL constraint */
1065
	bool		is_sequence;	/* is a sequence? */
1066 1067 1068
	Node	   *raw_default;	/* default value (untransformed parse
								 * tree) */
	char	   *cooked_default; /* nodeToString representation */
1069
	List	   *constraints;	/* other constraints on column */
1070
} ColumnDef;
1071 1072

/*
1073 1074 1075 1076 1077 1078 1079 1080
 * Ident -
 *	  an identifier (could be an attribute or a relation name). Depending
 *	  on the context at transformStmt time, the identifier is treated as
 *	  either a relation name (in which case, isRel will be set) or an
 *	  attribute (in which case, it will be transformed into an Attr).
 */
typedef struct Ident
{
1081 1082 1083
	NodeTag		type;
	char	   *name;			/* its name */
	List	   *indirection;	/* array references */
1084
	bool		isRel;			/* is this a relation or a column? */
1085
} Ident;
1086 1087

/*
1088 1089 1090 1091 1092 1093
 * 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.
1094
 */
1095 1096
typedef struct FuncCall
{
1097 1098 1099
	NodeTag		type;
	char	   *funcname;		/* name of function */
	List	   *args;			/* the arguments (list of exprs) */
1100 1101
	bool		agg_star;		/* argument was really '*' */
	bool		agg_distinct;	/* arguments were labeled DISTINCT */
1102
} FuncCall;
1103 1104 1105 1106

/*
 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
 */
1107 1108
typedef struct A_Indices
{
1109 1110 1111
	NodeTag		type;
	Node	   *lidx;			/* could be NULL */
	Node	   *uidx;
Bruce Momjian's avatar
Bruce Momjian committed
1112
} A_Indices;
1113 1114

/*
1115 1116
 * ResTarget -
 *	  result target (used in target list of pre-transformed Parse trees)
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
 *
 * 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.
1127 1128 1129
 */
typedef struct ResTarget
{
1130
	NodeTag		type;
1131
	char	   *name;			/* column name or NULL */
1132 1133 1134 1135
	List	   *indirection;	/* subscripts for destination column, or
								 * NIL */
	Node	   *val;			/* the value expression to compute or
								 * assign */
1136
} ResTarget;
1137 1138

/*
1139
 * SortGroupBy - for ORDER BY clause
1140
 */
1141
typedef struct SortGroupBy
1142 1143 1144
{
	NodeTag		type;
	char	   *useOp;			/* operator to use */
1145
	Node	   *node;			/* Expression  */
1146 1147
} SortGroupBy;

1148
/*
1149
 * RangeVar - range variable, used in FROM clauses
1150
 */
1151 1152
typedef struct RangeVar
{
1153
	NodeTag		type;
1154
	char	   *relname;		/* the relation name */
1155
	InhOption	inhOpt;			/* expand rel by inheritance? */
1156
	Attr	   *name;			/* optional table alias & column aliases */
1157
} RangeVar;
1158

1159 1160 1161 1162 1163 1164 1165
/*
 * RangeSubselect - subquery appearing in a FROM clause
 */
typedef struct RangeSubselect
{
	NodeTag		type;
	Node	   *subquery;		/* the untransformed sub-select clause */
1166
	Attr	   *name;			/* table alias & optional column aliases */
1167 1168
} RangeSubselect;

1169
/*
1170
 * IndexElem - index parameters (used in CREATE INDEX)
1171 1172 1173 1174 1175
 *
 * For a plain index, each 'name' is an attribute name in the heap relation,
 * and 'args' is NIL.  For a functional index, only one IndexElem is allowed.
 * It has name = name of function and args = list of attribute names that
 * are the function's arguments.
1176
 */
1177 1178
typedef struct IndexElem
{
1179
	NodeTag		type;
1180 1181 1182
	char	   *name;			/* name of attribute to index, or function */
	List	   *args;			/* list of names of function arguments */
	char	   *class;			/* name of desired opclass; NULL = default */
1183
} IndexElem;
1184 1185 1186

/*
 * DefElem -
1187
 *	  a definition (used in definition lists in the form of defname = arg)
1188
 */
1189 1190
typedef struct DefElem
{
1191 1192 1193
	NodeTag		type;
	char	   *defname;
	Node	   *arg;			/* a (Value *) or a (TypeName *) */
1194
} DefElem;
1195 1196 1197


/****************************************************************************
1198
 *	Nodes for a Query tree
1199 1200 1201 1202
 ****************************************************************************/

/*
 * TargetEntry -
1203
 *	   a target  entry (used in the transformed target list)
1204 1205
 *
 * one of resdom or fjoin is not NULL. a target list is
1206
 *		((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
1207
 */
1208 1209
typedef struct TargetEntry
{
1210 1211 1212
	NodeTag		type;
	Resdom	   *resdom;			/* fjoin overload this to be a list?? */
	Fjoin	   *fjoin;
1213
	Node	   *expr;
1214
} TargetEntry;
1215

1216
/*--------------------
1217
 * RangeTblEntry -
1218 1219
 *	  A range table is a List of RangeTblEntry nodes.
 *
1220 1221 1222
 *	  Currently we use the same node type for both plain relation references
 *	  and sub-selects in the FROM clause.  It might be cleaner to abstract
 *	  the common fields into a "superclass" nodetype.
1223
 *
1224 1225 1226 1227
 *	  alias is an Attr node representing the AS alias-clause attached to the
 *	  FROM expression, or NULL if no clause.
 *
 *	  eref is the table reference name and column reference names (either
1228 1229 1230 1231 1232 1233 1234 1235
 *	  real or aliases).  Note that system columns (OID etc) are not included
 *	  in the column list.
 *	  eref->relname is required to be present, and should generally be used
 *	  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
 *	  subquery RTEs.
1236
 *
1237 1238 1239
 *	  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,
1240
 *	  in which case a range table entry will be generated.	We still support
1241 1242 1243 1244 1245
 *	  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 '*'.
1246 1247 1248 1249 1250 1251 1252
 *
 *	  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.)
1253
 *--------------------
1254 1255 1256
 */
typedef struct RangeTblEntry
{
1257
	NodeTag		type;
1258

1259 1260 1261
	/*
	 * Fields valid for a plain relation RTE (else NULL/zero):
	 */
1262
	char	   *relname;		/* real name of the relation */
1263
	Oid			relid;			/* OID of the relation */
1264

1265 1266 1267 1268
	/*
	 * Fields valid for a subquery RTE (else NULL):
	 */
	Query	   *subquery;		/* the sub-query */
1269

1270 1271 1272
	/*
	 * Fields valid in all RTEs:
	 */
1273 1274
	Attr	   *alias;			/* user-written alias clause, if any */
	Attr	   *eref;			/* expanded reference names */
1275 1276
	bool		inh;			/* inheritance requested? */
	bool		inFromCl;		/* present in FROM clause */
1277 1278 1279
	bool		checkForRead;	/* check rel for read access */
	bool		checkForWrite;	/* check rel for write access */
	Oid			checkAsUser;	/* if not zero, check access as this user */
1280
} RangeTblEntry;
1281 1282 1283

/*
 * SortClause -
1284 1285 1286 1287 1288
 *	   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.
1289 1290 1291 1292 1293 1294 1295
 *
 * 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.
1296
 */
1297 1298
typedef struct SortClause
{
1299
	NodeTag		type;
1300
	Index		tleSortGroupRef;/* reference into targetlist */
1301
	Oid			sortop;			/* the sort operator to use */
1302
} SortClause;
1303 1304 1305

/*
 * GroupClause -
1306 1307 1308
 *	   representation of GROUP BY clauses
 *
 * GroupClause is exactly like SortClause except for the nodetag value
1309
 * (it's probably not even really necessary to have two different
1310
 * nodetags...).  We have routines that operate interchangeably on both.
1311
 */
1312
typedef SortClause GroupClause;
1313

1314
#endif	 /* PARSENODES_H */