OSDN Git Service

Implement column aliases on views "CREATE VIEW name (collist)".
[pg-rex/syncrep.git] / src / include / nodes / parsenodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * parsenodes.h
4  *        definitions for parse tree nodes
5  *
6  *
7  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: parsenodes.h,v 1.102 2000/03/14 23:06:47 thomas Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PARSENODES_H
15 #define PARSENODES_H
16
17 #include "nodes/primnodes.h"
18
19 /*****************************************************************************
20  *      Query Tree
21  *****************************************************************************/
22
23 /*
24  * Query -
25  *        all statments are turned into a Query tree (via transformStmt)
26  *        for further processing by the optimizer
27  *        utility statements (i.e. non-optimizable statements)
28  *        have the *utilityStmt field set.
29  *
30  * we need the isPortal flag because portal names can be null too; can
31  * get rid of it if we support CURSOR as a commandType.
32  *
33  */
34 typedef struct Query
35 {
36         NodeTag         type;
37
38         CmdType         commandType;    /* select|insert|update|delete|utility */
39
40         Node       *utilityStmt;        /* non-null if this is a non-optimizable
41                                                                  * statement */
42
43         int                     resultRelation; /* target relation (index to rtable) */
44         char       *into;                       /* portal (cursor) name */
45         bool            isPortal;               /* is this a retrieve into portal? */
46         bool            isBinary;               /* binary portal? */
47         bool            isTemp;                 /* is 'into' a temp table? */
48         bool            unionall;               /* union without unique sort */
49         bool            hasAggs;                /* has aggregates in tlist or havingQual */
50         bool            hasSubLinks;    /* has subquery SubLink */
51
52         List       *rtable;                     /* list of range table entries */
53         List       *targetList;         /* target list (of TargetEntry) */
54         Node       *qual;                       /* qualifications applied to tuples */
55         List       *rowMark;            /* list of RowMark entries */
56
57         List       *distinctClause;     /* a list of SortClause's */
58
59         List       *sortClause;         /* a list of SortClause's */
60
61         List       *groupClause;        /* a list of GroupClause's */
62
63         Node       *havingQual;         /* qualifications applied to groups */
64
65         List       *intersectClause;
66         List       *unionClause;        /* unions are linked under the previous
67                                                                  * query */
68
69         Node       *limitOffset;        /* # of result tuples to skip */
70         Node       *limitCount;         /* # of result tuples to return */
71
72         /* internal to planner */
73         List       *base_rel_list;      /* list of base-relation RelOptInfos */
74         List       *join_rel_list;      /* list of join-relation RelOptInfos */
75         List       *equi_key_list;      /* list of lists of equijoined PathKeyItems */
76         List       *query_pathkeys; /* pathkeys for query_planner()'s result */
77 } Query;
78
79
80 /*****************************************************************************
81  *              Other Statements (no optimizations required)
82  *
83  *              Some of them require a little bit of transformation (which is also
84  *              done by transformStmt). The whole structure is then passed on to
85  *              ProcessUtility (by-passing the optimization step) as the utilityStmt
86  *              field in Query.
87  *****************************************************************************/
88
89 /* ----------------------
90  *      Alter Table
91  * ----------------------
92  */
93 /* The fields are used in different ways by the different variants of this command */
94 typedef struct AlterTableStmt
95 {
96         NodeTag         type;
97     char        subtype;        /* A = add, T = alter, D = drop, C = add constr, X = drop constr */
98         char       *relname;        /* table to work on */
99         bool            inh;                    /* recursively on children? */
100     char       *name;           /* column or constraint name to act on */
101     Node       *def;            /* definition of new column or constraint */
102     int         behavior;       /* CASCADE or RESTRICT drop behavior */
103 } AlterTableStmt;
104
105 /* ----------------------
106  *              Change ACL Statement
107  * ----------------------
108  */
109 typedef struct ChangeACLStmt
110 {
111         NodeTag         type;
112         struct AclItem *aclitem;
113         unsigned        modechg;
114         List       *relNames;
115 } ChangeACLStmt;
116
117 /* ----------------------
118  *              Close Portal Statement
119  * ----------------------
120  */
121 typedef struct ClosePortalStmt
122 {
123         NodeTag         type;
124         char       *portalname;         /* name of the portal (cursor) */
125 } ClosePortalStmt;
126
127 /* ----------------------
128  *              Copy Statement
129  * ----------------------
130  */
131 typedef struct CopyStmt
132 {
133         NodeTag         type;
134         bool            binary;                 /* is a binary copy? */
135         char       *relname;            /* the relation to copy */
136         bool            oids;                   /* copy oid's? */
137         int                     direction;              /* TO or FROM */
138         char       *filename;           /* if NULL, use stdin/stdout */
139         char       *delimiter;          /* delimiter character, \t by default */
140     char       *null_print;     /* how to print NULLs, `\N' by default */
141 } CopyStmt;
142
143 /* ----------------------
144  *              Create Table Statement
145  * ----------------------
146  */
147 typedef struct CreateStmt
148 {
149         NodeTag         type;
150         bool            istemp;                 /* is this a temp table? */
151         char       *relname;            /* name of relation to create */
152         List       *tableElts;          /* column definitions (list of ColumnDef) */
153         List       *inhRelnames;        /* relations to inherit from (list of
154                                                                  * T_String Values) */
155         List       *constraints;        /* constraints (list of Constraint and
156                                                                  * FkConstraint nodes) */
157 } CreateStmt;
158
159 /* ----------
160  * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
161  *
162  * XXX probably these ought to be unified with FkConstraints at some point?
163  *
164  * For constraints that use expressions (CONSTR_DEFAULT, CONSTR_CHECK)
165  * we may have the expression in either "raw" form (an untransformed
166  * parse tree) or "cooked" form (the nodeToString representation of
167  * an executable expression tree), depending on how this Constraint
168  * node was created (by parsing, or by inheritance from an existing
169  * relation).  We should never have both in the same node!
170  *
171  * Constraint attributes (DEFERRABLE etc) are initially represented as
172  * separate Constraint nodes for simplicity of parsing.  analyze.c makes
173  * a pass through the constraints list to attach the info to the appropriate
174  * FkConstraint node (and, perhaps, someday to other kinds of constraints).
175  * ----------
176  */
177
178 typedef enum ConstrType                 /* types of constraints */
179 {
180         CONSTR_NULL,                            /* not SQL92, but a lot of people expect it */
181         CONSTR_NOTNULL,
182         CONSTR_DEFAULT,
183         CONSTR_CHECK,
184         CONSTR_PRIMARY,
185         CONSTR_UNIQUE,
186         CONSTR_ATTR_DEFERRABLE,         /* attributes for previous constraint node */
187         CONSTR_ATTR_NOT_DEFERRABLE,
188         CONSTR_ATTR_DEFERRED,
189         CONSTR_ATTR_IMMEDIATE
190 } ConstrType;
191
192 typedef struct Constraint
193 {
194         NodeTag         type;
195         ConstrType      contype;
196         char       *name;                       /* name, or NULL if unnamed */
197         Node       *raw_expr;           /* expr, as untransformed parse tree */
198         char       *cooked_expr;        /* expr, as nodeToString representation */
199         List       *keys;                       /* list of primary keys (or unique columns) */
200 } Constraint;
201
202
203 /* ----------
204  * Definitions for FOREIGN KEY constraints in CreateStmt
205  * ----------
206  */
207 #define FKCONSTR_ON_KEY_NOACTION                0x0000
208 #define FKCONSTR_ON_KEY_RESTRICT                0x0001
209 #define FKCONSTR_ON_KEY_CASCADE                 0x0002
210 #define FKCONSTR_ON_KEY_SETNULL                 0x0004
211 #define FKCONSTR_ON_KEY_SETDEFAULT              0x0008
212
213 #define FKCONSTR_ON_DELETE_MASK                 0x000F
214 #define FKCONSTR_ON_DELETE_SHIFT                0
215
216 #define FKCONSTR_ON_UPDATE_MASK                 0x00F0
217 #define FKCONSTR_ON_UPDATE_SHIFT                4
218
219 typedef struct FkConstraint
220 {
221         NodeTag         type;
222         char       *constr_name;                /* Constraint name */
223         char       *pktable_name;               /* Primary key table name */
224         List       *fk_attrs;                   /* Attributes of foreign key */
225         List       *pk_attrs;                   /* Corresponding attrs in PK table */
226         char       *match_type;                 /* FULL or PARTIAL */
227         int32           actions;                        /* ON DELETE/UPDATE actions */
228         bool            deferrable;                     /* DEFERRABLE */
229         bool            initdeferred;           /* INITIALLY DEFERRED */
230 } FkConstraint;
231
232
233 /* ----------------------
234  *              Create/Drop TRIGGER Statements
235  * ----------------------
236  */
237
238 typedef struct CreateTrigStmt
239 {
240         NodeTag         type;
241         char       *trigname;           /* TRIGGER' name */
242         char       *relname;            /* triggered relation */
243         char       *funcname;           /* function to call (or NULL) */
244         List       *args;                       /* list of (T_String) Values or NULL */
245         bool            before;                 /* BEFORE/AFTER */
246         bool            row;                    /* ROW/STATEMENT */
247         char            actions[4];             /* Insert, Update, Delete */
248         char       *lang;                       /* NULL (which means Clanguage) */
249         char       *text;                       /* AS 'text' */
250         List       *attr;                       /* UPDATE OF a, b,... (NI) or NULL */
251         char       *when;                       /* WHEN 'a > 10 ...' (NI) or NULL */
252
253                                                                 /* The following are used for referential */
254                                                                 /* integrity constraint triggers */
255         bool            isconstraint;   /* This is an RI trigger */
256         bool            deferrable;             /* [NOT] DEFERRABLE */
257         bool            initdeferred;   /* INITIALLY {DEFERRED|IMMEDIATE} */
258         char       *constrrelname;      /* opposite relation */
259 } CreateTrigStmt;
260
261 typedef struct DropTrigStmt
262 {
263         NodeTag         type;
264         char       *trigname;           /* TRIGGER' name */
265         char       *relname;            /* triggered relation */
266 } DropTrigStmt;
267
268
269 /* ----------------------
270  *              Create/Drop PROCEDURAL LANGUAGE Statement
271  * ----------------------
272  */
273 typedef struct CreatePLangStmt
274 {
275         NodeTag         type;
276         char       *plname;                     /* PL name */
277         char       *plhandler;          /* PL call handler function */
278         char       *plcompiler;         /* lancompiler text */
279         bool            pltrusted;              /* PL is trusted */
280 } CreatePLangStmt;
281
282 typedef struct DropPLangStmt
283 {
284         NodeTag         type;
285         char       *plname;                     /* PL name */
286 } DropPLangStmt;
287
288
289 /* ----------------------
290  *                              Create/Alter/Drop User Statements
291  * ----------------------
292  */
293 typedef struct CreateUserStmt
294 {
295         NodeTag         type;
296         char       *user;                       /* PostgreSQL user login                          */
297         char       *password;           /* PostgreSQL user password                       */
298     int         sysid;          /* PgSQL system id (-1 if don't care) */
299         bool        createdb;           /* Can the user create databases?         */
300         bool        createuser;         /* Can this user create users?            */
301         List       *groupElts;          /* The groups the user is a member of */
302         char       *validUntil;         /* The time the login is valid until  */
303 } CreateUserStmt;
304
305 typedef struct AlterUserStmt
306 {
307         NodeTag         type;
308         char       *user;                       /* PostgreSQL user login                          */
309         char       *password;           /* PostgreSQL user password                       */
310         int         createdb;           /* Can the user create databases?         */
311         int         createuser;         /* Can this user create users?            */
312         char       *validUntil;         /* The time the login is valid until  */
313 } AlterUserStmt;
314
315 typedef struct DropUserStmt
316 {
317         NodeTag         type;
318     List       *users;          /* List of users to remove */
319 } DropUserStmt;
320
321
322 /* ----------------------
323  *      Create/Alter/Drop Group Statements
324  * ----------------------
325  */
326 typedef struct CreateGroupStmt
327 {
328     NodeTag     type;
329     char       *name;           /* name of the new group */
330     int         sysid;          /* group id (-1 if pick default) */
331     List       *initUsers;      /* list of initial users */
332 } CreateGroupStmt;
333
334 typedef struct AlterGroupStmt
335 {
336     NodeTag     type;
337     char       *name;           /* name of group to alter */
338     int         action;         /* +1 = add, -1 = drop user */
339     int         sysid;          /* sysid change */
340     List       *listUsers;      /* list of users to add/drop */
341 } AlterGroupStmt;
342
343 typedef struct DropGroupStmt
344 {
345     NodeTag     type;
346     char       *name;
347 } DropGroupStmt;
348
349
350 /* ----------------------
351  *              Create SEQUENCE Statement
352  * ----------------------
353  */
354
355 typedef struct CreateSeqStmt
356 {
357         NodeTag         type;
358         char       *seqname;            /* the relation to create */
359         List       *options;
360 } CreateSeqStmt;
361
362 /* ----------------------
363  *              Create Version Statement
364  * ----------------------
365  */
366 typedef struct VersionStmt
367 {
368         NodeTag         type;
369         char       *relname;            /* the new relation */
370         int                     direction;              /* FORWARD | BACKWARD */
371         char       *fromRelname;        /* relation to create a version */
372         char       *date;                       /* date of the snapshot */
373 } VersionStmt;
374
375 /* ----------------------
376  *              Create {Operator|Type|Aggregate} Statement
377  * ----------------------
378  */
379 typedef struct DefineStmt
380 {
381         NodeTag         type;
382         int                     defType;                /* OPERATOR|P_TYPE|AGGREGATE */
383         char       *defname;
384         List       *definition;         /* a list of DefElem */
385 } DefineStmt;
386
387 /* ----------------------
388  *              Drop Table Statement
389  * ----------------------
390  */
391 typedef struct DropStmt
392 {
393         NodeTag         type;
394         List       *relNames;           /* relations to be dropped */
395         bool            sequence;
396 } DropStmt;
397
398 /* ----------------------
399  *              Truncate Table Statement
400  * ----------------------
401  */
402 typedef struct TruncateStmt
403 {
404         NodeTag         type;
405         char       *relName;            /* relation to be truncated */
406 } TruncateStmt;
407
408 /* ----------------------
409  *              Comment On Statement
410  * ----------------------
411  */
412 typedef struct CommentStmt
413 {
414   NodeTag type;
415   int objtype;                         /* Object's type */
416   char *objname;                       /* Name of the object */
417   char *objproperty;                   /* Property Id (such as column) */
418   List *objlist;                       /* Arguments for VAL objects */
419   char *comment;                       /* The comment to insert */
420 } CommentStmt;
421       
422 /* ----------------------
423  *              Extend Index Statement
424  * ----------------------
425  */
426 typedef struct ExtendStmt
427 {
428         NodeTag         type;
429         char       *idxname;            /* name of the index */
430         Node       *whereClause;        /* qualifications */
431         List       *rangetable;         /* range table, filled in by
432                                                                  * transformStmt() */
433 } ExtendStmt;
434
435 /* ----------------------
436  *              Begin Recipe Statement
437  * ----------------------
438  */
439 typedef struct RecipeStmt
440 {
441         NodeTag         type;
442         char       *recipeName;         /* name of the recipe */
443 } RecipeStmt;
444
445 /* ----------------------
446  *              Fetch Statement
447  * ----------------------
448  */
449 typedef struct FetchStmt
450 {
451         NodeTag         type;
452         int                     direction;              /* FORWARD or BACKWARD */
453         int                     howMany;                /* amount to fetch ("ALL" --> 0) */
454         char       *portalname;         /* name of portal (cursor) */
455         bool            ismove;                 /* TRUE if MOVE */
456 } FetchStmt;
457
458 /* ----------------------
459  *              Create Index Statement
460  * ----------------------
461  */
462 typedef struct IndexStmt
463 {
464         NodeTag         type;
465         char       *idxname;            /* name of the index */
466         char       *relname;            /* name of relation to index on */
467         char       *accessMethod;       /* name of acess methood (eg. btree) */
468         List       *indexParams;        /* a list of IndexElem */
469         List       *withClause;         /* a list of DefElem */
470         Node       *whereClause;        /* qualifications */
471         List       *rangetable;         /* range table, filled in by
472                                                                  * transformStmt() */
473         bool       *lossy;                      /* is index lossy? */
474         bool            unique;                 /* is index unique? */
475         bool            primary;                /* is index on primary key? */
476 } IndexStmt;
477
478 /* ----------------------
479  *              Create Function Statement
480  * ----------------------
481  */
482 typedef struct ProcedureStmt
483 {
484         NodeTag         type;
485         char       *funcname;           /* name of function to create */
486         List       *defArgs;            /* list of definitions a list of strings
487                                                                  * (as Value *) */
488         Node       *returnType;         /* the return type (as a string or a
489                                                                  * TypeName (ie.setof) */
490         List       *withClause;         /* a list of DefElem */
491         List       *as;                         /* the SQL statement or filename */
492         char       *language;           /* C or SQL */
493 } ProcedureStmt;
494
495 /* ----------------------
496  *              Drop Aggregate Statement
497  * ----------------------
498  */
499 typedef struct RemoveAggrStmt
500 {
501         NodeTag         type;
502         char       *aggname;            /* aggregate to drop */
503         char       *aggtype;            /* for this type */
504 } RemoveAggrStmt;
505
506 /* ----------------------
507  *              Drop Function Statement
508  * ----------------------
509  */
510 typedef struct RemoveFuncStmt
511 {
512         NodeTag         type;
513         char       *funcname;           /* function to drop */
514         List       *args;                       /* types of the arguments */
515 } RemoveFuncStmt;
516
517 /* ----------------------
518  *              Drop Operator Statement
519  * ----------------------
520  */
521 typedef struct RemoveOperStmt
522 {
523         NodeTag         type;
524         char       *opname;                     /* operator to drop */
525         List       *args;                       /* types of the arguments */
526 } RemoveOperStmt;
527
528 /* ----------------------
529  *              Drop {Type|Index|Rule|View} Statement
530  * ----------------------
531  */
532 typedef struct RemoveStmt
533 {
534         NodeTag         type;
535         int                     removeType;             /* P_TYPE|INDEX|RULE|VIEW */
536         char       *name;                       /* name to drop */
537 } RemoveStmt;
538
539 /* ----------------------
540  *              Alter Table Statement
541  * ----------------------
542  */
543 typedef struct RenameStmt
544 {
545         NodeTag         type;
546         char       *relname;            /* relation to be altered */
547         bool            inh;                    /* recursively alter children? */
548         char       *column;                     /* if NULL, rename the relation name to
549                                                                  * the new name. Otherwise, rename this
550                                                                  * column name. */
551         char       *newname;            /* the new name */
552 } RenameStmt;
553
554 /* ----------------------
555  *              Create Rule Statement
556  * ----------------------
557  */
558 typedef struct RuleStmt
559 {
560         NodeTag         type;
561         char       *rulename;           /* name of the rule */
562         Node       *whereClause;        /* qualifications */
563         CmdType         event;                  /* RETRIEVE */
564         struct Attr *object;            /* object affected */
565         bool            instead;                /* is a 'do instead'? */
566         List       *actions;            /* the action statements */
567 } RuleStmt;
568
569 /* ----------------------
570  *              Notify Statement
571  * ----------------------
572  */
573 typedef struct NotifyStmt
574 {
575         NodeTag         type;
576         char       *relname;            /* relation to notify */
577 } NotifyStmt;
578
579 /* ----------------------
580  *              Listen Statement
581  * ----------------------
582  */
583 typedef struct ListenStmt
584 {
585         NodeTag         type;
586         char       *relname;            /* relation to listen on */
587 } ListenStmt;
588
589 /* ----------------------
590  *              Unlisten Statement
591  * ----------------------
592  */
593 typedef struct UnlistenStmt
594 {
595         NodeTag         type;
596         char       *relname;            /* relation to unlisten on */
597 } UnlistenStmt;
598
599 /* ----------------------
600  *              {Begin|Abort|End} Transaction Statement
601  * ----------------------
602  */
603 typedef struct TransactionStmt
604 {
605         NodeTag         type;
606         int                     command;                /* BEGIN|END|ABORT */
607 } TransactionStmt;
608
609 /* ----------------------
610  *              Create View Statement
611  * ----------------------
612  */
613 typedef struct ViewStmt
614 {
615         NodeTag         type;
616         char       *viewname;           /* name of the view */
617         List       *aliases;            /* target column names */
618         Query      *query;                      /* the SQL statement */
619 } ViewStmt;
620
621 /* ----------------------
622  *              Load Statement
623  * ----------------------
624  */
625 typedef struct LoadStmt
626 {
627         NodeTag         type;
628         char       *filename;           /* file to load */
629 } LoadStmt;
630
631 /* ----------------------
632  *              Createdb Statement
633  * ----------------------
634  */
635 typedef struct CreatedbStmt
636 {
637         NodeTag         type;
638         char       *dbname;                     /* database to create */
639         char       *dbpath;                     /* location of database */
640         int                     encoding;               /* default encoding (see regex/pg_wchar.h) */
641 } CreatedbStmt;
642
643 /* ----------------------
644  *              Dropdb Statement
645  * ----------------------
646  */
647 typedef struct DropdbStmt
648 {
649         NodeTag         type;
650         char       *dbname;                     /* database to drop */
651 } DropdbStmt;
652
653 /* ----------------------
654  *              Cluster Statement (support pbrown's cluster index implementation)
655  * ----------------------
656  */
657 typedef struct ClusterStmt
658 {
659         NodeTag         type;
660         char       *relname;            /* relation being indexed */
661         char       *indexname;          /* original index defined */
662 } ClusterStmt;
663
664 /* ----------------------
665  *              Vacuum Statement
666  * ----------------------
667  */
668 typedef struct VacuumStmt
669 {
670         NodeTag         type;
671         bool            verbose;                /* print status info */
672         bool            analyze;                /* analyze data */
673         char       *vacrel;                     /* table to vacuum */
674         List       *va_spec;            /* columns to analyse */
675 } VacuumStmt;
676
677 /* ----------------------
678  *              Explain Statement
679  * ----------------------
680  */
681 typedef struct ExplainStmt
682 {
683         NodeTag         type;
684         Query      *query;                      /* the query */
685         bool            verbose;                /* print plan info */
686 } ExplainStmt;
687
688 /* ----------------------
689  * Set Statement
690  * ----------------------
691  */
692
693 typedef struct VariableSetStmt
694 {
695         NodeTag         type;
696         char       *name;
697         char       *value;
698 } VariableSetStmt;
699
700 /* ----------------------
701  * Show Statement
702  * ----------------------
703  */
704
705 typedef struct VariableShowStmt
706 {
707         NodeTag         type;
708         char       *name;
709 } VariableShowStmt;
710
711 /* ----------------------
712  * Reset Statement
713  * ----------------------
714  */
715
716 typedef struct VariableResetStmt
717 {
718         NodeTag         type;
719         char       *name;
720 } VariableResetStmt;
721
722 /* ----------------------
723  *              LOCK Statement
724  * ----------------------
725  */
726 typedef struct LockStmt
727 {
728         NodeTag         type;
729         char       *relname;            /* relation to lock */
730         int                     mode;                   /* lock mode */
731 } LockStmt;
732
733
734 /* ----------------------
735  *              SET CONSTRAINTS Statement
736  * ----------------------
737  */
738 typedef struct ConstraintsSetStmt
739 {
740         NodeTag         type;
741         List            *constraints;
742         bool            deferred;
743 } ConstraintsSetStmt;
744
745 /* ----------------------
746  *              REINDEX Statement
747  * ----------------------
748  */
749 typedef struct ReindexStmt
750 {
751         NodeTag         type;
752         int             reindexType;            /* INDEX|TABLE|DATABASE */
753         const   char   *name;                   /* name to reindex */
754         bool            force;
755         bool            all;
756 } ReindexStmt;
757
758
759 /*****************************************************************************
760  *              Optimizable Statements
761  *****************************************************************************/
762
763 /* ----------------------
764  *              Insert Statement
765  * ----------------------
766  */
767 typedef struct InsertStmt
768 {
769         NodeTag         type;
770         char       *relname;            /* relation to insert into */
771         List       *distinctClause;     /* NULL, list of DISTINCT ON exprs, or
772                                                                  * lcons(NIL,NIL) for all (SELECT DISTINCT) */
773         List       *cols;                       /* names of the columns */
774         List       *targetList;         /* the target list (of ResTarget) */
775         List       *fromClause;         /* the from clause */
776         Node       *whereClause;        /* qualifications */
777         List       *groupClause;        /* GROUP BY clauses */
778         Node       *havingClause;       /* having conditional-expression */
779         List       *unionClause;        /* union subselect parameters */
780         bool            unionall;               /* union without unique sort */
781         List       *intersectClause;
782         List       *forUpdate;          /* FOR UPDATE clause */
783 } InsertStmt;
784
785 /* ----------------------
786  *              Delete Statement
787  * ----------------------
788  */
789 typedef struct DeleteStmt
790 {
791         NodeTag         type;
792         char       *relname;            /* relation to delete from */
793         Node       *whereClause;        /* qualifications */
794 } DeleteStmt;
795
796 /* ----------------------
797  *              Update Statement
798  * ----------------------
799  */
800 typedef struct UpdateStmt
801 {
802         NodeTag         type;
803         char       *relname;            /* relation to update */
804         List       *targetList;         /* the target list (of ResTarget) */
805         Node       *whereClause;        /* qualifications */
806         List       *fromClause;         /* the from clause */
807 } UpdateStmt;
808
809 /* ----------------------
810  *              Select Statement
811  * ----------------------
812  */
813 typedef struct SelectStmt
814 {
815         NodeTag         type;
816         List       *distinctClause;     /* NULL, list of DISTINCT ON exprs, or
817                                                                  * lcons(NIL,NIL) for all (SELECT DISTINCT) */
818         char       *into;                       /* name of table (for select into table) */
819         List       *targetList;         /* the target list (of ResTarget) */
820         List       *fromClause;         /* the from clause */
821         Node       *whereClause;        /* qualifications */
822         List       *groupClause;        /* GROUP BY clauses */
823         Node       *havingClause;       /* having conditional-expression */
824         List       *intersectClause;
825         List       *exceptClause;
826
827         List       *unionClause;        /* union subselect parameters */
828         List       *sortClause;         /* sort clause (a list of SortGroupBy's) */
829         char       *portalname;         /* the portal (cursor) to create */
830         bool            binary;                 /* a binary (internal) portal? */
831         bool            istemp;                 /* into is a temp table */
832         bool            unionall;               /* union without unique sort */
833         Node       *limitOffset;        /* # of result tuples to skip */
834         Node       *limitCount;         /* # of result tuples to return */
835         List       *forUpdate;          /* FOR UPDATE clause */
836 } SelectStmt;
837
838 /****************************************************************************
839  *      Supporting data structures for Parse Trees
840  *
841  *      Most of these node types appear in raw parsetrees output by the grammar,
842  *      and get transformed to something else by the analyzer.  A few of them
843  *      are used as-is in transformed querytrees.
844  ****************************************************************************/
845
846 /*
847  * TypeName - specifies a type in definitions
848  */
849 typedef struct TypeName
850 {
851         NodeTag         type;
852         char       *name;                       /* name of the type */
853         bool            timezone;               /* timezone specified? */
854         bool            setof;                  /* is a set? */
855         int32           typmod;                 /* type modifier */
856         List       *arrayBounds;        /* array bounds */
857 } TypeName;
858
859 /*
860  * ParamNo - specifies a parameter reference
861  */
862 typedef struct ParamNo
863 {
864         NodeTag         type;
865         int                     number;                 /* the number of the parameter */
866         TypeName   *typename;           /* the typecast */
867         List       *indirection;        /* array references */
868 } ParamNo;
869
870 /*
871  * A_Expr - binary expressions
872  */
873 typedef struct A_Expr
874 {
875         NodeTag         type;
876         int                     oper;                   /* type of operation
877                                                                  * {OP,OR,AND,NOT,ISNULL,NOTNULL} */
878         char       *opname;                     /* name of operator/function */
879         Node       *lexpr;                      /* left argument */
880         Node       *rexpr;                      /* right argument */
881 } A_Expr;
882
883 /*
884  * Attr -
885  *        specifies an Attribute (ie. a Column); could have nested dots or
886  *        array references.
887  *
888  */
889 typedef struct Attr
890 {
891         NodeTag         type;
892         char       *relname;            /* name of relation (can be "*") */
893         ParamNo    *paramNo;            /* or a parameter */
894         List       *attrs;                      /* attributes (possibly nested); list of
895                                                                  * Values (strings) */
896         List       *indirection;        /* array refs (list of A_Indices') */
897 } Attr;
898
899 /*
900  * A_Const - a constant expression
901  */
902 typedef struct A_Const
903 {
904         NodeTag         type;
905         Value           val;                    /* the value (with the tag) */
906         TypeName   *typename;           /* typecast */
907 } A_Const;
908
909 /*
910  * TypeCast - a CAST expression
911  *
912  * NOTE: for mostly historical reasons, A_Const and ParamNo parsenodes contain
913  * room for a TypeName; we only generate a separate TypeCast node if the
914  * argument to be casted is neither of those kinds of nodes.  In theory either
915  * representation would work, but it is convenient (especially for A_Const)
916  * to have the target type immediately available.
917  */
918 typedef struct TypeCast
919 {
920         NodeTag         type;
921         Node       *arg;                        /* the expression being casted */
922         TypeName   *typename;           /* the target type */
923 } TypeCast;
924
925 /*
926  * CaseExpr - a CASE expression
927  */
928 typedef struct CaseExpr
929 {
930         NodeTag         type;
931         Oid                     casetype;
932         Node       *arg;                        /* implicit equality comparison argument */
933         List       *args;                       /* the arguments (list of WHEN clauses) */
934         Node       *defresult;          /* the default result (ELSE clause) */
935 } CaseExpr;
936
937 /*
938  * CaseWhen - an argument to a CASE expression
939  */
940 typedef struct CaseWhen
941 {
942         NodeTag         type;
943         Node       *expr;                       /* comparison expression */
944         Node       *result;                     /* substitution result */
945 } CaseWhen;
946
947 /*
948  * ColumnDef - column definition (used in various creates)
949  *
950  * If the column has a default value, we may have the value expression
951  * in either "raw" form (an untransformed parse tree) or "cooked" form
952  * (the nodeToString representation of an executable expression tree),
953  * depending on how this ColumnDef node was created (by parsing, or by
954  * inheritance from an existing relation).  We should never have both
955  * in the same node!
956  *
957  * The constraints list may contain a CONSTR_DEFAULT item in a raw
958  * parsetree produced by gram.y, but transformCreateStmt will remove
959  * the item and set raw_default instead.  CONSTR_DEFAULT items
960  * should not appear in any subsequent processing.
961  */
962 typedef struct ColumnDef
963 {
964         NodeTag         type;
965         char       *colname;            /* name of column */
966         TypeName   *typename;           /* type of column */
967         bool            is_not_null;    /* flag to NOT NULL constraint */
968         bool            is_sequence;    /* is a sequence? */
969         Node       *raw_default;        /* default value (untransformed parse tree) */
970         char       *cooked_default;     /* nodeToString representation */
971         List       *constraints;        /* other constraints on column */
972 } ColumnDef;
973
974 /*
975  * Ident -
976  *        an identifier (could be an attribute or a relation name). Depending
977  *        on the context at transformStmt time, the identifier is treated as
978  *        either a relation name (in which case, isRel will be set) or an
979  *        attribute (in which case, it will be transformed into an Attr).
980  */
981 typedef struct Ident
982 {
983         NodeTag         type;
984         char       *name;                       /* its name */
985         List       *indirection;        /* array references */
986         bool            isRel;                  /* is a relation - filled in by
987                                                                  * transformExpr() */
988 } Ident;
989
990 /*
991  * FuncCall - a function or aggregate invocation
992  *
993  * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
994  * indicates we saw 'foo(DISTINCT ...)'.  In either case, the construct
995  * *must* be an aggregate call.  Otherwise, it might be either an
996  * aggregate or some other kind of function.
997  */
998 typedef struct FuncCall
999 {
1000         NodeTag         type;
1001         char       *funcname;           /* name of function */
1002         List       *args;                       /* the arguments (list of exprs) */
1003         bool            agg_star;               /* argument was really '*' */
1004         bool            agg_distinct;   /* arguments were labeled DISTINCT */
1005 } FuncCall;
1006
1007 /*
1008  * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
1009  */
1010 typedef struct A_Indices
1011 {
1012         NodeTag         type;
1013         Node       *lidx;                       /* could be NULL */
1014         Node       *uidx;
1015 } A_Indices;
1016
1017 /*
1018  * ResTarget -
1019  *        result target (used in target list of pre-transformed Parse trees)
1020  *
1021  * In a SELECT or INSERT target list, 'name' is either NULL or
1022  * the column name assigned to the value.  (If there is an 'AS ColumnLabel'
1023  * clause, the grammar sets 'name' from it; otherwise 'name' is initially NULL
1024  * and is filled in during the parse analysis phase.)
1025  * The 'indirection' field is not used at all.
1026  *
1027  * In an UPDATE target list, 'name' is the name of the destination column,
1028  * and 'indirection' stores any subscripts attached to the destination.
1029  * That is, our representation is UPDATE table SET name [indirection] = val.
1030  */
1031 typedef struct ResTarget
1032 {
1033         NodeTag         type;
1034         char       *name;                       /* column name or NULL */
1035         List       *indirection;        /* subscripts for destination column, or
1036                                                                  * NIL */
1037         Node       *val;                        /* the value expression to compute or
1038                                                                  * assign */
1039 } ResTarget;
1040
1041 /*
1042  * RelExpr - relation expressions
1043  */
1044 typedef struct RelExpr
1045 {
1046         NodeTag         type;
1047         char       *relname;            /* the relation name */
1048         bool            inh;                    /* inheritance query */
1049 } RelExpr;
1050
1051 /*
1052  * SortGroupBy - for ORDER BY clause
1053  */
1054 typedef struct SortGroupBy
1055 {
1056         NodeTag         type;
1057         char       *useOp;                      /* operator to use */
1058         Node       *node;                       /* Expression  */
1059 } SortGroupBy;
1060
1061 /*
1062  * RangeVar - range variable, used in FROM clauses
1063  */
1064 typedef struct RangeVar
1065 {
1066         NodeTag         type;
1067         RelExpr    *relExpr;            /* the relation expression */
1068         Attr       *name;                       /* the name to be referenced (optional) */
1069 } RangeVar;
1070
1071 /*
1072  * IndexElem - index parameters (used in CREATE INDEX)
1073  */
1074 typedef struct IndexElem
1075 {
1076         NodeTag         type;
1077         char       *name;                       /* name of index */
1078         List       *args;                       /* if not NULL, function index */
1079         char       *class;
1080         TypeName   *typename;           /* type of index's keys (optional) */
1081 } IndexElem;
1082
1083 /*
1084  * DefElem -
1085  *        a definition (used in definition lists in the form of defname = arg)
1086  */
1087 typedef struct DefElem
1088 {
1089         NodeTag         type;
1090         char       *defname;
1091         Node       *arg;                        /* a (Value *) or a (TypeName *) */
1092 } DefElem;
1093
1094 /*
1095  * JoinExpr - for JOIN expressions
1096  */
1097 typedef struct JoinExpr
1098 {
1099         NodeTag         type;
1100         int                     jointype;
1101         bool            isNatural;              /* Natural join? Will need to shape table */
1102         Node       *larg;                       /* RangeVar or join expression */
1103         Node       *rarg;                       /* RangeVar or join expression */
1104         Attr       *alias;                      /* table and column aliases, if any */
1105         List       *quals;                      /* qualifiers on join, if any */
1106 } JoinExpr;
1107
1108
1109 /****************************************************************************
1110  *      Nodes for a Query tree
1111  ****************************************************************************/
1112
1113 /*
1114  * TargetEntry -
1115  *         a target  entry (used in the transformed target list)
1116  *
1117  * one of resdom or fjoin is not NULL. a target list is
1118  *              ((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
1119  */
1120 typedef struct TargetEntry
1121 {
1122         NodeTag         type;
1123         Resdom     *resdom;                     /* fjoin overload this to be a list?? */
1124         Fjoin      *fjoin;
1125         Node       *expr;
1126 } TargetEntry;
1127
1128 /*--------------------
1129  * RangeTblEntry -
1130  *        A range table is a List of RangeTblEntry nodes.
1131  *
1132  *        Some of the following are only used in one of
1133  *        the parsing, optimizing, execution stages.
1134  *
1135  *        eref is the expanded table name and columns for the underlying
1136  *        relation. Note that for outer join syntax, allowed reference names
1137  *        could be modified as one evaluates the nested clauses (e.g.
1138  *        "SELECT ... FROM t1 NATURAL JOIN t2 WHERE ..." forbids explicit mention
1139  *        of a table name in any reference to the join column.
1140  *
1141  *        inFromCl marks those range variables that are listed in the FROM clause.
1142  *        In SQL, the query can only refer to range variables listed in the
1143  *        FROM clause, but POSTQUEL allows you to refer to tables not listed,
1144  *        in which case a range table entry will be generated.  We still support
1145  *        this POSTQUEL feature, although there is some doubt whether it's
1146  *        convenient or merely confusing.  The flag is needed since an
1147  *        implicitly-added RTE shouldn't change the namespace for unqualified
1148  *        column names processed later, and it also shouldn't affect the
1149  *        expansion of '*'.
1150  *
1151  *        inJoinSet marks those range variables that the planner should join
1152  *        over even if they aren't explicitly referred to in the query.  For
1153  *        example, "SELECT COUNT(1) FROM tx" should produce the number of rows
1154  *        in tx.  A more subtle example uses a POSTQUEL implicit RTE:
1155  *                      SELECT COUNT(1) FROM tx WHERE TRUE OR (tx.f1 = ty.f2)
1156  *        Here we should get the product of the sizes of tx and ty.  However,
1157  *        the query optimizer can simplify the WHERE clause to "TRUE", so
1158  *        ty will no longer be referred to explicitly; without a flag forcing
1159  *        it to be included in the join, we will get the wrong answer.  So,
1160  *        a POSTQUEL implicit RTE must be marked inJoinSet but not inFromCl.
1161  *--------------------
1162  */
1163 typedef struct RangeTblEntry
1164 {
1165         NodeTag         type;
1166         char       *relname;            /* real name of the relation */
1167         Attr       *ref;                        /* reference names (given in FROM clause) */
1168         Attr       *eref;                       /* expanded reference names */
1169         Oid                     relid;                  /* OID of the relation */
1170         bool            inh;                    /* inheritance requested? */
1171         bool            inFromCl;               /* present in FROM clause */
1172         bool            inJoinSet;              /* planner must include this rel */
1173         bool            skipAcl;                /* skip ACL check in executor */
1174 } RangeTblEntry;
1175
1176 /*
1177  * SortClause -
1178  *         representation of ORDER BY clauses
1179  *
1180  * tleSortGroupRef must match ressortgroupref of exactly one Resdom of the
1181  * associated targetlist; that is the expression to be sorted (or grouped) by.
1182  * sortop is the OID of the ordering operator.
1183  *
1184  * SortClauses are also used to identify Resdoms that we will do a "Unique"
1185  * filter step on (for SELECT DISTINCT and SELECT DISTINCT ON).  The
1186  * distinctClause list is simply a copy of the relevant members of the
1187  * sortClause list.  Note that distinctClause can be a subset of sortClause,
1188  * but cannot have members not present in sortClause; and the members that
1189  * do appear must be in the same order as in sortClause.
1190  */
1191 typedef struct SortClause
1192 {
1193         NodeTag         type;
1194         Index           tleSortGroupRef;/* reference into targetlist */
1195         Oid                     sortop;                 /* the sort operator to use */
1196 } SortClause;
1197
1198 /*
1199  * GroupClause -
1200  *         representation of GROUP BY clauses
1201  *
1202  * GroupClause is exactly like SortClause except for the nodetag value
1203  * (it's probably not even really necessary to have two different
1204  * nodetags...).  We have routines that operate interchangeably on both.
1205  */
1206 typedef SortClause GroupClause;
1207
1208 #define ROW_MARK_FOR_UPDATE             (1 << 0)
1209 #define ROW_ACL_FOR_UPDATE              (1 << 1)
1210
1211 typedef struct RowMark
1212 {
1213         NodeTag         type;
1214         Index           rti;                    /* index in Query->rtable */
1215         bits8           info;                   /* as above */
1216 } RowMark;
1217
1218 #endif   /* PARSENODES_H */