parsenodes.h 30.5 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * parsenodes.h
4
 *	  definitions for parse tree nodes
5 6 7 8
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
9
 * $Id: parsenodes.h,v 1.92 1999/12/16 17:24:19 momjian Exp $
10 11 12
 *
 *-------------------------------------------------------------------------
 */
13 14
#ifndef PARSENODES_H
#define PARSENODES_H
15

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

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

/*
 * Query -
24 25 26 27
 *	  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.
28 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 43 44 45
	int			resultRelation; /* target relation (index to rtable) */
	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
	bool		unionall;		/* union without unique sort */
48
	bool		hasAggs;		/* has aggregates in tlist or havingQual */
49
	bool		hasSubLinks;	/* has subquery SubLink */
50

51 52
	List	   *rtable;			/* list of range table entries */
	List	   *targetList;		/* target list (of TargetEntry) */
53
	Node	   *qual;			/* qualifications applied to tuples */
54
	List	   *rowMark;		/* list of RowMark entries */
55

56 57
	char	   *uniqueFlag;		/* NULL, '*', or Unique attribute name */
	List	   *sortClause;		/* a list of SortClause's */
58

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

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

63
	List	   *intersectClause;
64 65
	List	   *unionClause;	/* unions are linked under the previous
								 * query */
66

B
Bruce Momjian 已提交
67 68
	Node	   *limitOffset;	/* # of result tuples to skip */
	Node	   *limitCount;		/* # of result tuples to return */
B
Bruce Momjian 已提交
69

70
	/* internal to planner */
71 72
	List	   *base_rel_list;	/* list of base-relation RelOptInfos */
	List	   *join_rel_list;	/* list of join-relation RelOptInfos */
73
	List	   *query_pathkeys; /* pathkeys for query_planner()'s result */
74
} Query;
75 76 77


/*****************************************************************************
78
 *		Other Statements (no optimizations required)
79
 *
80 81 82 83
 *		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.
84 85 86
 *****************************************************************************/

/* ----------------------
87
 *		Add Column Statement
88 89
 * ----------------------
 */
90 91
typedef struct AddAttrStmt
{
92 93 94
	NodeTag		type;
	char	   *relname;		/* the relation to add attr */
	bool		inh;			/* add recursively to children? */
95
	Node	   *colDef;			/* the attribute definition */
B
Bruce Momjian 已提交
96
} AddAttrStmt;
97 98

/* ----------------------
99
 *		Change ACL Statement
100 101
 * ----------------------
 */
102 103
typedef struct ChangeACLStmt
{
104
	NodeTag		type;
105
	struct AclItem *aclitem;
106 107
	unsigned	modechg;
	List	   *relNames;
108
} ChangeACLStmt;
109 110

/* ----------------------
111
 *		Close Portal Statement
112 113
 * ----------------------
 */
114 115
typedef struct ClosePortalStmt
{
116 117
	NodeTag		type;
	char	   *portalname;		/* name of the portal (cursor) */
118
} ClosePortalStmt;
119 120

/* ----------------------
121
 *		Copy Statement
122 123
 * ----------------------
 */
124 125
typedef struct CopyStmt
{
126 127 128 129 130 131 132
	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 */
133
    char       *null_print;     /* how to print NULLs, `\N' by default */
134
} CopyStmt;
135 136

/* ----------------------
137
 *		Create Table Statement
138 139
 * ----------------------
 */
140 141
typedef struct CreateStmt
{
142
	NodeTag		type;
143
	bool		istemp;			/* is this a temp table? */
144 145 146 147 148
	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) */
	List	   *constraints;	/* list of constraints (Constraint nodes) */
149
} CreateStmt;
150

151
typedef enum ConstrType			/* types of constraints */
152
{
153 154
	CONSTR_NULL, CONSTR_NOTNULL, CONSTR_DEFAULT, CONSTR_CHECK,
	CONSTR_PRIMARY, CONSTR_UNIQUE
155
} ConstrType;
156

157 158 159 160 161 162 163 164 165
/*
 * 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!
 */

