OSDN Git Service

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