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