166
typedef struct Constraint
167
{
168 169
	NodeTag		type;
	ConstrType	contype;
170
	char	   *name;			/* name */
171 172 173
	Node	   *raw_expr;		/* untransformed parse tree */
	char	   *cooked_expr;	/* nodeToString representation */
	List	   *keys;			/* list of primary keys */
174
} Constraint;
175

J
Jan Wieck 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206

/* ----------
 * 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;
	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 */
} FkConstraint;


207
/* ----------------------
208
 *		Create/Drop TRIGGER Statements
209 210 211
 * ----------------------
 */

212 213
typedef struct CreateTrigStmt
{
214 215 216 217 218 219 220 221 222 223 224 225
	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 */
	char	   *lang;			/* NULL (which means Clanguage) */
	char	   *text;			/* AS 'text' */
	List	   *attr;			/* UPDATE OF a, b,... (NI) or NULL */
	char	   *when;			/* WHEN 'a > 10 ...' (NI) or NULL */
226 227 228 229 230 231 232

								/* 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} */
	char	   *constrrelname;	/* opposite relation */
233
} CreateTrigStmt;
234

235 236
typedef struct DropTrigStmt
{
237 238 239
	NodeTag		type;
	char	   *trigname;		/* TRIGGER' name */
	char	   *relname;		/* triggered relation */
240
} DropTrigStmt;
241 242 243 244 245 246 247 248 249 250 251 252 253


/* ----------------------
 *		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 */
254
} CreatePLangStmt;
255 256 257 258 259

typedef struct DropPLangStmt
{
	NodeTag		type;
	char	   *plname;			/* PL name */
260
} DropPLangStmt;
261

262

263
/* ----------------------
264
 *				Create/Alter/Drop User Statements
265 266 267 268
 * ----------------------
 */
typedef struct CreateUserStmt
{
269 270 271
	NodeTag		type;
	char	   *user;			/* PostgreSQL user login			  */
	char	   *password;		/* PostgreSQL user password			  */
B
Bruce Momjian 已提交
272
    int         sysid;          /* PgSQL system id (-1 if don't care) */
273 274 275 276
	bool	   *createdb;		/* Can the user create databases?	  */
	bool	   *createuser;		/* Can this user create users?		  */
	List	   *groupElts;		/* The groups the user is a member of */
	char	   *validUntil;		/* The time the login is valid until  */
277 278
} CreateUserStmt;

279
typedef CreateUserStmt AlterUserStmt;
280 281 282

typedef struct DropUserStmt
{
283 284
	NodeTag		type;
	char	   *user;			/* PostgreSQL user login			  */
285 286 287
} DropUserStmt;


288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
/* ----------------------
 *      Create/Alter/Drop Group Statements
 * ----------------------
 */
typedef struct CreateGroupStmt
{
    NodeTag     type;
    char       *name;           /* name of the new group */
    int         sysid;          /* group id (-1 if pick default) */
    List       *initUsers;      /* list of initial users */
} CreateGroupStmt;

typedef struct AlterGroupStmt
{
    NodeTag     type;
    char       *name;           /* name of group to alter */
    int         action;         /* +1 = add, -1 = drop, 0 = other (HACK!) */
    int         sysid;          /* sysid change */
    List       *listUsers;      /* list of users to add/drop */
} AlterGroupStmt;

typedef struct DropGroupStmt
{
    NodeTag     type;
    char       *name;
} DropGroupStmt;


V
Vadim B. Mikheev 已提交
316
/* ----------------------
317
 *		Create SEQUENCE Statement
V
Vadim B. Mikheev 已提交
318 319 320
 * ----------------------
 */

321 322
typedef struct CreateSeqStmt
{
323 324 325
	NodeTag		type;
	char	   *seqname;		/* the relation to create */
	List	   *options;
326
} CreateSeqStmt;
V
Vadim B. Mikheev 已提交
327

328
/* ----------------------
329
 *		Create Version Statement
330 331
 * ----------------------
 */
332 333
typedef struct VersionStmt
{
334 335 336 337 338
	NodeTag		type;
	char	   *relname;		/* the new relation */
	int			direction;		/* FORWARD | BACKWARD */
	char	   *fromRelname;	/* relation to create a version */
	char	   *date;			/* date of the snapshot */
339
} VersionStmt;
340 341

