1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: parsenodes.h,v 1.62 1998/12/04 15:34:44 thomas 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
63 Node *limitOffset; /* # of result tuples to skip */
64 Node *limitCount; /* # of result tuples to return */
66 /* internal to planner */
67 List *base_rel_list; /* base relation list */
68 List *join_rel_list; /* list of relation involved in joins */
72 /*****************************************************************************
73 * Other Statements (no optimizations required)
75 * Some of them require a little bit of transformation (which is also
76 * done by transformStmt). The whole structure is then passed on to
77 * ProcessUtility (by-passing the optimization step) as the utilityStmt
79 *****************************************************************************/
81 /* ----------------------
82 * Add Column Statement
83 * ----------------------
85 typedef struct AddAttrStmt
88 char *relname; /* the relation to add attr */
89 bool inh; /* add recursively to children? */
90 Node *colDef; /* the attribute definition */
93 /* ----------------------
94 * Change ACL Statement
95 * ----------------------
97 typedef struct ChangeACLStmt
100 struct AclItem *aclitem;
105 /* ----------------------
106 * Close Portal Statement
107 * ----------------------
109 typedef struct ClosePortalStmt
112 char *portalname; /* name of the portal (cursor) */
115 /* ----------------------
117 * ----------------------
119 typedef struct CopyStmt
122 bool binary; /* is a binary copy? */
123 char *relname; /* the relation to copy */
124 bool oids; /* copy oid's? */
125 int direction; /* TO or FROM */
126 char *filename; /* if NULL, use stdin/stdout */
127 char *delimiter; /* delimiter character, \t by default */
130 /* ----------------------
131 * Create Table Statement
132 * ----------------------
134 typedef struct CreateStmt
137 char *relname; /* the relation to create */
138 List *tableElts; /* column definitions list of Column */
139 List *inhRelnames; /* relations to inherit from list of Value
141 List *constraints; /* list of constraints (ConstaintDef) */
144 typedef enum ConstrType /* type of constaints */
146 CONSTR_NONE, CONSTR_NOTNULL, CONSTR_DEFAULT, CONSTR_CHECK, CONSTR_PRIMARY, CONSTR_UNIQUE
149 typedef struct Constraint
153 char *name; /* name */
154 void *def; /* definition */
155 void *keys; /* list of primary keys */
158 /* ----------------------
159 * Create/Drop TRIGGER Statements
160 * ----------------------
163 typedef struct CreateTrigStmt
166 char *trigname; /* TRIGGER' name */
167 char *relname; /* triggered relation */
168 char *funcname; /* function to call (or NULL) */
169 List *args; /* list of (T_String) Values or NULL */
170 bool before; /* BEFORE/AFTER */
171 bool row; /* ROW/STATEMENT */
172 char actions[4]; /* Insert, Update, Delete */
173 char *lang; /* NULL (which means Clanguage) */
174 char *text; /* AS 'text' */
175 List *attr; /* UPDATE OF a, b,... (NI) or NULL */
176 char *when; /* WHEN 'a > 10 ...' (NI) or NULL */
179 typedef struct DropTrigStmt
182 char *trigname; /* TRIGGER' name */
183 char *relname; /* triggered relation */
187 /* ----------------------
188 * Create/Drop PROCEDURAL LANGUAGE Statement
189 * ----------------------
191 typedef struct CreatePLangStmt
194 char *plname; /* PL name */
195 char *plhandler; /* PL call handler function */
196 char *plcompiler; /* lancompiler text */
197 bool pltrusted; /* PL is trusted */
200 typedef struct DropPLangStmt
203 char *plname; /* PL name */
207 /* ----------------------
208 * Create/Alter/Drop User Statements
209 * ----------------------
211 typedef struct CreateUserStmt
214 char *user; /* PostgreSQL user login */
215 char *password; /* PostgreSQL user password */
216 bool *createdb; /* Can the user create databases? */
217 bool *createuser; /* Can this user create users? */
218 List *groupElts; /* The groups the user is a member of */
219 char *validUntil; /* The time the login is valid until */
222 typedef CreateUserStmt AlterUserStmt;
224 typedef struct DropUserStmt
227 char *user; /* PostgreSQL user login */
231 /* ----------------------
232 * Create SEQUENCE Statement
233 * ----------------------
236 typedef struct CreateSeqStmt
239 char *seqname; /* the relation to create */
243 /* ----------------------
244 * Create Version Statement
245 * ----------------------
247 typedef struct VersionStmt
250 char *relname; /* the new relation */
251 int direction; /* FORWARD | BACKWARD */
252 char *fromRelname; /* relation to create a version */
253 char *date; /* date of the snapshot */
256 /* ----------------------
257 * Create {Operator|Type|Aggregate} Statement
258 * ----------------------
260 typedef struct DefineStmt
263 int defType; /* OPERATOR|P_TYPE|AGGREGATE */
265 List *definition; /* a list of DefElem */
268 /* ----------------------
269 * Drop Table Statement
270 * ----------------------
272 typedef struct DestroyStmt
275 List *relNames; /* relations to be dropped */
279 /* ----------------------
280 * Extend Index Statement
281 * ----------------------
283 typedef struct ExtendStmt
286 char *idxname; /* name of the index */
287 Node *whereClause; /* qualifications */
288 List *rangetable; /* range table, filled in by
292 /* ----------------------
293 * Begin Recipe Statement
294 * ----------------------
296 typedef struct RecipeStmt
299 char *recipeName; /* name of the recipe */
302 /* ----------------------
304 * ----------------------
306 typedef struct FetchStmt
309 int direction; /* FORWARD or BACKWARD */
310 int howMany; /* amount to fetch ("ALL" --> 0) */
311 char *portalname; /* name of portal (cursor) */
312 bool ismove; /* TRUE if MOVE */
315 /* ----------------------
316 * Create Index Statement
317 * ----------------------
319 typedef struct IndexStmt
322 char *idxname; /* name of the index */
323 char *relname; /* name of relation to index on */
324 char *accessMethod; /* name of acess methood (eg. btree) */
325 List *indexParams; /* a list of IndexElem */
326 List *withClause; /* a list of ParamString */
327 Node *whereClause; /* qualifications */
328 List *rangetable; /* range table, filled in by
330 bool *lossy; /* is index lossy? */
331 bool unique; /* is index unique? */
334 /* ----------------------
335 * Create Function Statement
336 * ----------------------
338 typedef struct ProcedureStmt
341 char *funcname; /* name of function to create */
342 List *defArgs; /* list of definitions a list of strings
344 Node *returnType; /* the return type (as a string or a
345 * TypeName (ie.setof) */
346 List *withClause; /* a list of ParamString */
347 char *as; /* the SQL statement or filename */
348 char *language; /* C or SQL */
351 /* ----------------------
352 * Drop Aggregate Statement
353 * ----------------------
355 typedef struct RemoveAggrStmt
358 char *aggname; /* aggregate to drop */
359 char *aggtype; /* for this type */
362 /* ----------------------
363 * Drop Function Statement
364 * ----------------------
366 typedef struct RemoveFuncStmt
369 char *funcname; /* function to drop */
370 List *args; /* types of the arguments */
373 /* ----------------------
374 * Drop Operator Statement
375 * ----------------------
377 typedef struct RemoveOperStmt
380 char *opname; /* operator to drop */
381 List *args; /* types of the arguments */
384 /* ----------------------
385 * Drop {Type|Index|Rule|View} Statement
386 * ----------------------
388 typedef struct RemoveStmt
391 int removeType; /* P_TYPE|INDEX|RULE|VIEW */
392 char *name; /* name to drop */
395 /* ----------------------
396 * Alter Table Statement
397 * ----------------------
399 typedef struct RenameStmt
402 char *relname; /* relation to be altered */
403 bool inh; /* recursively alter children? */
404 char *column; /* if NULL, rename the relation name to
405 * the new name. Otherwise, rename this
407 char *newname; /* the new name */
410 /* ----------------------
411 * Create Rule Statement
412 * ----------------------
414 typedef struct RuleStmt
417 char *rulename; /* name of the rule */
418 Node *whereClause; /* qualifications */
419 CmdType event; /* RETRIEVE */
420 struct Attr *object; /* object affected */
421 bool instead; /* is a 'do instead'? */
422 List *actions; /* the action statements */
425 /* ----------------------
427 * ----------------------
429 typedef struct NotifyStmt
432 char *relname; /* relation to notify */
435 /* ----------------------
437 * ----------------------
439 typedef struct ListenStmt
442 char *relname; /* relation to listen on */
445 /* ----------------------
447 * ----------------------
449 typedef struct UnlistenStmt
452 char *relname; /* relation to unlisten on */
455 /* ----------------------
456 * {Begin|Abort|End} Transaction Statement
457 * ----------------------
459 typedef struct TransactionStmt
462 int command; /* BEGIN|END|ABORT */
465 /* ----------------------
466 * Create View Statement
467 * ----------------------
469 typedef struct ViewStmt
472 char *viewname; /* name of the view */
473 Query *query; /* the SQL statement */
476 /* ----------------------
478 * ----------------------
480 typedef struct LoadStmt
483 char *filename; /* file to load */
486 /* ----------------------
488 * ----------------------
490 typedef struct CreatedbStmt
493 char *dbname; /* database to create */
494 char *dbpath; /* location of database */
495 int encoding; /* default encoding (see regex/pg_wchar.h) */
498 /* ----------------------
499 * Destroydb Statement
500 * ----------------------
502 typedef struct DestroydbStmt
505 char *dbname; /* database to drop */
508 /* ----------------------
509 * Cluster Statement (support pbrown's cluster index implementation)
510 * ----------------------
512 typedef struct ClusterStmt
515 char *relname; /* relation being indexed */
516 char *indexname; /* original index defined */
519 /* ----------------------
521 * ----------------------
523 typedef struct VacuumStmt
526 bool verbose; /* print status info */
527 bool analyze; /* analyze data */
528 char *vacrel; /* table to vacuum */
529 List *va_spec; /* columns to analyse */
532 /* ----------------------
534 * ----------------------
536 typedef struct ExplainStmt
539 Query *query; /* the query */
540 bool verbose; /* print plan info */
543 /* ----------------------
545 * ----------------------
548 typedef struct VariableSetStmt
555 /* ----------------------
557 * ----------------------
560 typedef struct VariableShowStmt
566 /* ----------------------
568 * ----------------------
571 typedef struct VariableResetStmt
578 /*****************************************************************************
579 * Optimizable Statements
580 *****************************************************************************/
582 /* ----------------------
584 * ----------------------
586 typedef struct InsertStmt
589 char *relname; /* relation to insert into */
590 char *unique; /* NULL, '*', or unique attribute name */
591 List *cols; /* names of the columns */
592 List *targetList; /* the target list (of ResTarget) */
593 List *fromClause; /* the from clause */
594 Node *whereClause; /* qualifications */
595 List *groupClause; /* group by clause */
596 Node *havingClause; /* having conditional-expression */
597 List *unionClause; /* union subselect parameters */
598 bool unionall; /* union without unique sort */
601 /* ----------------------
603 * ----------------------
605 typedef struct DeleteStmt
608 char *relname; /* relation to delete from */
609 Node *whereClause; /* qualifications */
612 /* ----------------------
614 * ----------------------
616 typedef struct UpdateStmt
619 char *relname; /* relation to update */
620 List *targetList; /* the target list (of ResTarget) */
621 Node *whereClause; /* qualifications */
622 List *fromClause; /* the from clause */
625 /* ----------------------
627 * ----------------------
629 typedef struct SelectStmt
632 char *unique; /* NULL, '*', or unique attribute name */
633 char *into; /* name of table (for select into table) */
634 List *targetList; /* the target list (of ResTarget) */
635 List *fromClause; /* the from clause */
636 Node *whereClause; /* qualifications */
637 List *groupClause; /* group by clause */
638 Node *havingClause; /* having conditional-expression */
639 List *unionClause; /* union subselect parameters */
640 List *sortClause; /* sort clause (a list of SortGroupBy's) */
641 char *portalname; /* the portal (cursor) to create */
642 bool binary; /* a binary (internal) portal? */
643 bool unionall; /* union without unique sort */
644 Node *limitOffset; /* # of result tuples to skip */
645 Node *limitCount; /* # of result tuples to return */
649 /****************************************************************************
650 * Supporting data structures for Parse Trees
651 ****************************************************************************/
654 * TypeName - specifies a type in definitions
656 typedef struct TypeName
659 char *name; /* name of the type */
660 bool timezone; /* timezone specified? */
661 bool setof; /* is a set? */
662 int16 typmod; /* type modifier */
663 List *arrayBounds; /* array bounds */
667 * ParamNo - specifies a parameter reference
669 typedef struct ParamNo
672 int number; /* the number of the parameter */
673 TypeName *typename; /* the typecast */
674 List *indirection; /* array references */
678 * A_Expr - binary expressions
680 typedef struct A_Expr
683 int oper; /* type of operation
684 * {OP,OR,AND,NOT,ISNULL,NOTNULL} */
685 char *opname; /* name of operator/function */
686 Node *lexpr; /* left argument */
687 Node *rexpr; /* right argument */
692 * specifies an Attribute (ie. a Column); could have nested dots or
699 char *relname; /* name of relation (can be "*") */
700 ParamNo *paramNo; /* or a parameter */
701 List *attrs; /* attributes (possibly nested); list of
702 * Values (strings) */
703 List *indirection; /* array refs (list of A_Indices') */
707 * A_Const - a constant expression
709 typedef struct A_Const
712 Value val; /* the value (with the tag) */
713 TypeName *typename; /* typecast */
717 * CaseExpr - a CASE expression
719 typedef struct CaseExpr
723 Node *arg; /* implicit equality comparison argument */
724 List *args; /* the arguments (list of WHEN clauses) */
725 Node *defresult; /* the default result (ELSE clause) */
729 * CaseWhen - an argument to a CASE expression
731 typedef struct CaseWhen
734 Node *expr; /* comparison expression */
735 Node *result; /* substitution result */
739 * ColumnDef - column definition (used in various creates)
741 typedef struct ColumnDef
744 char *colname; /* name of column */
745 TypeName *typename; /* type of column */
746 bool is_not_null; /* flag to NOT NULL constraint */
747 bool is_sequence; /* is a sequence? */
748 char *defval; /* default value of column */
749 List *constraints; /* constraints on column */
754 * an identifier (could be an attribute or a relation name). Depending
755 * on the context at transformStmt time, the identifier is treated as
756 * either a relation name (in which case, isRel will be set) or an
757 * attribute (in which case, it will be transformed into an Attr).
762 char *name; /* its name */
763 List *indirection; /* array references */
764 bool isRel; /* is a relation - filled in by
769 * FuncCall - a function/aggregate invocation
771 typedef struct FuncCall
774 char *funcname; /* name of function */
775 List *args; /* the arguments (list of exprs) */
779 * A_Indices - array reference or bounds ([lidx:uidx] or [uidx])
781 typedef struct A_Indices
784 Node *lidx; /* could be NULL */
790 * result target (used in target list of pre-transformed Parse trees)
792 typedef struct ResTarget
795 char *name; /* name of the result column */
796 List *indirection; /* array references */
797 Node *val; /* the value of the result (A_Expr or
798 * Attr) (or A_Const) */
802 * ParamString - used in WITH clauses
804 typedef struct ParamString
812 * RelExpr - relation expressions
814 typedef struct RelExpr
817 char *relname; /* the relation name */
818 bool inh; /* inheritance query */
822 * SortGroupBy - for ORDER BY clause
824 typedef struct SortGroupBy
827 char *useOp; /* operator to use */
828 Node *node; /* Expression */
832 * JoinUsing - for JOIN USING clause
834 typedef struct JoinUsing
837 int resno; /* target number */
839 char *name; /* name of column to sort on */
843 * RangeVar - range variable, used in FROM clauses
845 typedef struct RangeVar
848 RelExpr *relExpr; /* the relation expression */
849 char *name; /* the name to be referenced (optional) */
853 * IndexElem - index parameters (used in CREATE INDEX)
855 typedef struct IndexElem
858 char *name; /* name of index */
859 List *args; /* if not NULL, function index */
861 TypeName *typename; /* type of index's keys (optional) */
866 * a definition (used in definition lists in the form of defname = arg)
868 typedef struct DefElem
872 Node *arg; /* a (Value *) or a (TypeName *) */
876 /****************************************************************************
877 * Nodes for a Query tree
878 ****************************************************************************/
882 * a target entry (used in the transformed target list)
884 * one of resdom or fjoin is not NULL. a target list is
885 * ((<resdom | fjoin> expr) (<resdom | fjoin> expr) ...)
887 typedef struct TargetEntry
890 Resdom *resdom; /* fjoin overload this to be a list?? */
892 Node *expr; /* can be a list too */
897 * used in range tables. Some of the following are only used in one of
898 * the parsing, optimizing, execution stages.
900 * inFromCl marks those range variables that are listed in the from clause.
901 * In SQL, the targetlist can only refer to range variables listed in the
902 * from clause but POSTQUEL allows you to refer to tables not specified, in
903 * which case a range table entry will be generated. We use POSTQUEL
904 * semantics which is more powerful. However, we need SQL semantics in
905 * some cases (eg. when expanding a '*')
907 typedef struct RangeTblEntry
910 char *relname; /* real name of the relation */
911 char *refname; /* the reference name (specified in the
914 bool inh; /* inheritance? */
915 bool inFromCl; /* comes from From Clause */
916 bool skipAcl; /* skip ACL check in executor */
921 * used in the sort clause for retrieves and cursors
923 typedef struct SortClause
926 Resdom *resdom; /* attributes in tlist to be sorted */
927 Oid opoid; /* sort operators */
932 * used in the GROUP BY clause
934 typedef struct GroupClause
937 TargetEntry *entry; /* attributes to group on */
938 Oid grpOpoid; /* the sort operator to use */
941 #endif /* PARSENODES_H */