1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: parsenodes.h,v 1.52 1998/07/26 04:31:29 scrappy Exp $
11 *-------------------------------------------------------------------------
16 #include <nodes/primnodes.h>
18 /*****************************************************************************
20 *****************************************************************************/
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.
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.
37 CmdType commandType; /* select|insert|update|delete|utility */
39 Node *utilityStmt; /* non-null if this is a non-optimizable
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 unionall; /* union without unique sort */
47 bool hasAggs; /* has aggregates in target list */
48 bool hasSubLinks; /* has subquery SubLink */
50 char *uniqueFlag; /* NULL, '*', or Unique attribute name */
51 List *sortClause; /* a list of SortClause's */
53 List *rtable; /* list of range table entries */
54 List *targetList; /* target list (of TargetEntry) */
55 Node *qual; /* qualifications */
57 List *groupClause; /* list of columns to specified in GROUP
59 Node *havingQual; /* qualification of each group */
61 List *unionClause; /* unions are linked under the previous
64 /* internal to planner */
65 List *base_relation_list_; /* base relation list */
66 List *join_relation_list_; /* list of relations */
70 /*****************************************************************************
71 * Other Statements (no optimizations required)
73 * Some of them require a little bit of transformation (which is also
74 * done by transformStmt). The whole structure is then passed on to
75 * ProcessUtility (by-passing the optimization step) as the utilityStmt
77 *****************************************************************************/
79 /* ----------------------
80 * Add Column Statement
81 * ----------------------
83 typedef struct AddAttrStmt
86 char *relname; /* the relation to add attr */
87 bool inh; /* add recursively to children? */
88 Node *colDef; /* the attribute definition */
91 /* ----------------------
92 * Change ACL Statement
93 * ----------------------
95 typedef struct ChangeACLStmt
98 struct AclItem *aclitem;
103 /* ----------------------
104 * Close Portal Statement
105 * ----------------------
107 typedef struct ClosePortalStmt
110 char *portalname; /* name of the portal (cursor) */
113 /* ----------------------
115 * ----------------------
117 typedef struct CopyStmt
120 bool binary; /* is a binary copy? */
121 char *relname; /* the relation to copy */
122 bool oids; /* copy oid's? */
123 int direction; /* TO or FROM */
124 char *filename; /* if NULL, use stdin/stdout */
125 char *delimiter; /* delimiter character, \t by default */
128 /* ----------------------
129 * Create Table Statement
130 * ----------------------
132 typedef struct CreateStmt
135 char *relname; /* the relation to create */
136 List *tableElts; /* column definitions list of Column */
137 List *inhRelnames; /* relations to inherit from list of Value
139 List *constraints; /* list of constraints (ConstaintDef) */
142 typedef enum ConstrType /* type of constaints */
144 CONSTR_NONE, CONSTR_NOTNULL, CONSTR_DEFAULT, CONSTR_CHECK, CONSTR_PRIMARY, CONSTR_UNIQUE
147 typedef struct Constraint
151 char *name; /* name */
152 void *def; /* definition */
153 void *keys; /* list of primary keys */
156 /* ----------------------
157 * Create/Drop TRIGGER Statements
158 * ----------------------
161 typedef struct CreateTrigStmt
164 char *trigname; /* TRIGGER' name */
165 char *relname; /* triggered relation */
166 char *funcname; /* function to call (or NULL) */
167 List *args; /* list of (T_String) Values or NULL */
168 bool before; /* BEFORE/AFTER */
169 bool row; /* ROW/STATEMENT */
170 char actions[4]; /* Insert, Update, Delete */
171 char *lang; /* NULL (which means Clanguage) */
172 char *text; /* AS 'text' */
173 List *attr; /* UPDATE OF a, b,... (NI) or NULL */
174 char *when; /* WHEN 'a > 10 ...' (NI) or NULL */
177 typedef struct DropTrigStmt
180 char *trigname; /* TRIGGER' name */
181 char *relname; /* triggered relation */
185 /* ----------------------
186 * Create/Drop PROCEDURAL LANGUAGE Statement
187 * ----------------------
189 typedef struct CreatePLangStmt
192 char *plname; /* PL name */
193 char *plhandler; /* PL call handler function */
194 char *plcompiler; /* lancompiler text */
195 bool pltrusted; /* PL is trusted */
198 typedef struct DropPLangStmt
201 char *plname; /* PL name */
205 /* ----------------------
206 * Create/Alter/Drop User Statements
207 * ----------------------
209 typedef struct CreateUserStmt
212 char *user; /* PostgreSQL user login */
213 char *password; /* PostgreSQL user password */
214 bool *createdb; /* Can the user create databases? */
215 bool *createuser; /* Can this user create users? */
216 List *groupElts; /* The groups the user is a member of */
217 char *validUntil; /* The time the login is valid until */
220 typedef CreateUserStmt AlterUserStmt;
222 typedef struct DropUserStmt
225 char *user; /* PostgreSQL user login */
229 /* ----------------------
230 * Create SEQUENCE Statement
231 * ----------------------
234 typedef struct CreateSeqStmt
237 char *seqname; /* the relation to create */
241 /* ----------------------
242 * Create Version Statement
243 * ----------------------
245 typedef struct VersionStmt
248 char *relname; /* the new relation */
249 int direction; /* FORWARD | BACKWARD */
250 char *fromRelname; /* relation to create a version */
251 char *date; /* date of the snapshot */
254 /* ----------------------
255 * Create {Operator|Type|Aggregate} Statement
256 * ----------------------
258 typedef struct DefineStmt
261 int defType; /* OPERATOR|P_TYPE|AGGREGATE */
263 List *definition; /* a list of DefElem */
266 /* ----------------------
267 * Drop Table Statement
268 * ----------------------
270 typedef struct DestroyStmt
273 List *relNames; /* relations to be dropped */
277 /* ----------------------
278 * Extend Index Statement
279 * ----------------------
281 typedef struct ExtendStmt
284 char *idxname; /* name of the index */
285 Node *whereClause; /* qualifications */
286 List *rangetable; /* range table, filled in by
290 /* ----------------------
291 * Begin Recipe Statement
292 * ----------------------
294 typedef struct RecipeStmt
297 char *recipeName; /* name of the recipe */
300 /* ----------------------
302 * ----------------------
304 typedef struct FetchStmt
307 int direction; /* FORWARD or BACKWARD */
308 int howMany; /* amount to fetch ("ALL" --> 0) */
309 char *portalname; /* name of portal (cursor) */
310 bool ismove; /* TRUE if MOVE */
313 /* ----------------------
314 * Create Index Statement
315 * ----------------------
317 typedef struct IndexStmt
320 char *idxname; /* name of the index */
321 char *relname; /* name of relation to index on */
322 char *accessMethod; /* name of acess methood (eg. btree) */
323 List *indexParams; /* a list of IndexElem */
324 List *withClause; /* a list of ParamString */
325 Node *whereClause; /* qualifications */
326 List *rangetable; /* range table, filled in by
328 bool *lossy; /* is index lossy? */
329 bool unique; /* is index unique? */
332 /* ----------------------
333 * Create Function Statement
334 * ----------------------
336 typedef struct ProcedureStmt
339 char *funcname; /* name of function to create */
340 List *defArgs; /* list of definitions a list of strings
342 Node *returnType; /* the return type (as a string or a
343 * TypeName (ie.setof) */
344 List *withClause; /* a list of ParamString */
345 char *as; /* the SQL statement or filename */
346 char *language; /* C or SQL */
349 /* ----------------------
350 * Drop Aggregate Statement
351 * ----------------------
353 typedef struct RemoveAggrStmt
356 char *aggname; /* aggregate to drop */
357 char *aggtype; /* for this type */
360 /* ----------------------
361 * Drop Function Statement
362 * ----------------------
364 typedef struct RemoveFuncStmt
367 char *funcname; /* function to drop */
368 List *args; /* types of the arguments */
371 /* ----------------------
372 * Drop Operator Statement
373 * ----------------------
375 typedef struct RemoveOperStmt
378 char *opname; /* operator to drop */
379 List *args; /* types of the arguments */
382 /* ----------------------
383 * Drop {Type|Index|Rule|View} Statement
384 * ----------------------
386 typedef struct RemoveStmt
389 int removeType; /* P_TYPE|INDEX|RULE|VIEW */
390 char *name; /* name to drop */
393 /* ----------------------
394 * Alter Table Statement
395 * ----------------------
397 typedef struct RenameStmt
400 char *relname; /* relation to be altered */
401 bool inh; /* recursively alter children? */
402 char *column; /* if NULL, rename the relation name to
403 * the new name. Otherwise, rename this
405 char *newname; /* the new name */
408 /* ----------------------
409 * Create Rule Statement
410 * ----------------------
412 typedef struct RuleStmt
415 char *rulename; /* name of the rule */
416 Node *whereClause; /* qualifications */
417 CmdType event; /* RETRIEVE */
418 struct Attr *object; /* object affected */
419 bool instead; /* is a 'do instead'? */
420 List *actions; /* the action statements */
423 /* ----------------------
425 * ----------------------
427 typedef struct NotifyStmt
430 char *relname; /* relation to notify */
433 /* ----------------------
435 * ----------------------
437 typedef struct ListenStmt
440 char *relname; /* relation to listen on */
443 /* ----------------------
444 * {Begin|Abort|End} Transaction Statement
445 * ----------------------
447 typedef struct TransactionStmt
450 int command; /* BEGIN|END|ABORT */
453 /* ----------------------
454 * Create View Statement
455 * ----------------------
457 typedef struct ViewStmt
460 char *viewname; /* name of the view */
461 Query *query; /* the SQL statement */
464 /* ----------------------
466 * ----------------------
468 typedef struct LoadStmt
471 char *filename; /* file to load */
474 /* ----------------------
476 * ----------------------
478 typedef struct CreatedbStmt
481 char *dbname; /* database to create */
482 char *dbpath; /* location of database */
484 int encoding; /* default encoding
485 (see regex/pg_wchar.h) */
489 /* ----------------------
490 * Destroydb Statement
491 * ----------------------
493 typedef struct DestroydbStmt
496 char *dbname; /* database to drop */
499 /* ----------------------
500 * Cluster Statement (support pbrown's cluster index implementation)
501 * ----------------------
503 typedef struct ClusterStmt
506 char *relname; /* relation being indexed */
507 char *indexname; /* original index defined */
510 /* ----------------------
512 * ----------------------
514 typedef struct VacuumStmt
517 bool verbose; /* print status info */
518 bool analyze; /* analyze data */
519 char *vacrel; /* table to vacuum */
520 List *va_spec; /* columns to analyse */
523 /* ----------------------
525 * ----------------------
527 typedef struct ExplainStmt
530 Query *query; /* the query */
531 bool verbose; /* print plan info */
534 /* ----------------------
536 * ----------------------
539 typedef struct VariableSetStmt
546 /* ----------------------
548 * ----------------------
551 typedef struct VariableShowStmt
557 /* ----------------------
559 * ----------------------
562 typedef struct VariableResetStmt
569 /*****************************************************************************
570 * Optimizable Statements
571 *****************************************************************************/
573 /* ----------------------
575 * ----------------------
577 typedef struct InsertStmt
580 char *relname; /* relation to insert into */
581 char *unique; /* NULL, '*', or unique attribute name */
582 List *cols; /* names of the columns */
583 List *targetList; /* the target list (of ResTarget) */
584 List *fromClause; /* the from clause */
585 Node *whereClause; /* qualifications */
586 List *groupClause; /* group by clause */
587 Node *havingClause; /* having conditional-expression */
588 List *unionClause; /* union subselect parameters */
589 bool unionall; /* union without unique sort */
592 /* ----------------------
594 * ----------------------
596 typedef struct DeleteStmt
599 char *relname; /* relation to delete from */
600 Node *whereClause; /* qualifications */
603 /* ----------------------
605 * ----------------------
607 typedef struct UpdateStmt
610 char *relname; /* relation to update */
611 List *targetList; /* the target list (of ResTarget) */
612 Node *whereClause; /* qualifications */
613 List *fromClause; /* the from clause */
616 /* ----------------------
618 * ----------------------
620 typedef struct SelectStmt
623 char *unique; /* NULL, '*', or unique attribute name */
624 char *into; /* name of table (for select into table) */
625 List *targetList; /* the target list (of ResTarget) */
626 List *fromClause; /* the from clause */
627 Node *whereClause; /* qualifications */
628 List *groupClause; /* group by clause */
629 Node *havingClause; /* having conditional-expression */
630 List *unionClause; /* union subselect parameters */
631 List *sortClause; /* sort clause (a list of SortGroupBy's) */
632 char *portalname; /* the portal (cursor) to create */
633 bool binary; /* a binary (internal) portal? */
634 bool unionall; /* union without unique sort */
638 /****************************************************************************
639 * Supporting data structures for Parse Trees
640 ****************************************************************************/
643 * TypeName - specifies a type in definitions
645 typedef struct TypeName
648 char *name; /* name of the type */
649 bool timezone; /* timezone specified? */
650 bool setof; /* is a set? */
651 int32 typmod; /* type modifier */
652 List *arrayBounds; /* array bounds */
656 * ParamNo - specifies a parameter reference
658 typedef struct ParamNo
661 int number; /* the number of the parameter */
662 TypeName *typename; /* the typecast */
666 * A_Expr - binary expressions
668 typedef struct A_Expr
671 int oper; /* type of operation
672 * {OP,OR,AND,NOT,ISNULL,NOTNULL} */
673 char *opname; /* name of operator/function */
674 Node *lexpr; /* left argument */
675 Node *rexpr; /* right argument */
680 * specifies an Attribute (ie. a Column); could have nested dots or
687 char *relname; /* name of relation (can be "*") */
688 ParamNo *paramNo; /* or a parameter */
689 List *attrs; /* attributes (possibly nested); list of
690 * Values (strings) */
691 List *indirection; /* array refs (list of A_Indices') */
695 * A_Const - a constant expression
697 typedef struct A_Const
700 Value val; /* the value (with the tag) */
701 TypeName *typename; /* typecast */
705 * ColumnDef - column definition (used in various creates)
707 typedef struct ColumnDef
710 char *colname; /* name of column */
711 TypeName *typename; /* type of column */
712 bool is_not_null; /* flag to NOT NULL constraint */
713 char *defval; /* default value of column */
714 List *constraints; /* constraints on column */
719 * an identifier (could be an attribute or a relation name). Depending
720 * on the context at transformStmt time, the identifier is treated as
721 * either a relation name (in which case, isRel will be set) or an
722 * attribute (in which case, it will be transformed into an Attr).
727 char *name; /* its name */
728 List *indirection; /* array references */
729 bool isRel; /* is a relation - filled in by
734 * FuncCall - a function/aggregate invocation
736 typedef struct FuncCall
739 char *funcname; /* name of function */
740 List *args; /* the arguments (list of exprs) */
744 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
746 typedef struct A_Indices
749 Node *lidx; /* could be NULL */
755 * result target (used in target list of pre-transformed Parse trees)
757 typedef struct ResTarget
760 char *name; /* name of the result column */
761 List *indirection; /* array references */
762 Node *val; /* the value of the result (A_Expr or
763 * Attr) (or A_Const) */
767 * ParamString - used in with clauses
769 typedef struct ParamString
777 * RelExpr - relation expressions
779 typedef struct RelExpr
782 char *relname; /* the relation name */
783 bool inh; /* inheritance query */
787 * SortGroupBy - for order by clause
789 typedef struct SortGroupBy
792 int resno; /* target number */
794 char *name; /* name of column to sort on */
795 char *useOp; /* operator to use */
799 * RangeVar - range variable, used in from clauses
801 typedef struct RangeVar
804 RelExpr *relExpr; /* the relation expression */
805 char *name; /* the name to be referenced (optional) */
809 * IndexElem - index parameters (used in create index)
811 typedef struct IndexElem
814 char *name; /* name of index */
815 List *args; /* if not NULL, function index */
817 TypeName *tname; /* type of index's keys (optional) */
822 * a definition (used in definition lists in the form of defname = arg)
824 typedef struct DefElem
828 Node *arg; /* a (Value *) or a (TypeName *) */
832 /****************************************************************************
833 * Nodes for a Query tree
834 ****************************************************************************/
838 * a target entry (used in the transformed target list)
840 * one of resdom or fjoin is not NULL. a target list is
841 * ((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
843 typedef struct TargetEntry
846 Resdom *resdom; /* fjoin overload this to be a list?? */
848 Node *expr; /* can be a list too */
853 * used in range tables. Some of the following are only used in one of
854 * the parsing, optimizing, execution stages.
856 * inFromCl marks those range variables that are listed in the from clause.
857 * In SQL, the targetlist can only refer to range variables listed in the
858 * from clause but POSTQUEL allows you to refer to tables not specified, in
859 * which case a range table entry will be generated. We use POSTQUEL
860 * semantics which is more powerful. However, we need SQL semantics in
861 * some cases (eg. when expanding a '*')
863 typedef struct RangeTblEntry
866 char *relname; /* real name of the relation */
867 char *refname; /* the reference name (specified in the
870 bool inh; /* inheritance? */
871 bool inFromCl; /* comes from From Clause */
872 bool skipAcl; /* skip ACL check in executor */
877 * used in the sort clause for retrieves and cursors
879 typedef struct SortClause
882 Resdom *resdom; /* attributes in tlist to be sorted */
883 Oid opoid; /* sort operators */
888 * used in the GROUP BY clause
890 typedef struct GroupClause
893 TargetEntry *entry; /* attributes to group on */
894 Oid grpOpoid; /* the sort operator to use */
897 #endif /* PARSENODES_H */