/* ----------------------
342
 *		Create {Operator|Type|Aggregate} Statement
343 344
 * ----------------------
 */
345 346
typedef struct DefineStmt
{
347 348 349 350
	NodeTag		type;
	int			defType;		/* OPERATOR|P_TYPE|AGGREGATE */
	char	   *defname;
	List	   *definition;		/* a list of DefElem */
351
} DefineStmt;
352 353

/* ----------------------
354
 *		Drop Table Statement
355 356
 * ----------------------
 */
357
typedef struct DropStmt
358
{
359 360 361
	NodeTag		type;
	List	   *relNames;		/* relations to be dropped */
	bool		sequence;
362
} DropStmt;
363

364 365 366 367 368 369 370 371 372
/* ----------------------
 *              Truncate Table Statement
 * ----------------------
 */
typedef struct TruncateStmt
{
        NodeTag         type;
        char	   *relName;            /* relation to be truncated */
} TruncateStmt;
373 374 375 376 377 378 379

/* ----------------------
 *              Comment On Statement
 * ----------------------
 */
typedef struct CommentStmt
{
B
Hello.  
Bruce Momjian 已提交
380 381 382 383 384 385
  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 */
386
} CommentStmt;
387
      
388
/* ----------------------
389
 *		Extend Index Statement
390 391
 * ----------------------
 */
392 393
typedef struct ExtendStmt
{
394 395 396 397
	NodeTag		type;
	char	   *idxname;		/* name of the index */
	Node	   *whereClause;	/* qualifications */
	List	   *rangetable;		/* range table, filled in by
398
								 * transformStmt() */
399
} ExtendStmt;
400 401

/* ----------------------
402
 *		Begin Recipe Statement
403 404
 * ----------------------
 */
405 406
typedef struct RecipeStmt
{
407 408
	NodeTag		type;
	char	   *recipeName;		/* name of the recipe */
409
} RecipeStmt;
410 411

/* ----------------------
412
 *		Fetch Statement
413 414
 * ----------------------
 */
415 416
typedef struct FetchStmt
{
417 418 419 420
	NodeTag		type;
	int			direction;		/* FORWARD or BACKWARD */
	int			howMany;		/* amount to fetch ("ALL" --> 0) */
	char	   *portalname;		/* name of portal (cursor) */
421
	bool		ismove;			/* TRUE if MOVE */
422
} FetchStmt;
423 424

/* ----------------------
425
 *		Create Index Statement
426 427
 * ----------------------
 */
428 429
typedef struct IndexStmt
{
430 431 432 433 434
	NodeTag		type;
	char	   *idxname;		/* name of the index */
	char	   *relname;		/* name of relation to index on */
	char	   *accessMethod;	/* name of acess methood (eg. btree) */
	List	   *indexParams;	/* a list of IndexElem */
435
	List	   *withClause;		/* a list of DefElem */
436 437
	Node	   *whereClause;	/* qualifications */
	List	   *rangetable;		/* range table, filled in by
438
								 * transformStmt() */
439 440
	bool	   *lossy;			/* is index lossy? */
	bool		unique;			/* is index unique? */
441
	bool		primary;		/* is index on primary key? */
442
} IndexStmt;
443 444

/* ----------------------
445
 *		Create Function Statement
446 447
 * ----------------------
 */
448 449
typedef struct ProcedureStmt
{
450 451 452
	NodeTag		type;
	char	   *funcname;		/* name of function to create */
	List	   *defArgs;		/* list of definitions a list of strings
453
								 * (as Value *) */
454
	Node	   *returnType;		/* the return type (as a string or a
455
								 * TypeName (ie.setof) */
456
	List	   *withClause;		/* a list of DefElem */
457
	List	   *as;				/* the SQL statement or filename */
458
	char	   *language;		/* C or SQL */
459
} ProcedureStmt;
460

461
/* ----------------------
462
 *		Drop Aggregate Statement
463 464
 * ----------------------
 */
465 466
typedef struct RemoveAggrStmt
{
467 468 469
	NodeTag		type;
	char	   *aggname;		/* aggregate to drop */
	char	   *aggtype;		/* for this type */
470
} RemoveAggrStmt;
471

472
/* ----------------------
473
 *		Drop Function Statement
474 475
 * ----------------------
 */
476 477
typedef struct RemoveFuncStmt
{
478 479 480
	NodeTag		type;
	char	   *funcname;		/* function to drop */
	List	   *args;			/* types of the arguments */
481
} RemoveFuncStmt;
482 483

/* ----------------------
484
 *		Drop Operator Statement
485 486
 * ----------------------
 */
487 488
typedef struct RemoveOperStmt
{
489 490 491
	NodeTag		type;
	char	   *opname;			/* operator to drop */
	List	   *args;			/* types of the arguments */
492
} RemoveOperStmt;
493 494

/* ----------------------
495
 *		Drop {Type|Index|Rule|View} Statement
496 497
 * ----------------------
 */
498 499
typedef struct RemoveStmt
{
500 501 502
	NodeTag		type;
	int			removeType;		/* P_TYPE|INDEX|RULE|VIEW */
	char	   *name;			/* name to drop */
503
} RemoveStmt;
504 505

/* ----------------------
506
 *		Alter Table Statement
507 508
 * ----------------------
 */
509 510
typedef struct RenameStmt
{
511 512 513 514
	NodeTag		type;
	char	   *relname;		/* relation to be altered */
	bool		inh;			/* recursively alter children? */
	char	   *column;			/* if NULL, rename the relation name to
515 516
								 * the new name. Otherwise, rename this
								 * column name. */
517
	char	   *newname;		/* the new name */
518
} RenameStmt;
519 520

/* ----------------------
521
 *		Create Rule Statement
522 523
 * ----------------------
 */
524 525
typedef struct RuleStmt
{
526 527 528 529 530 531 532
	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 */
533
} RuleStmt;
534 535

/* ----------------------
536
 *		Notify Statement
537 538
 * ----------------------
 */
539 540
typedef struct NotifyStmt
{
541 542
	NodeTag		type;
	char	   *relname;		/* relation to notify */
543
} NotifyStmt;
544 545

/* ----------------------
546
 *		Listen Statement
547 548
 * ----------------------
 */
549 550
typedef struct ListenStmt
{
551 552
	NodeTag		type;
	char	   *relname;		/* relation to listen on */
553
} ListenStmt;
M
 
Marc G. Fournier 已提交
554 555 556 557 558 559 560 561 562

/* ----------------------
 *		Unlisten Statement
 * ----------------------
 */
typedef struct UnlistenStmt
{
	NodeTag		type;
	char	   *relname;		/* relation to unlisten on */
563
} UnlistenStmt;
564 565

/* ----------------------
566
 *		{Begin|Abort|End} Transaction Statement
567 568
 * ----------------------
 */
569 570
typedef struct TransactionStmt
{
571 572
	NodeTag		type;
	int			command;		/* BEGIN|END|ABORT */
573
} TransactionStmt;
574 575

/* ----------------------
576
 *		Create View Statement
577 578
 * ----------------------
 */
579 580
typedef struct ViewStmt
{
581 582 583
	NodeTag		type;
	char	   *viewname;		/* name of the view */
	Query	   *query;			/* the SQL statement */
584
} ViewStmt;
585 586

/* ----------------------
587
 *		Load Statement
588 589
 * ----------------------
 */
590 591
typedef struct LoadStmt
{
592 593
	NodeTag		type;
	char	   *filename;		/* file to load */
594
} LoadStmt;
595 596

/* ----------------------
597
 *		Createdb Statement
598 599
 * ----------------------
 */
600 601
typedef struct CreatedbStmt
{
602 603
	NodeTag		type;
	char	   *dbname;			/* database to create */
604
	char	   *dbpath;			/* location of database */
605
	int			encoding;		/* default encoding (see regex/pg_wchar.h) */
606
} CreatedbStmt;
607 608

/* ----------------------
609
 *		Dropdb Statement
610 611
 * ----------------------
 */
612
typedef struct DropdbStmt
613
{
614 615
	NodeTag		type;
	char	   *dbname;			/* database to drop */
616
} DropdbStmt;
617 618

/* ----------------------
619
 *		Cluster Statement (support pbrown's cluster index implementation)
620 621
 * ----------------------
 */
622 623
typedef struct ClusterStmt
{
624 625 626
	NodeTag		type;
	char	   *relname;		/* relation being indexed */
	char	   *indexname;		/* original index defined */
627
} ClusterStmt;
628 629

/* ----------------------
630
 *		Vacuum Statement
631 632
 * ----------------------
 */
633 634
typedef struct VacuumStmt
{
635 636 637 638 639
	NodeTag		type;
	bool		verbose;		/* print status info */
	bool		analyze;		/* analyze data */
	char	   *vacrel;			/* table to vacuum */
	List	   *va_spec;		/* columns to analyse */
640
} VacuumStmt;
641 642

/* ----------------------
643
 *		Explain Statement
644 645
 * ----------------------
 */
646 647
typedef struct ExplainStmt
{
648 649 650
	NodeTag		type;
	Query	   *query;			/* the query */
	bool		verbose;		/* print plan info */
651
} ExplainStmt;
652

653 654 655 656 657
/* ----------------------
 * Set Statement
 * ----------------------
 */

658 659
typedef struct VariableSetStmt
{
660 661 662
	NodeTag		type;
	char	   *name;
	char	   *value;
663
} VariableSetStmt;
664 665 666 667 668 669

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

670 671
typedef struct VariableShowStmt
{
672 673
	NodeTag		type;
	char	   *name;
674
} VariableShowStmt;
675 676 677 678 679 680

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

681 682
typedef struct VariableResetStmt
{
683 684
	NodeTag		type;
	char	   *name;
685
} VariableResetStmt;
686

687 688 689 690 691 692 693 694 695
/* ----------------------
 *		LOCK Statement
 * ----------------------
 */
typedef struct LockStmt
{
	NodeTag		type;
	char	   *relname;		/* relation to lock */
	int			mode;			/* lock mode */
696
} LockStmt;
697

698 699 700 701 702 703 704 705 706 707 708 709 710

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


711
/*****************************************************************************
712
 *		Optimizable Statements
713 714 715
 *****************************************************************************/

/* ----------------------
716
 *		Insert Statement
717 718
 * ----------------------
 */
B
Bruce Momjian 已提交
719
typedef struct InsertStmt
720
{
721 722
	NodeTag		type;
	char	   *relname;		/* relation to insert into */
723
	char	   *unique;			/* NULL, '*', or unique attribute name */
724 725 726 727
	List	   *cols;			/* names of the columns */
	List	   *targetList;		/* the target list (of ResTarget) */
	List	   *fromClause;		/* the from clause */
	Node	   *whereClause;	/* qualifications */
728
	List	   *groupClause;	/* GROUP BY clauses */
729 730
	Node	   *havingClause;	/* having conditional-expression */
	List	   *unionClause;	/* union subselect parameters */
731
	bool		unionall;		/* union without unique sort */
B
Bruce Momjian 已提交
732
	List	   *intersectClause;
733
	List	   *forUpdate;		/* FOR UPDATE clause */
B
Bruce Momjian 已提交
734
} InsertStmt;
735 736

/* ----------------------
737
 *		Delete Statement
738 739
 * ----------------------
 */
740 741
typedef struct DeleteStmt
{
742 743 744
	NodeTag		type;
	char	   *relname;		/* relation to delete from */
	Node	   *whereClause;	/* qualifications */
745
} DeleteStmt;
746 747

/* ----------------------
748
 *		Update Statement
749 750
 * ----------------------
 */
B
Bruce Momjian 已提交
751
typedef struct UpdateStmt
752
{
753 754 755 756 757
	NodeTag		type;
	char	   *relname;		/* relation to update */
	List	   *targetList;		/* the target list (of ResTarget) */
	Node	   *whereClause;	/* qualifications */
	List	   *fromClause;		/* the from clause */
B
Bruce Momjian 已提交
758
} UpdateStmt;
759 760

/* ----------------------
761
 *		Select Statement
762 763
 * ----------------------
 */
B
Bruce Momjian 已提交
764
typedef struct SelectStmt
765
{
766 767 768 769 770 771
	NodeTag		type;
	char	   *unique;			/* NULL, '*', or unique attribute name */
	char	   *into;			/* name of table (for select into table) */
	List	   *targetList;		/* the target list (of ResTarget) */
	List	   *fromClause;		/* the from clause */
	Node	   *whereClause;	/* qualifications */
772
	List	   *groupClause;	/* GROUP BY clauses */
773
	Node	   *havingClause;	/* having conditional-expression */
774 775 776
	List	   *intersectClause;
	List	   *exceptClause;

777
	List	   *unionClause;	/* union subselect parameters */
778
	List	   *sortClause;		/* sort clause (a list of SortGroupBy's) */
779 780
	char	   *portalname;		/* the portal (cursor) to create */
	bool		binary;			/* a binary (internal) portal? */
781
	bool		istemp;			/* into is a temp table */
782
	bool		unionall;		/* union without unique sort */
B
Bruce Momjian 已提交
783 784
	Node	   *limitOffset;	/* # of result tuples to skip */
	Node	   *limitCount;		/* # of result tuples to return */
V
Vadim B. Mikheev 已提交
785
	List	   *forUpdate;		/* FOR UPDATE clause */
B
Bruce Momjian 已提交
786
} SelectStmt;
787 788

/****************************************************************************
789
 *	Supporting data structures for Parse Trees
790 791 792 793
 *
 *	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.
794 795 796 797 798
 ****************************************************************************/

/*
 * TypeName - specifies a type in definitions
 */
799 800
typedef struct TypeName
{
801 802 803 804
	NodeTag		type;
	char	   *name;			/* name of the type */
	bool		timezone;		/* timezone specified? */
	bool		setof;			/* is a set? */
805
	int32		typmod;			/* type modifier */
806
	List	   *arrayBounds;	/* array bounds */
807
} TypeName;
808 809 810 811

/*
 * ParamNo - specifies a parameter reference
 */
812 813
typedef struct ParamNo
{
814 815 816
	NodeTag		type;
	int			number;			/* the number of the parameter */
	TypeName   *typename;		/* the typecast */
817
	List	   *indirection;	/* array references */
818
} ParamNo;
819 820 821 822

/*
 * A_Expr - binary expressions
 */
823 824
typedef struct A_Expr
{
825 826
	NodeTag		type;
	int			oper;			/* type of operation
827
								 * {OP,OR,AND,NOT,ISNULL,NOTNULL} */
828 829 830
	char	   *opname;			/* name of operator/function */
	Node	   *lexpr;			/* left argument */
	Node	   *rexpr;			/* right argument */
B
Bruce Momjian 已提交
831
} A_Expr;
832 833 834

/*
 * Attr -
835 836
 *	  specifies an Attribute (ie. a Column); could have nested dots or
 *	  array references.
837 838
 *
 */
839 840
typedef struct Attr
{
841 842 843 844
	NodeTag		type;
	char	   *relname;		/* name of relation (can be "*") */
	ParamNo    *paramNo;		/* or a parameter */
	List	   *attrs;			/* attributes (possibly nested); list of
845
								 * Values (strings) */
846
	List	   *indirection;	/* array refs (list of A_Indices') */
B
Bruce Momjian 已提交
847
} Attr;
848 849 850 851

/*
 * A_Const - a constant expression
 */
852 853
typedef struct A_Const
{
854 855 856
	NodeTag		type;
	Value		val;			/* the value (with the tag) */
	TypeName   *typename;		/* typecast */
B
Bruce Momjian 已提交
857
} A_Const;
858

T
Thomas G. Lockhart 已提交
859 860 861 862 863 864 865 866 867 868
/*
 * 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) */
869
} CaseExpr;
T
Thomas G. Lockhart 已提交
870 871 872 873 874 875 876 877 878

/*
 * CaseWhen - an argument to a CASE expression
 */
typedef struct CaseWhen
{
	NodeTag		type;
	Node	   *expr;			/* comparison expression */
	Node	   *result;			/* substitution result */
879
} CaseWhen;
T
Thomas G. Lockhart 已提交
880

881 882
/*
 * ColumnDef - column definition (used in various creates)
883 884 885 886 887 888 889 890 891 892 893 894
 *
 * 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.
895
 */
896 897
typedef struct ColumnDef
{
898 899 900 901
	NodeTag		type;
	char	   *colname;		/* name of column */
	TypeName   *typename;		/* type of column */
	bool		is_not_null;	/* flag to NOT NULL constraint */
902
	bool		is_sequence;	/* is a sequence? */
903 904 905
	Node	   *raw_default;	/* default value (untransformed parse tree) */
	char	   *cooked_default;	/* nodeToString representation */
	List	   *constraints;	/* other constraints on column */
906
} ColumnDef;
907 908

/*
909 910 911 912 913 914 915 916
 * 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
{
917 918 919 920
	NodeTag		type;
	char	   *name;			/* its name */
	List	   *indirection;	/* array references */
	bool		isRel;			/* is a relation - filled in by
921
								 * transformExpr() */
922
} Ident;
923 924

/*
925 926 927 928 929 930
 * 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.
931
 */
932 933
typedef struct FuncCall
{
934 935 936
	NodeTag		type;
	char	   *funcname;		/* name of function */
	List	   *args;			/* the arguments (list of exprs) */
937 938
	bool		agg_star;		/* argument was really '*' */
	bool		agg_distinct;	/* arguments were labeled DISTINCT */
939
} FuncCall;
940 941 942 943

/*
 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
 */
944 945
typedef struct A_Indices
{
946 947 948
	NodeTag		type;
	Node	   *lidx;			/* could be NULL */
	Node	   *uidx;
B
Bruce Momjian 已提交
949
} A_Indices;
950 951

/*
952 953
 * ResTarget -
 *	  result target (used in target list of pre-transformed Parse trees)
954 955 956 957 958 959 960 961 962 963
 *
 * 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.
964 965 966
 */
typedef struct ResTarget
{
967
	NodeTag		type;
968
	char	   *name;			/* column name or NULL */
969 970 971 972
	List	   *indirection;	/* subscripts for destination column, or
								 * NIL */
	Node	   *val;			/* the value expression to compute or
								 * assign */
973
} ResTarget;
974 975 976 977

/*
 * RelExpr - relation expressions
 */
978 979
typedef struct RelExpr
{
980 981 982
	NodeTag		type;
	char	   *relname;		/* the relation name */
	bool		inh;			/* inheritance query */
983
} RelExpr;
984 985

/*
T
Thomas G. Lockhart 已提交
986
 * SortGroupBy - for ORDER BY clause
987
 */
988
typedef struct SortGroupBy
M
 
Marc G. Fournier 已提交
989 990 991
{
	NodeTag		type;
	char	   *useOp;			/* operator to use */
992
	Node	   *node;			/* Expression  */
M
 
Marc G. Fournier 已提交
993 994
} SortGroupBy;

995
/*
T
Thomas G. Lockhart 已提交
996
 * RangeVar - range variable, used in FROM clauses
997
 */
998 999
typedef struct RangeVar
{
1000 1001 1002
	NodeTag		type;
	RelExpr    *relExpr;		/* the relation expression */
	char	   *name;			/* the name to be referenced (optional) */
1003
} RangeVar;
1004 1005

/*
T
Thomas G. Lockhart 已提交
1006
 * IndexElem - index parameters (used in CREATE INDEX)
1007
 */
1008 1009
typedef struct IndexElem
{
1010 1011 1012 1013
	NodeTag		type;
	char	   *name;			/* name of index */
	List	   *args;			/* if not NULL, function index */
	char	   *class;
1014
	TypeName   *typename;		/* type of index's keys (optional) */
1015
} IndexElem;
1016 1017 1018

/*
 * DefElem -
1019
 *	  a definition (used in definition lists in the form of defname = arg)
1020
 */
1021 1022
typedef struct DefElem
{
1023 1024 1025
	NodeTag		type;
	char	   *defname;
	Node	   *arg;			/* a (Value *) or a (TypeName *) */
1026
} DefElem;
1027

1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
/*
 * JoinExpr - for JOIN expressions
 */
typedef struct JoinExpr
{
	NodeTag		type;
	int			jointype;
	RangeVar   *larg;
	Node	   *rarg;
	List	   *quals;
1038
} JoinExpr;
1039

1040 1041

/****************************************************************************
1042
 *	Nodes for a Query tree
1043 1044 1045 1046
 ****************************************************************************/

/*
 * TargetEntry -
1047
 *	   a target  entry (used in the transformed target list)
1048 1049
 *
 * one of resdom or fjoin is not NULL. a target list is
1050
 *		((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
1051
 */
1052 1053
typedef struct TargetEntry
{
1054 1055 1056
	NodeTag		type;
	Resdom	   *resdom;			/* fjoin overload this to be a list?? */
	Fjoin	   *fjoin;
1057
	Node	   *expr;
1058
} TargetEntry;
1059

1060
/*--------------------
1061
 * RangeTblEntry -
1062 1063 1064
 *	  A range table is a List of RangeTblEntry nodes.
 *
 *	  Some of the following are only used in one of
1065
 *	  the parsing, optimizing, execution stages.
1066
 *
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
 *	  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 '*'.
 *
 *	  inJoinSet marks those range variables that the planner should join
 *	  over even if they aren't explicitly referred to in the query.  For
 *	  example, "SELECT COUNT(1) FROM tx" should produce the number of rows
 *	  in tx.  A more subtle example uses a POSTQUEL implicit RTE:
 *			SELECT COUNT(1) FROM tx WHERE TRUE OR (tx.f1 = ty.f2)
 *	  Here we should get the product of the sizes of tx and ty.  However,
 *	  the query optimizer can simplify the WHERE clause to "TRUE", so
 *	  ty will no longer be referred to explicitly; without a flag forcing
 *	  it to be included in the join, we will get the wrong answer.  So,
 *	  a POSTQUEL implicit RTE must be marked inJoinSet but not inFromCl.
 *--------------------
1088 1089 1090
 */
typedef struct RangeTblEntry
{
1091 1092
	NodeTag		type;
	char	   *relname;		/* real name of the relation */
1093 1094 1095 1096 1097 1098
	char	   *refname;		/* the reference name (as specified in the
								 * FROM clause) */
	Oid			relid;			/* OID of the relation */
	bool		inh;			/* inheritance requested? */
	bool		inFromCl;		/* present in FROM clause */
	bool		inJoinSet;		/* planner must include this rel */
M
Marc G. Fournier 已提交
1099
	bool		skipAcl;		/* skip ACL check in executor */
1100
} RangeTblEntry;
1101 1102 1103

/*
 * SortClause -
1104 1105 1106 1107 1108
 *	   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.
1109
 */
1110 1111
typedef struct SortClause
{
1112
	NodeTag		type;
1113
	Index		tleSortGroupRef;/* reference into targetlist */
1114
	Oid			sortop;			/* the sort operator to use */
1115
} SortClause;
1116 1117 1118

/*
 * GroupClause -
1119 1120 1121 1122 1123
 *	   representation of GROUP BY clauses
 *
 * GroupClause is exactly like SortClause except for the nodetag value
 * (and it's probably not even really necessary to have two different
 * nodetags...).  We have routines that operate interchangeably on both.
1124
 */
1125
typedef SortClause GroupClause;
1126

B
Bruce Momjian 已提交
1127 1128
#define ROW_MARK_FOR_UPDATE		(1 << 0)
#define ROW_ACL_FOR_UPDATE		(1 << 1)
1129 1130 1131

typedef struct RowMark
{
B
Bruce Momjian 已提交
1132 1133 1134
	NodeTag		type;
	Index		rti;			/* index in Query->rtable */
	bits8		info;			/* as above */
1135
} RowMark;
1136

1137
#endif	 /* PARSENODES_H */