00001 /*------------------------------------------------------------------------- 00002 * 00003 * parsenodes.h 00004 * definitions for parse tree nodes 00005 * 00006 * Many of the node types used in parsetrees include a "location" field. 00007 * This is a byte (not character) offset in the original source text, to be 00008 * used for positioning an error cursor when there is an error related to 00009 * the node. Access to the original source text is needed to make use of 00010 * the location. 00011 * 00012 * 00013 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00014 * Portions Copyright (c) 1994, Regents of the University of California 00015 * 00016 * src/include/nodes/parsenodes.h 00017 * 00018 *------------------------------------------------------------------------- 00019 */ 00020 #ifndef PARSENODES_H 00021 #define PARSENODES_H 00022 00023 #include "nodes/bitmapset.h" 00024 #include "nodes/primnodes.h" 00025 #include "nodes/value.h" 00026 00027 /* Possible sources of a Query */ 00028 typedef enum QuerySource 00029 { 00030 QSRC_ORIGINAL, /* original parsetree (explicit query) */ 00031 QSRC_PARSER, /* added by parse analysis (now unused) */ 00032 QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */ 00033 QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */ 00034 QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */ 00035 } QuerySource; 00036 00037 /* Sort ordering options for ORDER BY and CREATE INDEX */ 00038 typedef enum SortByDir 00039 { 00040 SORTBY_DEFAULT, 00041 SORTBY_ASC, 00042 SORTBY_DESC, 00043 SORTBY_USING /* not allowed in CREATE INDEX ... */ 00044 } SortByDir; 00045 00046 typedef enum SortByNulls 00047 { 00048 SORTBY_NULLS_DEFAULT, 00049 SORTBY_NULLS_FIRST, 00050 SORTBY_NULLS_LAST 00051 } SortByNulls; 00052 00053 /* 00054 * Grantable rights are encoded so that we can OR them together in a bitmask. 00055 * The present representation of AclItem limits us to 16 distinct rights, 00056 * even though AclMode is defined as uint32. See utils/acl.h. 00057 * 00058 * Caution: changing these codes breaks stored ACLs, hence forces initdb. 00059 */ 00060 typedef uint32 AclMode; /* a bitmask of privilege bits */ 00061 00062 #define ACL_INSERT (1<<0) /* for relations */ 00063 #define ACL_SELECT (1<<1) 00064 #define ACL_UPDATE (1<<2) 00065 #define ACL_DELETE (1<<3) 00066 #define ACL_TRUNCATE (1<<4) 00067 #define ACL_REFERENCES (1<<5) 00068 #define ACL_TRIGGER (1<<6) 00069 #define ACL_EXECUTE (1<<7) /* for functions */ 00070 #define ACL_USAGE (1<<8) /* for languages, namespaces, FDWs, and 00071 * servers */ 00072 #define ACL_CREATE (1<<9) /* for namespaces and databases */ 00073 #define ACL_CREATE_TEMP (1<<10) /* for databases */ 00074 #define ACL_CONNECT (1<<11) /* for databases */ 00075 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */ 00076 #define ACL_NO_RIGHTS 0 00077 /* Currently, SELECT ... FOR [KEY] UPDATE/SHARE requires UPDATE privileges */ 00078 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE 00079 00080 00081 /***************************************************************************** 00082 * Query Tree 00083 *****************************************************************************/ 00084 00085 /* 00086 * Query - 00087 * Parse analysis turns all statements into a Query tree 00088 * for further processing by the rewriter and planner. 00089 * 00090 * Utility statements (i.e. non-optimizable statements) have the 00091 * utilityStmt field set, and the Query itself is mostly dummy. 00092 * DECLARE CURSOR is a special case: it is represented like a SELECT, 00093 * but the original DeclareCursorStmt is stored in utilityStmt. 00094 * 00095 * Planning converts a Query tree into a Plan tree headed by a PlannedStmt 00096 * node --- the Query structure is not used by the executor. 00097 */ 00098 typedef struct Query 00099 { 00100 NodeTag type; 00101 00102 CmdType commandType; /* select|insert|update|delete|utility */ 00103 00104 QuerySource querySource; /* where did I come from? */ 00105 00106 uint32 queryId; /* query identifier (can be set by plugins) */ 00107 00108 bool canSetTag; /* do I set the command result tag? */ 00109 00110 Node *utilityStmt; /* non-null if this is DECLARE CURSOR or a 00111 * non-optimizable statement */ 00112 00113 int resultRelation; /* rtable index of target relation for 00114 * INSERT/UPDATE/DELETE; 0 for SELECT */ 00115 00116 bool hasAggs; /* has aggregates in tlist or havingQual */ 00117 bool hasWindowFuncs; /* has window functions in tlist */ 00118 bool hasSubLinks; /* has subquery SubLink */ 00119 bool hasDistinctOn; /* distinctClause is from DISTINCT ON */ 00120 bool hasRecursive; /* WITH RECURSIVE was specified */ 00121 bool hasModifyingCTE; /* has INSERT/UPDATE/DELETE in WITH */ 00122 bool hasForUpdate; /* FOR [KEY] UPDATE/SHARE was specified */ 00123 00124 List *cteList; /* WITH list (of CommonTableExpr's) */ 00125 00126 List *rtable; /* list of range table entries */ 00127 FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */ 00128 00129 List *targetList; /* target list (of TargetEntry) */ 00130 00131 List *returningList; /* return-values list (of TargetEntry) */ 00132 00133 List *groupClause; /* a list of SortGroupClause's */ 00134 00135 Node *havingQual; /* qualifications applied to groups */ 00136 00137 List *windowClause; /* a list of WindowClause's */ 00138 00139 List *distinctClause; /* a list of SortGroupClause's */ 00140 00141 List *sortClause; /* a list of SortGroupClause's */ 00142 00143 Node *limitOffset; /* # of result tuples to skip (int8 expr) */ 00144 Node *limitCount; /* # of result tuples to return (int8 expr) */ 00145 00146 List *rowMarks; /* a list of RowMarkClause's */ 00147 00148 Node *setOperations; /* set-operation tree if this is top level of 00149 * a UNION/INTERSECT/EXCEPT query */ 00150 00151 List *constraintDeps; /* a list of pg_constraint OIDs that the query 00152 * depends on to be semantically valid */ 00153 } Query; 00154 00155 00156 /**************************************************************************** 00157 * Supporting data structures for Parse Trees 00158 * 00159 * Most of these node types appear in raw parsetrees output by the grammar, 00160 * and get transformed to something else by the analyzer. A few of them 00161 * are used as-is in transformed querytrees. 00162 ****************************************************************************/ 00163 00164 /* 00165 * TypeName - specifies a type in definitions 00166 * 00167 * For TypeName structures generated internally, it is often easier to 00168 * specify the type by OID than by name. If "names" is NIL then the 00169 * actual type OID is given by typeOid, otherwise typeOid is unused. 00170 * Similarly, if "typmods" is NIL then the actual typmod is expected to 00171 * be prespecified in typemod, otherwise typemod is unused. 00172 * 00173 * If pct_type is TRUE, then names is actually a field name and we look up 00174 * the type of that field. Otherwise (the normal case), names is a type 00175 * name possibly qualified with schema and database name. 00176 */ 00177 typedef struct TypeName 00178 { 00179 NodeTag type; 00180 List *names; /* qualified name (list of Value strings) */ 00181 Oid typeOid; /* type identified by OID */ 00182 bool setof; /* is a set? */ 00183 bool pct_type; /* %TYPE specified? */ 00184 List *typmods; /* type modifier expression(s) */ 00185 int32 typemod; /* prespecified type modifier */ 00186 List *arrayBounds; /* array bounds */ 00187 int location; /* token location, or -1 if unknown */ 00188 } TypeName; 00189 00190 /* 00191 * ColumnRef - specifies a reference to a column, or possibly a whole tuple 00192 * 00193 * The "fields" list must be nonempty. It can contain string Value nodes 00194 * (representing names) and A_Star nodes (representing occurrence of a '*'). 00195 * Currently, A_Star must appear only as the last list element --- the grammar 00196 * is responsible for enforcing this! 00197 * 00198 * Note: any array subscripting or selection of fields from composite columns 00199 * is represented by an A_Indirection node above the ColumnRef. However, 00200 * for simplicity in the normal case, initial field selection from a table 00201 * name is represented within ColumnRef and not by adding A_Indirection. 00202 */ 00203 typedef struct ColumnRef 00204 { 00205 NodeTag type; 00206 List *fields; /* field names (Value strings) or A_Star */ 00207 int location; /* token location, or -1 if unknown */ 00208 } ColumnRef; 00209 00210 /* 00211 * ParamRef - specifies a $n parameter reference 00212 */ 00213 typedef struct ParamRef 00214 { 00215 NodeTag type; 00216 int number; /* the number of the parameter */ 00217 int location; /* token location, or -1 if unknown */ 00218 } ParamRef; 00219 00220 /* 00221 * A_Expr - infix, prefix, and postfix expressions 00222 */ 00223 typedef enum A_Expr_Kind 00224 { 00225 AEXPR_OP, /* normal operator */ 00226 AEXPR_AND, /* booleans - name field is unused */ 00227 AEXPR_OR, 00228 AEXPR_NOT, 00229 AEXPR_OP_ANY, /* scalar op ANY (array) */ 00230 AEXPR_OP_ALL, /* scalar op ALL (array) */ 00231 AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */ 00232 AEXPR_NULLIF, /* NULLIF - name must be "=" */ 00233 AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */ 00234 AEXPR_IN /* [NOT] IN - name must be "=" or "<>" */ 00235 } A_Expr_Kind; 00236 00237 typedef struct A_Expr 00238 { 00239 NodeTag type; 00240 A_Expr_Kind kind; /* see above */ 00241 List *name; /* possibly-qualified name of operator */ 00242 Node *lexpr; /* left argument, or NULL if none */ 00243 Node *rexpr; /* right argument, or NULL if none */ 00244 int location; /* token location, or -1 if unknown */ 00245 } A_Expr; 00246 00247 /* 00248 * A_Const - a literal constant 00249 */ 00250 typedef struct A_Const 00251 { 00252 NodeTag type; 00253 Value val; /* value (includes type info, see value.h) */ 00254 int location; /* token location, or -1 if unknown */ 00255 } A_Const; 00256 00257 /* 00258 * TypeCast - a CAST expression 00259 */ 00260 typedef struct TypeCast 00261 { 00262 NodeTag type; 00263 Node *arg; /* the expression being casted */ 00264 TypeName *typeName; /* the target type */ 00265 int location; /* token location, or -1 if unknown */ 00266 } TypeCast; 00267 00268 /* 00269 * CollateClause - a COLLATE expression 00270 */ 00271 typedef struct CollateClause 00272 { 00273 NodeTag type; 00274 Node *arg; /* input expression */ 00275 List *collname; /* possibly-qualified collation name */ 00276 int location; /* token location, or -1 if unknown */ 00277 } CollateClause; 00278 00279 /* 00280 * FuncCall - a function or aggregate invocation 00281 * 00282 * agg_order (if not NIL) indicates we saw 'foo(... ORDER BY ...)'. 00283 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct 00284 * indicates we saw 'foo(DISTINCT ...)'. In any of these cases, the 00285 * construct *must* be an aggregate call. Otherwise, it might be either an 00286 * aggregate or some other kind of function. However, if OVER is present 00287 * it had better be an aggregate or window function. 00288 */ 00289 typedef struct FuncCall 00290 { 00291 NodeTag type; 00292 List *funcname; /* qualified name of function */ 00293 List *args; /* the arguments (list of exprs) */ 00294 List *agg_order; /* ORDER BY (list of SortBy) */ 00295 bool agg_star; /* argument was really '*' */ 00296 bool agg_distinct; /* arguments were labeled DISTINCT */ 00297 bool func_variadic; /* last argument was labeled VARIADIC */ 00298 struct WindowDef *over; /* OVER clause, if any */ 00299 int location; /* token location, or -1 if unknown */ 00300 } FuncCall; 00301 00302 /* 00303 * A_Star - '*' representing all columns of a table or compound field 00304 * 00305 * This can appear within ColumnRef.fields, A_Indirection.indirection, and 00306 * ResTarget.indirection lists. 00307 */ 00308 typedef struct A_Star 00309 { 00310 NodeTag type; 00311 } A_Star; 00312 00313 /* 00314 * A_Indices - array subscript or slice bounds ([lidx:uidx] or [uidx]) 00315 */ 00316 typedef struct A_Indices 00317 { 00318 NodeTag type; 00319 Node *lidx; /* NULL if it's a single subscript */ 00320 Node *uidx; 00321 } A_Indices; 00322 00323 /* 00324 * A_Indirection - select a field and/or array element from an expression 00325 * 00326 * The indirection list can contain A_Indices nodes (representing 00327 * subscripting), string Value nodes (representing field selection --- the 00328 * string value is the name of the field to select), and A_Star nodes 00329 * (representing selection of all fields of a composite type). 00330 * For example, a complex selection operation like 00331 * (foo).field1[42][7].field2 00332 * would be represented with a single A_Indirection node having a 4-element 00333 * indirection list. 00334 * 00335 * Currently, A_Star must appear only as the last list element --- the grammar 00336 * is responsible for enforcing this! 00337 */ 00338 typedef struct A_Indirection 00339 { 00340 NodeTag type; 00341 Node *arg; /* the thing being selected from */ 00342 List *indirection; /* subscripts and/or field names and/or * */ 00343 } A_Indirection; 00344 00345 /* 00346 * A_ArrayExpr - an ARRAY[] construct 00347 */ 00348 typedef struct A_ArrayExpr 00349 { 00350 NodeTag type; 00351 List *elements; /* array element expressions */ 00352 int location; /* token location, or -1 if unknown */ 00353 } A_ArrayExpr; 00354 00355 /* 00356 * ResTarget - 00357 * result target (used in target list of pre-transformed parse trees) 00358 * 00359 * In a SELECT target list, 'name' is the column label from an 00360 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the 00361 * value expression itself. The 'indirection' field is not used. 00362 * 00363 * INSERT uses ResTarget in its target-column-names list. Here, 'name' is 00364 * the name of the destination column, 'indirection' stores any subscripts 00365 * attached to the destination, and 'val' is not used. 00366 * 00367 * In an UPDATE target list, 'name' is the name of the destination column, 00368 * 'indirection' stores any subscripts attached to the destination, and 00369 * 'val' is the expression to assign. 00370 * 00371 * See A_Indirection for more info about what can appear in 'indirection'. 00372 */ 00373 typedef struct ResTarget 00374 { 00375 NodeTag type; 00376 char *name; /* column name or NULL */ 00377 List *indirection; /* subscripts, field names, and '*', or NIL */ 00378 Node *val; /* the value expression to compute or assign */ 00379 int location; /* token location, or -1 if unknown */ 00380 } ResTarget; 00381 00382 /* 00383 * SortBy - for ORDER BY clause 00384 */ 00385 typedef struct SortBy 00386 { 00387 NodeTag type; 00388 Node *node; /* expression to sort on */ 00389 SortByDir sortby_dir; /* ASC/DESC/USING/default */ 00390 SortByNulls sortby_nulls; /* NULLS FIRST/LAST */ 00391 List *useOp; /* name of op to use, if SORTBY_USING */ 00392 int location; /* operator location, or -1 if none/unknown */ 00393 } SortBy; 00394 00395 /* 00396 * WindowDef - raw representation of WINDOW and OVER clauses 00397 * 00398 * For entries in a WINDOW list, "name" is the window name being defined. 00399 * For OVER clauses, we use "name" for the "OVER window" syntax, or "refname" 00400 * for the "OVER (window)" syntax, which is subtly different --- the latter 00401 * implies overriding the window frame clause. 00402 */ 00403 typedef struct WindowDef 00404 { 00405 NodeTag type; 00406 char *name; /* window's own name */ 00407 char *refname; /* referenced window name, if any */ 00408 List *partitionClause; /* PARTITION BY expression list */ 00409 List *orderClause; /* ORDER BY (list of SortBy) */ 00410 int frameOptions; /* frame_clause options, see below */ 00411 Node *startOffset; /* expression for starting bound, if any */ 00412 Node *endOffset; /* expression for ending bound, if any */ 00413 int location; /* parse location, or -1 if none/unknown */ 00414 } WindowDef; 00415 00416 /* 00417 * frameOptions is an OR of these bits. The NONDEFAULT and BETWEEN bits are 00418 * used so that ruleutils.c can tell which properties were specified and 00419 * which were defaulted; the correct behavioral bits must be set either way. 00420 * The START_foo and END_foo options must come in pairs of adjacent bits for 00421 * the convenience of gram.y, even though some of them are useless/invalid. 00422 * We will need more bits (and fields) to cover the full SQL:2008 option set. 00423 */ 00424 #define FRAMEOPTION_NONDEFAULT 0x00001 /* any specified? */ 00425 #define FRAMEOPTION_RANGE 0x00002 /* RANGE behavior */ 00426 #define FRAMEOPTION_ROWS 0x00004 /* ROWS behavior */ 00427 #define FRAMEOPTION_BETWEEN 0x00008 /* BETWEEN given? */ 00428 #define FRAMEOPTION_START_UNBOUNDED_PRECEDING 0x00010 /* start is U. P. */ 00429 #define FRAMEOPTION_END_UNBOUNDED_PRECEDING 0x00020 /* (disallowed) */ 00430 #define FRAMEOPTION_START_UNBOUNDED_FOLLOWING 0x00040 /* (disallowed) */ 00431 #define FRAMEOPTION_END_UNBOUNDED_FOLLOWING 0x00080 /* end is U. F. */ 00432 #define FRAMEOPTION_START_CURRENT_ROW 0x00100 /* start is C. R. */ 00433 #define FRAMEOPTION_END_CURRENT_ROW 0x00200 /* end is C. R. */ 00434 #define FRAMEOPTION_START_VALUE_PRECEDING 0x00400 /* start is V. P. */ 00435 #define FRAMEOPTION_END_VALUE_PRECEDING 0x00800 /* end is V. P. */ 00436 #define FRAMEOPTION_START_VALUE_FOLLOWING 0x01000 /* start is V. F. */ 00437 #define FRAMEOPTION_END_VALUE_FOLLOWING 0x02000 /* end is V. F. */ 00438 00439 #define FRAMEOPTION_START_VALUE \ 00440 (FRAMEOPTION_START_VALUE_PRECEDING | FRAMEOPTION_START_VALUE_FOLLOWING) 00441 #define FRAMEOPTION_END_VALUE \ 00442 (FRAMEOPTION_END_VALUE_PRECEDING | FRAMEOPTION_END_VALUE_FOLLOWING) 00443 00444 #define FRAMEOPTION_DEFAULTS \ 00445 (FRAMEOPTION_RANGE | FRAMEOPTION_START_UNBOUNDED_PRECEDING | \ 00446 FRAMEOPTION_END_CURRENT_ROW) 00447 00448 /* 00449 * RangeSubselect - subquery appearing in a FROM clause 00450 */ 00451 typedef struct RangeSubselect 00452 { 00453 NodeTag type; 00454 bool lateral; /* does it have LATERAL prefix? */ 00455 Node *subquery; /* the untransformed sub-select clause */ 00456 Alias *alias; /* table alias & optional column aliases */ 00457 } RangeSubselect; 00458 00459 /* 00460 * RangeFunction - function call appearing in a FROM clause 00461 */ 00462 typedef struct RangeFunction 00463 { 00464 NodeTag type; 00465 bool lateral; /* does it have LATERAL prefix? */ 00466 Node *funccallnode; /* untransformed function call tree */ 00467 Alias *alias; /* table alias & optional column aliases */ 00468 List *coldeflist; /* list of ColumnDef nodes to describe result 00469 * of function returning RECORD */ 00470 } RangeFunction; 00471 00472 /* 00473 * ColumnDef - column definition (used in various creates) 00474 * 00475 * If the column has a default value, we may have the value expression 00476 * in either "raw" form (an untransformed parse tree) or "cooked" form 00477 * (a post-parse-analysis, executable expression tree), depending on 00478 * how this ColumnDef node was created (by parsing, or by inheritance 00479 * from an existing relation). We should never have both in the same node! 00480 * 00481 * Similarly, we may have a COLLATE specification in either raw form 00482 * (represented as a CollateClause with arg==NULL) or cooked form 00483 * (the collation's OID). 00484 * 00485 * The constraints list may contain a CONSTR_DEFAULT item in a raw 00486 * parsetree produced by gram.y, but transformCreateStmt will remove 00487 * the item and set raw_default instead. CONSTR_DEFAULT items 00488 * should not appear in any subsequent processing. 00489 */ 00490 typedef struct ColumnDef 00491 { 00492 NodeTag type; 00493 char *colname; /* name of column */ 00494 TypeName *typeName; /* type of column */ 00495 int inhcount; /* number of times column is inherited */ 00496 bool is_local; /* column has local (non-inherited) def'n */ 00497 bool is_not_null; /* NOT NULL constraint specified? */ 00498 bool is_from_type; /* column definition came from table type */ 00499 char storage; /* attstorage setting, or 0 for default */ 00500 Node *raw_default; /* default value (untransformed parse tree) */ 00501 Node *cooked_default; /* default value (transformed expr tree) */ 00502 CollateClause *collClause; /* untransformed COLLATE spec, if any */ 00503 Oid collOid; /* collation OID (InvalidOid if not set) */ 00504 List *constraints; /* other constraints on column */ 00505 List *fdwoptions; /* per-column FDW options */ 00506 } ColumnDef; 00507 00508 /* 00509 * TableLikeClause - CREATE TABLE ( ... LIKE ... ) clause 00510 */ 00511 typedef struct TableLikeClause 00512 { 00513 NodeTag type; 00514 RangeVar *relation; 00515 bits32 options; /* OR of TableLikeOption flags */ 00516 } TableLikeClause; 00517 00518 typedef enum TableLikeOption 00519 { 00520 CREATE_TABLE_LIKE_DEFAULTS = 1 << 0, 00521 CREATE_TABLE_LIKE_CONSTRAINTS = 1 << 1, 00522 CREATE_TABLE_LIKE_INDEXES = 1 << 2, 00523 CREATE_TABLE_LIKE_STORAGE = 1 << 3, 00524 CREATE_TABLE_LIKE_COMMENTS = 1 << 4, 00525 CREATE_TABLE_LIKE_ALL = 0x7FFFFFFF 00526 } TableLikeOption; 00527 00528 /* 00529 * IndexElem - index parameters (used in CREATE INDEX) 00530 * 00531 * For a plain index attribute, 'name' is the name of the table column to 00532 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and 00533 * 'expr' is the expression tree. 00534 */ 00535 typedef struct IndexElem 00536 { 00537 NodeTag type; 00538 char *name; /* name of attribute to index, or NULL */ 00539 Node *expr; /* expression to index, or NULL */ 00540 char *indexcolname; /* name for index column; NULL = default */ 00541 List *collation; /* name of collation; NIL = default */ 00542 List *opclass; /* name of desired opclass; NIL = default */ 00543 SortByDir ordering; /* ASC/DESC/default */ 00544 SortByNulls nulls_ordering; /* FIRST/LAST/default */ 00545 } IndexElem; 00546 00547 /* 00548 * DefElem - a generic "name = value" option definition 00549 * 00550 * In some contexts the name can be qualified. Also, certain SQL commands 00551 * allow a SET/ADD/DROP action to be attached to option settings, so it's 00552 * convenient to carry a field for that too. (Note: currently, it is our 00553 * practice that the grammar allows namespace and action only in statements 00554 * where they are relevant; C code can just ignore those fields in other 00555 * statements.) 00556 */ 00557 typedef enum DefElemAction 00558 { 00559 DEFELEM_UNSPEC, /* no action given */ 00560 DEFELEM_SET, 00561 DEFELEM_ADD, 00562 DEFELEM_DROP 00563 } DefElemAction; 00564 00565 typedef struct DefElem 00566 { 00567 NodeTag type; 00568 char *defnamespace; /* NULL if unqualified name */ 00569 char *defname; 00570 Node *arg; /* a (Value *) or a (TypeName *) */ 00571 DefElemAction defaction; /* unspecified action, or SET/ADD/DROP */ 00572 } DefElem; 00573 00574 /* 00575 * LockingClause - raw representation of FOR [NO KEY] UPDATE/[KEY] SHARE 00576 * options 00577 * 00578 * Note: lockedRels == NIL means "all relations in query". Otherwise it 00579 * is a list of RangeVar nodes. (We use RangeVar mainly because it carries 00580 * a location field --- currently, parse analysis insists on unqualified 00581 * names in LockingClause.) 00582 */ 00583 typedef enum LockClauseStrength 00584 { 00585 /* order is important -- see applyLockingClause */ 00586 LCS_FORKEYSHARE, 00587 LCS_FORSHARE, 00588 LCS_FORNOKEYUPDATE, 00589 LCS_FORUPDATE 00590 } LockClauseStrength; 00591 00592 typedef struct LockingClause 00593 { 00594 NodeTag type; 00595 List *lockedRels; /* FOR [KEY] UPDATE/SHARE relations */ 00596 LockClauseStrength strength; 00597 bool noWait; /* NOWAIT option */ 00598 } LockingClause; 00599 00600 /* 00601 * XMLSERIALIZE (in raw parse tree only) 00602 */ 00603 typedef struct XmlSerialize 00604 { 00605 NodeTag type; 00606 XmlOptionType xmloption; /* DOCUMENT or CONTENT */ 00607 Node *expr; 00608 TypeName *typeName; 00609 int location; /* token location, or -1 if unknown */ 00610 } XmlSerialize; 00611 00612 00613 /**************************************************************************** 00614 * Nodes for a Query tree 00615 ****************************************************************************/ 00616 00617 /*-------------------- 00618 * RangeTblEntry - 00619 * A range table is a List of RangeTblEntry nodes. 00620 * 00621 * A range table entry may represent a plain relation, a sub-select in 00622 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax 00623 * produces an RTE, not the implicit join resulting from multiple FROM 00624 * items. This is because we only need the RTE to deal with SQL features 00625 * like outer joins and join-output-column aliasing.) Other special 00626 * RTE types also exist, as indicated by RTEKind. 00627 * 00628 * Note that we consider RTE_RELATION to cover anything that has a pg_class 00629 * entry. relkind distinguishes the sub-cases. 00630 * 00631 * alias is an Alias node representing the AS alias-clause attached to the 00632 * FROM expression, or NULL if no clause. 00633 * 00634 * eref is the table reference name and column reference names (either 00635 * real or aliases). Note that system columns (OID etc) are not included 00636 * in the column list. 00637 * eref->aliasname is required to be present, and should generally be used 00638 * to identify the RTE for error messages etc. 00639 * 00640 * In RELATION RTEs, the colnames in both alias and eref are indexed by 00641 * physical attribute number; this means there must be colname entries for 00642 * dropped columns. When building an RTE we insert empty strings ("") for 00643 * dropped columns. Note however that a stored rule may have nonempty 00644 * colnames for columns dropped since the rule was created (and for that 00645 * matter the colnames might be out of date due to column renamings). 00646 * The same comments apply to FUNCTION RTEs when the function's return type 00647 * is a named composite type. 00648 * 00649 * In JOIN RTEs, the colnames in both alias and eref are one-to-one with 00650 * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when 00651 * those columns are known to be dropped at parse time. Again, however, 00652 * a stored rule might contain entries for columns dropped since the rule 00653 * was created. (This is only possible for columns not actually referenced 00654 * in the rule.) When loading a stored rule, we replace the joinaliasvars 00655 * items for any such columns with NULL Consts. (We can't simply delete 00656 * them from the joinaliasvars list, because that would affect the attnums 00657 * of Vars referencing the rest of the list.) 00658 * 00659 * inh is TRUE for relation references that should be expanded to include 00660 * inheritance children, if the rel has any. This *must* be FALSE for 00661 * RTEs other than RTE_RELATION entries. 00662 * 00663 * inFromCl marks those range variables that are listed in the FROM clause. 00664 * It's false for RTEs that are added to a query behind the scenes, such 00665 * as the NEW and OLD variables for a rule, or the subqueries of a UNION. 00666 * This flag is not used anymore during parsing, since the parser now uses 00667 * a separate "namespace" data structure to control visibility, but it is 00668 * needed by ruleutils.c to determine whether RTEs should be shown in 00669 * decompiled queries. 00670 * 00671 * requiredPerms and checkAsUser specify run-time access permissions 00672 * checks to be performed at query startup. The user must have *all* 00673 * of the permissions that are OR'd together in requiredPerms (zero 00674 * indicates no permissions checking). If checkAsUser is not zero, 00675 * then do the permissions checks using the access rights of that user, 00676 * not the current effective user ID. (This allows rules to act as 00677 * setuid gateways.) Permissions checks only apply to RELATION RTEs. 00678 * 00679 * For SELECT/INSERT/UPDATE permissions, if the user doesn't have 00680 * table-wide permissions then it is sufficient to have the permissions 00681 * on all columns identified in selectedCols (for SELECT) and/or 00682 * modifiedCols (for INSERT/UPDATE; we can tell which from the query type). 00683 * selectedCols and modifiedCols are bitmapsets, which cannot have negative 00684 * integer members, so we subtract FirstLowInvalidHeapAttributeNumber from 00685 * column numbers before storing them in these fields. A whole-row Var 00686 * reference is represented by setting the bit for InvalidAttrNumber. 00687 *-------------------- 00688 */ 00689 typedef enum RTEKind 00690 { 00691 RTE_RELATION, /* ordinary relation reference */ 00692 RTE_SUBQUERY, /* subquery in FROM */ 00693 RTE_JOIN, /* join */ 00694 RTE_FUNCTION, /* function in FROM */ 00695 RTE_VALUES, /* VALUES (<exprlist>), (<exprlist>), ... */ 00696 RTE_CTE /* common table expr (WITH list element) */ 00697 } RTEKind; 00698 00699 typedef struct RangeTblEntry 00700 { 00701 NodeTag type; 00702 00703 RTEKind rtekind; /* see above */ 00704 00705 /* 00706 * XXX the fields applicable to only some rte kinds should be merged into 00707 * a union. I didn't do this yet because the diffs would impact a lot of 00708 * code that is being actively worked on. FIXME someday. 00709 */ 00710 00711 /* 00712 * Fields valid for a plain relation RTE (else zero): 00713 */ 00714 Oid relid; /* OID of the relation */ 00715 char relkind; /* relation kind (see pg_class.relkind) */ 00716 00717 /* 00718 * Fields valid for a subquery RTE (else NULL): 00719 */ 00720 Query *subquery; /* the sub-query */ 00721 bool security_barrier; /* is from security_barrier view? */ 00722 00723 /* 00724 * Fields valid for a join RTE (else NULL/zero): 00725 * 00726 * joinaliasvars is a list of Vars or COALESCE expressions corresponding 00727 * to the columns of the join result. An alias Var referencing column K 00728 * of the join result can be replaced by the K'th element of joinaliasvars 00729 * --- but to simplify the task of reverse-listing aliases correctly, we 00730 * do not do that until planning time. In a Query loaded from a stored 00731 * rule, it is also possible for joinaliasvars items to be NULL Consts, 00732 * denoting columns dropped since the rule was made. 00733 */ 00734 JoinType jointype; /* type of join */ 00735 List *joinaliasvars; /* list of alias-var expansions */ 00736 00737 /* 00738 * Fields valid for a function RTE (else NULL): 00739 * 00740 * If the function returns RECORD, funccoltypes lists the column types 00741 * declared in the RTE's column type specification, funccoltypmods lists 00742 * their declared typmods, funccolcollations their collations. Otherwise, 00743 * those fields are NIL. 00744 */ 00745 Node *funcexpr; /* expression tree for func call */ 00746 List *funccoltypes; /* OID list of column type OIDs */ 00747 List *funccoltypmods; /* integer list of column typmods */ 00748 List *funccolcollations; /* OID list of column collation OIDs */ 00749 00750 /* 00751 * Fields valid for a values RTE (else NIL): 00752 */ 00753 List *values_lists; /* list of expression lists */ 00754 List *values_collations; /* OID list of column collation OIDs */ 00755 00756 /* 00757 * Fields valid for a CTE RTE (else NULL/zero): 00758 */ 00759 char *ctename; /* name of the WITH list item */ 00760 Index ctelevelsup; /* number of query levels up */ 00761 bool self_reference; /* is this a recursive self-reference? */ 00762 List *ctecoltypes; /* OID list of column type OIDs */ 00763 List *ctecoltypmods; /* integer list of column typmods */ 00764 List *ctecolcollations; /* OID list of column collation OIDs */ 00765 00766 /* 00767 * Fields valid in all RTEs: 00768 */ 00769 Alias *alias; /* user-written alias clause, if any */ 00770 Alias *eref; /* expanded reference names */ 00771 bool lateral; /* subquery, function, or values is LATERAL? */ 00772 bool inh; /* inheritance requested? */ 00773 bool inFromCl; /* present in FROM clause? */ 00774 AclMode requiredPerms; /* bitmask of required access permissions */ 00775 Oid checkAsUser; /* if valid, check access as this role */ 00776 Bitmapset *selectedCols; /* columns needing SELECT permission */ 00777 Bitmapset *modifiedCols; /* columns needing INSERT/UPDATE permission */ 00778 } RangeTblEntry; 00779 00780 /* 00781 * SortGroupClause - 00782 * representation of ORDER BY, GROUP BY, PARTITION BY, 00783 * DISTINCT, DISTINCT ON items 00784 * 00785 * You might think that ORDER BY is only interested in defining ordering, 00786 * and GROUP/DISTINCT are only interested in defining equality. However, 00787 * one way to implement grouping is to sort and then apply a "uniq"-like 00788 * filter. So it's also interesting to keep track of possible sort operators 00789 * for GROUP/DISTINCT, and in particular to try to sort for the grouping 00790 * in a way that will also yield a requested ORDER BY ordering. So we need 00791 * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates 00792 * the decision to give them the same representation. 00793 * 00794 * tleSortGroupRef must match ressortgroupref of exactly one entry of the 00795 * query's targetlist; that is the expression to be sorted or grouped by. 00796 * eqop is the OID of the equality operator. 00797 * sortop is the OID of the ordering operator (a "<" or ">" operator), 00798 * or InvalidOid if not available. 00799 * nulls_first means about what you'd expect. If sortop is InvalidOid 00800 * then nulls_first is meaningless and should be set to false. 00801 * hashable is TRUE if eqop is hashable (note this condition also depends 00802 * on the datatype of the input expression). 00803 * 00804 * In an ORDER BY item, all fields must be valid. (The eqop isn't essential 00805 * here, but it's cheap to get it along with the sortop, and requiring it 00806 * to be valid eases comparisons to grouping items.) Note that this isn't 00807 * actually enough information to determine an ordering: if the sortop is 00808 * collation-sensitive, a collation OID is needed too. We don't store the 00809 * collation in SortGroupClause because it's not available at the time the 00810 * parser builds the SortGroupClause; instead, consult the exposed collation 00811 * of the referenced targetlist expression to find out what it is. 00812 * 00813 * In a grouping item, eqop must be valid. If the eqop is a btree equality 00814 * operator, then sortop should be set to a compatible ordering operator. 00815 * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that 00816 * the query presents for the same tlist item. If there is none, we just 00817 * use the default ordering op for the datatype. 00818 * 00819 * If the tlist item's type has a hash opclass but no btree opclass, then 00820 * we will set eqop to the hash equality operator, sortop to InvalidOid, 00821 * and nulls_first to false. A grouping item of this kind can only be 00822 * implemented by hashing, and of course it'll never match an ORDER BY item. 00823 * 00824 * The hashable flag is provided since we generally have the requisite 00825 * information readily available when the SortGroupClause is constructed, 00826 * and it's relatively expensive to get it again later. Note there is no 00827 * need for a "sortable" flag since OidIsValid(sortop) serves the purpose. 00828 * 00829 * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses. 00830 * In SELECT DISTINCT, the distinctClause list is as long or longer than the 00831 * sortClause list, while in SELECT DISTINCT ON it's typically shorter. 00832 * The two lists must match up to the end of the shorter one --- the parser 00833 * rearranges the distinctClause if necessary to make this true. (This 00834 * restriction ensures that only one sort step is needed to both satisfy the 00835 * ORDER BY and set up for the Unique step. This is semantically necessary 00836 * for DISTINCT ON, and presents no real drawback for DISTINCT.) 00837 */ 00838 typedef struct SortGroupClause 00839 { 00840 NodeTag type; 00841 Index tleSortGroupRef; /* reference into targetlist */ 00842 Oid eqop; /* the equality operator ('=' op) */ 00843 Oid sortop; /* the ordering operator ('<' op), or 0 */ 00844 bool nulls_first; /* do NULLs come before normal values? */ 00845 bool hashable; /* can eqop be implemented by hashing? */ 00846 } SortGroupClause; 00847 00848 /* 00849 * WindowClause - 00850 * transformed representation of WINDOW and OVER clauses 00851 * 00852 * A parsed Query's windowClause list contains these structs. "name" is set 00853 * if the clause originally came from WINDOW, and is NULL if it originally 00854 * was an OVER clause (but note that we collapse out duplicate OVERs). 00855 * partitionClause and orderClause are lists of SortGroupClause structs. 00856 * winref is an ID number referenced by WindowFunc nodes; it must be unique 00857 * among the members of a Query's windowClause list. 00858 * When refname isn't null, the partitionClause is always copied from there; 00859 * the orderClause might or might not be copied (see copiedOrder); the framing 00860 * options are never copied, per spec. 00861 */ 00862 typedef struct WindowClause 00863 { 00864 NodeTag type; 00865 char *name; /* window name (NULL in an OVER clause) */ 00866 char *refname; /* referenced window name, if any */ 00867 List *partitionClause; /* PARTITION BY list */ 00868 List *orderClause; /* ORDER BY list */ 00869 int frameOptions; /* frame_clause options, see WindowDef */ 00870 Node *startOffset; /* expression for starting bound, if any */ 00871 Node *endOffset; /* expression for ending bound, if any */ 00872 Index winref; /* ID referenced by window functions */ 00873 bool copiedOrder; /* did we copy orderClause from refname? */ 00874 } WindowClause; 00875 00876 /* 00877 * RowMarkClause - 00878 * parser output representation of FOR [KEY] UPDATE/SHARE clauses 00879 * 00880 * Query.rowMarks contains a separate RowMarkClause node for each relation 00881 * identified as a FOR [KEY] UPDATE/SHARE target. If one of these clauses 00882 * is applied to a subquery, we generate RowMarkClauses for all normal and 00883 * subquery rels in the subquery, but they are marked pushedDown = true to 00884 * distinguish them from clauses that were explicitly written at this query 00885 * level. Also, Query.hasForUpdate tells whether there were explicit FOR 00886 * UPDATE/SHARE/KEY SHARE clauses in the current query level. 00887 */ 00888 typedef struct RowMarkClause 00889 { 00890 NodeTag type; 00891 Index rti; /* range table index of target relation */ 00892 LockClauseStrength strength; 00893 bool noWait; /* NOWAIT option */ 00894 bool pushedDown; /* pushed down from higher query level? */ 00895 } RowMarkClause; 00896 00897 /* 00898 * WithClause - 00899 * representation of WITH clause 00900 * 00901 * Note: WithClause does not propagate into the Query representation; 00902 * but CommonTableExpr does. 00903 */ 00904 typedef struct WithClause 00905 { 00906 NodeTag type; 00907 List *ctes; /* list of CommonTableExprs */ 00908 bool recursive; /* true = WITH RECURSIVE */ 00909 int location; /* token location, or -1 if unknown */ 00910 } WithClause; 00911 00912 /* 00913 * CommonTableExpr - 00914 * representation of WITH list element 00915 * 00916 * We don't currently support the SEARCH or CYCLE clause. 00917 */ 00918 typedef struct CommonTableExpr 00919 { 00920 NodeTag type; 00921 char *ctename; /* query name (never qualified) */ 00922 List *aliascolnames; /* optional list of column names */ 00923 /* SelectStmt/InsertStmt/etc before parse analysis, Query afterwards: */ 00924 Node *ctequery; /* the CTE's subquery */ 00925 int location; /* token location, or -1 if unknown */ 00926 /* These fields are set during parse analysis: */ 00927 bool cterecursive; /* is this CTE actually recursive? */ 00928 int cterefcount; /* number of RTEs referencing this CTE 00929 * (excluding internal self-references) */ 00930 List *ctecolnames; /* list of output column names */ 00931 List *ctecoltypes; /* OID list of output column type OIDs */ 00932 List *ctecoltypmods; /* integer list of output column typmods */ 00933 List *ctecolcollations; /* OID list of column collation OIDs */ 00934 } CommonTableExpr; 00935 00936 /* Convenience macro to get the output tlist of a CTE's query */ 00937 #define GetCTETargetList(cte) \ 00938 (AssertMacro(IsA((cte)->ctequery, Query)), \ 00939 ((Query *) (cte)->ctequery)->commandType == CMD_SELECT ? \ 00940 ((Query *) (cte)->ctequery)->targetList : \ 00941 ((Query *) (cte)->ctequery)->returningList) 00942 00943 00944 /***************************************************************************** 00945 * Optimizable Statements 00946 *****************************************************************************/ 00947 00948 /* ---------------------- 00949 * Insert Statement 00950 * 00951 * The source expression is represented by SelectStmt for both the 00952 * SELECT and VALUES cases. If selectStmt is NULL, then the query 00953 * is INSERT ... DEFAULT VALUES. 00954 * ---------------------- 00955 */ 00956 typedef struct InsertStmt 00957 { 00958 NodeTag type; 00959 RangeVar *relation; /* relation to insert into */ 00960 List *cols; /* optional: names of the target columns */ 00961 Node *selectStmt; /* the source SELECT/VALUES, or NULL */ 00962 List *returningList; /* list of expressions to return */ 00963 WithClause *withClause; /* WITH clause */ 00964 } InsertStmt; 00965 00966 /* ---------------------- 00967 * Delete Statement 00968 * ---------------------- 00969 */ 00970 typedef struct DeleteStmt 00971 { 00972 NodeTag type; 00973 RangeVar *relation; /* relation to delete from */ 00974 List *usingClause; /* optional using clause for more tables */ 00975 Node *whereClause; /* qualifications */ 00976 List *returningList; /* list of expressions to return */ 00977 WithClause *withClause; /* WITH clause */ 00978 } DeleteStmt; 00979 00980 /* ---------------------- 00981 * Update Statement 00982 * ---------------------- 00983 */ 00984 typedef struct UpdateStmt 00985 { 00986 NodeTag type; 00987 RangeVar *relation; /* relation to update */ 00988 List *targetList; /* the target list (of ResTarget) */ 00989 Node *whereClause; /* qualifications */ 00990 List *fromClause; /* optional from clause for more tables */ 00991 List *returningList; /* list of expressions to return */ 00992 WithClause *withClause; /* WITH clause */ 00993 } UpdateStmt; 00994 00995 /* ---------------------- 00996 * Select Statement 00997 * 00998 * A "simple" SELECT is represented in the output of gram.y by a single 00999 * SelectStmt node; so is a VALUES construct. A query containing set 01000 * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt 01001 * nodes, in which the leaf nodes are component SELECTs and the internal nodes 01002 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node 01003 * type for both leaf and internal nodes allows gram.y to stick ORDER BY, 01004 * LIMIT, etc, clause values into a SELECT statement without worrying 01005 * whether it is a simple or compound SELECT. 01006 * ---------------------- 01007 */ 01008 typedef enum SetOperation 01009 { 01010 SETOP_NONE = 0, 01011 SETOP_UNION, 01012 SETOP_INTERSECT, 01013 SETOP_EXCEPT 01014 } SetOperation; 01015 01016 typedef struct SelectStmt 01017 { 01018 NodeTag type; 01019 01020 /* 01021 * These fields are used only in "leaf" SelectStmts. 01022 */ 01023 List *distinctClause; /* NULL, list of DISTINCT ON exprs, or 01024 * lcons(NIL,NIL) for all (SELECT DISTINCT) */ 01025 IntoClause *intoClause; /* target for SELECT INTO */ 01026 List *targetList; /* the target list (of ResTarget) */ 01027 List *fromClause; /* the FROM clause */ 01028 Node *whereClause; /* WHERE qualification */ 01029 List *groupClause; /* GROUP BY clauses */ 01030 Node *havingClause; /* HAVING conditional-expression */ 01031 List *windowClause; /* WINDOW window_name AS (...), ... */ 01032 01033 /* 01034 * In a "leaf" node representing a VALUES list, the above fields are all 01035 * null, and instead this field is set. Note that the elements of the 01036 * sublists are just expressions, without ResTarget decoration. Also note 01037 * that a list element can be DEFAULT (represented as a SetToDefault 01038 * node), regardless of the context of the VALUES list. It's up to parse 01039 * analysis to reject that where not valid. 01040 */ 01041 List *valuesLists; /* untransformed list of expression lists */ 01042 01043 /* 01044 * These fields are used in both "leaf" SelectStmts and upper-level 01045 * SelectStmts. 01046 */ 01047 List *sortClause; /* sort clause (a list of SortBy's) */ 01048 Node *limitOffset; /* # of result tuples to skip */ 01049 Node *limitCount; /* # of result tuples to return */ 01050 List *lockingClause; /* FOR UPDATE (list of LockingClause's) */ 01051 WithClause *withClause; /* WITH clause */ 01052 01053 /* 01054 * These fields are used only in upper-level SelectStmts. 01055 */ 01056 SetOperation op; /* type of set op */ 01057 bool all; /* ALL specified? */ 01058 struct SelectStmt *larg; /* left child */ 01059 struct SelectStmt *rarg; /* right child */ 01060 /* Eventually add fields for CORRESPONDING spec here */ 01061 } SelectStmt; 01062 01063 01064 /* ---------------------- 01065 * Set Operation node for post-analysis query trees 01066 * 01067 * After parse analysis, a SELECT with set operations is represented by a 01068 * top-level Query node containing the leaf SELECTs as subqueries in its 01069 * range table. Its setOperations field shows the tree of set operations, 01070 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal 01071 * nodes replaced by SetOperationStmt nodes. Information about the output 01072 * column types is added, too. (Note that the child nodes do not necessarily 01073 * produce these types directly, but we've checked that their output types 01074 * can be coerced to the output column type.) Also, if it's not UNION ALL, 01075 * information about the types' sort/group semantics is provided in the form 01076 * of a SortGroupClause list (same representation as, eg, DISTINCT). 01077 * The resolved common column collations are provided too; but note that if 01078 * it's not UNION ALL, it's okay for a column to not have a common collation, 01079 * so a member of the colCollations list could be InvalidOid even though the 01080 * column has a collatable type. 01081 * ---------------------- 01082 */ 01083 typedef struct SetOperationStmt 01084 { 01085 NodeTag type; 01086 SetOperation op; /* type of set op */ 01087 bool all; /* ALL specified? */ 01088 Node *larg; /* left child */ 01089 Node *rarg; /* right child */ 01090 /* Eventually add fields for CORRESPONDING spec here */ 01091 01092 /* Fields derived during parse analysis: */ 01093 List *colTypes; /* OID list of output column type OIDs */ 01094 List *colTypmods; /* integer list of output column typmods */ 01095 List *colCollations; /* OID list of output column collation OIDs */ 01096 List *groupClauses; /* a list of SortGroupClause's */ 01097 /* groupClauses is NIL if UNION ALL, but must be set otherwise */ 01098 } SetOperationStmt; 01099 01100 01101 /***************************************************************************** 01102 * Other Statements (no optimizations required) 01103 * 01104 * These are not touched by parser/analyze.c except to put them into 01105 * the utilityStmt field of a Query. This is eventually passed to 01106 * ProcessUtility (by-passing rewriting and planning). Some of the 01107 * statements do need attention from parse analysis, and this is 01108 * done by routines in parser/parse_utilcmd.c after ProcessUtility 01109 * receives the command for execution. 01110 *****************************************************************************/ 01111 01112 /* 01113 * When a command can act on several kinds of objects with only one 01114 * parse structure required, use these constants to designate the 01115 * object type. Note that commands typically don't support all the types. 01116 */ 01117 01118 typedef enum ObjectType 01119 { 01120 OBJECT_AGGREGATE, 01121 OBJECT_ATTRIBUTE, /* type's attribute, when distinct from column */ 01122 OBJECT_CAST, 01123 OBJECT_COLUMN, 01124 OBJECT_CONSTRAINT, 01125 OBJECT_COLLATION, 01126 OBJECT_CONVERSION, 01127 OBJECT_DATABASE, 01128 OBJECT_DOMAIN, 01129 OBJECT_EVENT_TRIGGER, 01130 OBJECT_EXTENSION, 01131 OBJECT_FDW, 01132 OBJECT_FOREIGN_SERVER, 01133 OBJECT_FOREIGN_TABLE, 01134 OBJECT_FUNCTION, 01135 OBJECT_INDEX, 01136 OBJECT_LANGUAGE, 01137 OBJECT_LARGEOBJECT, 01138 OBJECT_MATVIEW, 01139 OBJECT_OPCLASS, 01140 OBJECT_OPERATOR, 01141 OBJECT_OPFAMILY, 01142 OBJECT_ROLE, 01143 OBJECT_RULE, 01144 OBJECT_SCHEMA, 01145 OBJECT_SEQUENCE, 01146 OBJECT_TABLE, 01147 OBJECT_TABLESPACE, 01148 OBJECT_TRIGGER, 01149 OBJECT_TSCONFIGURATION, 01150 OBJECT_TSDICTIONARY, 01151 OBJECT_TSPARSER, 01152 OBJECT_TSTEMPLATE, 01153 OBJECT_TYPE, 01154 OBJECT_VIEW 01155 } ObjectType; 01156 01157 /* ---------------------- 01158 * Create Schema Statement 01159 * 01160 * NOTE: the schemaElts list contains raw parsetrees for component statements 01161 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and 01162 * executed after the schema itself is created. 01163 * ---------------------- 01164 */ 01165 typedef struct CreateSchemaStmt 01166 { 01167 NodeTag type; 01168 char *schemaname; /* the name of the schema to create */ 01169 char *authid; /* the owner of the created schema */ 01170 List *schemaElts; /* schema components (list of parsenodes) */ 01171 bool if_not_exists; /* just do nothing if schema already exists? */ 01172 } CreateSchemaStmt; 01173 01174 typedef enum DropBehavior 01175 { 01176 DROP_RESTRICT, /* drop fails if any dependent objects */ 01177 DROP_CASCADE /* remove dependent objects too */ 01178 } DropBehavior; 01179 01180 /* ---------------------- 01181 * Alter Table 01182 * ---------------------- 01183 */ 01184 typedef struct AlterTableStmt 01185 { 01186 NodeTag type; 01187 RangeVar *relation; /* table to work on */ 01188 List *cmds; /* list of subcommands */ 01189 ObjectType relkind; /* type of object */ 01190 bool missing_ok; /* skip error if table missing */ 01191 } AlterTableStmt; 01192 01193 typedef enum AlterTableType 01194 { 01195 AT_AddColumn, /* add column */ 01196 AT_AddColumnRecurse, /* internal to commands/tablecmds.c */ 01197 AT_AddColumnToView, /* implicitly via CREATE OR REPLACE VIEW */ 01198 AT_ColumnDefault, /* alter column default */ 01199 AT_DropNotNull, /* alter column drop not null */ 01200 AT_SetNotNull, /* alter column set not null */ 01201 AT_SetStatistics, /* alter column set statistics */ 01202 AT_SetOptions, /* alter column set ( options ) */ 01203 AT_ResetOptions, /* alter column reset ( options ) */ 01204 AT_SetStorage, /* alter column set storage */ 01205 AT_DropColumn, /* drop column */ 01206 AT_DropColumnRecurse, /* internal to commands/tablecmds.c */ 01207 AT_AddIndex, /* add index */ 01208 AT_ReAddIndex, /* internal to commands/tablecmds.c */ 01209 AT_AddConstraint, /* add constraint */ 01210 AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */ 01211 AT_ReAddConstraint, /* internal to commands/tablecmds.c */ 01212 AT_ValidateConstraint, /* validate constraint */ 01213 AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */ 01214 AT_ProcessedConstraint, /* pre-processed add constraint (local in 01215 * parser/parse_utilcmd.c) */ 01216 AT_AddIndexConstraint, /* add constraint using existing index */ 01217 AT_DropConstraint, /* drop constraint */ 01218 AT_DropConstraintRecurse, /* internal to commands/tablecmds.c */ 01219 AT_AlterColumnType, /* alter column type */ 01220 AT_AlterColumnGenericOptions, /* alter column OPTIONS (...) */ 01221 AT_ChangeOwner, /* change owner */ 01222 AT_ClusterOn, /* CLUSTER ON */ 01223 AT_DropCluster, /* SET WITHOUT CLUSTER */ 01224 AT_AddOids, /* SET WITH OIDS */ 01225 AT_AddOidsRecurse, /* internal to commands/tablecmds.c */ 01226 AT_DropOids, /* SET WITHOUT OIDS */ 01227 AT_SetTableSpace, /* SET TABLESPACE */ 01228 AT_SetRelOptions, /* SET (...) -- AM specific parameters */ 01229 AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */ 01230 AT_ReplaceRelOptions, /* replace reloption list in its entirety */ 01231 AT_EnableTrig, /* ENABLE TRIGGER name */ 01232 AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */ 01233 AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */ 01234 AT_DisableTrig, /* DISABLE TRIGGER name */ 01235 AT_EnableTrigAll, /* ENABLE TRIGGER ALL */ 01236 AT_DisableTrigAll, /* DISABLE TRIGGER ALL */ 01237 AT_EnableTrigUser, /* ENABLE TRIGGER USER */ 01238 AT_DisableTrigUser, /* DISABLE TRIGGER USER */ 01239 AT_EnableRule, /* ENABLE RULE name */ 01240 AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */ 01241 AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */ 01242 AT_DisableRule, /* DISABLE RULE name */ 01243 AT_AddInherit, /* INHERIT parent */ 01244 AT_DropInherit, /* NO INHERIT parent */ 01245 AT_AddOf, /* OF <type_name> */ 01246 AT_DropOf, /* NOT OF */ 01247 AT_GenericOptions /* OPTIONS (...) */ 01248 } AlterTableType; 01249 01250 typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */ 01251 { 01252 NodeTag type; 01253 AlterTableType subtype; /* Type of table alteration to apply */ 01254 char *name; /* column, constraint, or trigger to act on, 01255 * or new owner or tablespace */ 01256 Node *def; /* definition of new column, index, 01257 * constraint, or parent table */ 01258 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ 01259 bool missing_ok; /* skip error if missing? */ 01260 } AlterTableCmd; 01261 01262 01263 /* ---------------------- 01264 * Alter Domain 01265 * 01266 * The fields are used in different ways by the different variants of 01267 * this command. 01268 * ---------------------- 01269 */ 01270 typedef struct AlterDomainStmt 01271 { 01272 NodeTag type; 01273 char subtype; /*------------ 01274 * T = alter column default 01275 * N = alter column drop not null 01276 * O = alter column set not null 01277 * C = add constraint 01278 * X = drop constraint 01279 *------------ 01280 */ 01281 List *typeName; /* domain to work on */ 01282 char *name; /* column or constraint name to act on */ 01283 Node *def; /* definition of default or constraint */ 01284 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ 01285 bool missing_ok; /* skip error if missing? */ 01286 } AlterDomainStmt; 01287 01288 01289 /* ---------------------- 01290 * Grant|Revoke Statement 01291 * ---------------------- 01292 */ 01293 typedef enum GrantTargetType 01294 { 01295 ACL_TARGET_OBJECT, /* grant on specific named object(s) */ 01296 ACL_TARGET_ALL_IN_SCHEMA, /* grant on all objects in given schema(s) */ 01297 ACL_TARGET_DEFAULTS /* ALTER DEFAULT PRIVILEGES */ 01298 } GrantTargetType; 01299 01300 typedef enum GrantObjectType 01301 { 01302 ACL_OBJECT_COLUMN, /* column */ 01303 ACL_OBJECT_RELATION, /* table, view */ 01304 ACL_OBJECT_SEQUENCE, /* sequence */ 01305 ACL_OBJECT_DATABASE, /* database */ 01306 ACL_OBJECT_DOMAIN, /* domain */ 01307 ACL_OBJECT_FDW, /* foreign-data wrapper */ 01308 ACL_OBJECT_FOREIGN_SERVER, /* foreign server */ 01309 ACL_OBJECT_FUNCTION, /* function */ 01310 ACL_OBJECT_LANGUAGE, /* procedural language */ 01311 ACL_OBJECT_LARGEOBJECT, /* largeobject */ 01312 ACL_OBJECT_NAMESPACE, /* namespace */ 01313 ACL_OBJECT_TABLESPACE, /* tablespace */ 01314 ACL_OBJECT_TYPE /* type */ 01315 } GrantObjectType; 01316 01317 typedef struct GrantStmt 01318 { 01319 NodeTag type; 01320 bool is_grant; /* true = GRANT, false = REVOKE */ 01321 GrantTargetType targtype; /* type of the grant target */ 01322 GrantObjectType objtype; /* kind of object being operated on */ 01323 List *objects; /* list of RangeVar nodes, FuncWithArgs nodes, 01324 * or plain names (as Value strings) */ 01325 List *privileges; /* list of AccessPriv nodes */ 01326 /* privileges == NIL denotes ALL PRIVILEGES */ 01327 List *grantees; /* list of PrivGrantee nodes */ 01328 bool grant_option; /* grant or revoke grant option */ 01329 DropBehavior behavior; /* drop behavior (for REVOKE) */ 01330 } GrantStmt; 01331 01332 typedef struct PrivGrantee 01333 { 01334 NodeTag type; 01335 char *rolname; /* if NULL then PUBLIC */ 01336 } PrivGrantee; 01337 01338 /* 01339 * Note: FuncWithArgs carries only the types of the input parameters of the 01340 * function. So it is sufficient to identify an existing function, but it 01341 * is not enough info to define a function nor to call it. 01342 */ 01343 typedef struct FuncWithArgs 01344 { 01345 NodeTag type; 01346 List *funcname; /* qualified name of function */ 01347 List *funcargs; /* list of Typename nodes */ 01348 } FuncWithArgs; 01349 01350 /* 01351 * An access privilege, with optional list of column names 01352 * priv_name == NULL denotes ALL PRIVILEGES (only used with a column list) 01353 * cols == NIL denotes "all columns" 01354 * Note that simple "ALL PRIVILEGES" is represented as a NIL list, not 01355 * an AccessPriv with both fields null. 01356 */ 01357 typedef struct AccessPriv 01358 { 01359 NodeTag type; 01360 char *priv_name; /* string name of privilege */ 01361 List *cols; /* list of Value strings */ 01362 } AccessPriv; 01363 01364 /* ---------------------- 01365 * Grant/Revoke Role Statement 01366 * 01367 * Note: because of the parsing ambiguity with the GRANT <privileges> 01368 * statement, granted_roles is a list of AccessPriv; the execution code 01369 * should complain if any column lists appear. grantee_roles is a list 01370 * of role names, as Value strings. 01371 * ---------------------- 01372 */ 01373 typedef struct GrantRoleStmt 01374 { 01375 NodeTag type; 01376 List *granted_roles; /* list of roles to be granted/revoked */ 01377 List *grantee_roles; /* list of member roles to add/delete */ 01378 bool is_grant; /* true = GRANT, false = REVOKE */ 01379 bool admin_opt; /* with admin option */ 01380 char *grantor; /* set grantor to other than current role */ 01381 DropBehavior behavior; /* drop behavior (for REVOKE) */ 01382 } GrantRoleStmt; 01383 01384 /* ---------------------- 01385 * Alter Default Privileges Statement 01386 * ---------------------- 01387 */ 01388 typedef struct AlterDefaultPrivilegesStmt 01389 { 01390 NodeTag type; 01391 List *options; /* list of DefElem */ 01392 GrantStmt *action; /* GRANT/REVOKE action (with objects=NIL) */ 01393 } AlterDefaultPrivilegesStmt; 01394 01395 /* ---------------------- 01396 * Copy Statement 01397 * 01398 * We support "COPY relation FROM file", "COPY relation TO file", and 01399 * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation" 01400 * and "query" must be non-NULL. 01401 * ---------------------- 01402 */ 01403 typedef struct CopyStmt 01404 { 01405 NodeTag type; 01406 RangeVar *relation; /* the relation to copy */ 01407 Node *query; /* the SELECT query to copy */ 01408 List *attlist; /* List of column names (as Strings), or NIL 01409 * for all columns */ 01410 bool is_from; /* TO or FROM */ 01411 bool is_program; /* is 'filename' a program to popen? */ 01412 char *filename; /* filename, or NULL for STDIN/STDOUT */ 01413 List *options; /* List of DefElem nodes */ 01414 } CopyStmt; 01415 01416 /* ---------------------- 01417 * SET Statement (includes RESET) 01418 * 01419 * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we 01420 * preserve the distinction in VariableSetKind for CreateCommandTag(). 01421 * ---------------------- 01422 */ 01423 typedef enum 01424 { 01425 VAR_SET_VALUE, /* SET var = value */ 01426 VAR_SET_DEFAULT, /* SET var TO DEFAULT */ 01427 VAR_SET_CURRENT, /* SET var FROM CURRENT */ 01428 VAR_SET_MULTI, /* special case for SET TRANSACTION ... */ 01429 VAR_RESET, /* RESET var */ 01430 VAR_RESET_ALL /* RESET ALL */ 01431 } VariableSetKind; 01432 01433 typedef struct VariableSetStmt 01434 { 01435 NodeTag type; 01436 VariableSetKind kind; 01437 char *name; /* variable to be set */ 01438 List *args; /* List of A_Const nodes */ 01439 bool is_local; /* SET LOCAL? */ 01440 } VariableSetStmt; 01441 01442 /* ---------------------- 01443 * Show Statement 01444 * ---------------------- 01445 */ 01446 typedef struct VariableShowStmt 01447 { 01448 NodeTag type; 01449 char *name; 01450 } VariableShowStmt; 01451 01452 /* ---------------------- 01453 * Create Table Statement 01454 * 01455 * NOTE: in the raw gram.y output, ColumnDef and Constraint nodes are 01456 * intermixed in tableElts, and constraints is NIL. After parse analysis, 01457 * tableElts contains just ColumnDefs, and constraints contains just 01458 * Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present 01459 * implementation). 01460 * ---------------------- 01461 */ 01462 01463 typedef struct CreateStmt 01464 { 01465 NodeTag type; 01466 RangeVar *relation; /* relation to create */ 01467 List *tableElts; /* column definitions (list of ColumnDef) */ 01468 List *inhRelations; /* relations to inherit from (list of 01469 * inhRelation) */ 01470 TypeName *ofTypename; /* OF typename */ 01471 List *constraints; /* constraints (list of Constraint nodes) */ 01472 List *options; /* options from WITH clause */ 01473 OnCommitAction oncommit; /* what do we do at COMMIT? */ 01474 char *tablespacename; /* table space to use, or NULL */ 01475 bool if_not_exists; /* just do nothing if it already exists? */ 01476 } CreateStmt; 01477 01478 /* ---------- 01479 * Definitions for constraints in CreateStmt 01480 * 01481 * Note that column defaults are treated as a type of constraint, 01482 * even though that's a bit odd semantically. 01483 * 01484 * For constraints that use expressions (CONSTR_CHECK, CONSTR_DEFAULT) 01485 * we may have the expression in either "raw" form (an untransformed 01486 * parse tree) or "cooked" form (the nodeToString representation of 01487 * an executable expression tree), depending on how this Constraint 01488 * node was created (by parsing, or by inheritance from an existing 01489 * relation). We should never have both in the same node! 01490 * 01491 * FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype 01492 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are 01493 * stored into pg_constraint.confmatchtype. Changing the code values may 01494 * require an initdb! 01495 * 01496 * If skip_validation is true then we skip checking that the existing rows 01497 * in the table satisfy the constraint, and just install the catalog entries 01498 * for the constraint. A new FK constraint is marked as valid iff 01499 * initially_valid is true. (Usually skip_validation and initially_valid 01500 * are inverses, but we can set both true if the table is known empty.) 01501 * 01502 * Constraint attributes (DEFERRABLE etc) are initially represented as 01503 * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes 01504 * a pass through the constraints list to insert the info into the appropriate 01505 * Constraint node. 01506 * ---------- 01507 */ 01508 01509 typedef enum ConstrType /* types of constraints */ 01510 { 01511 CONSTR_NULL, /* not standard SQL, but a lot of people expect it */ 01512 CONSTR_NOTNULL, 01513 CONSTR_DEFAULT, 01514 CONSTR_CHECK, 01515 CONSTR_PRIMARY, 01516 CONSTR_UNIQUE, 01517 CONSTR_EXCLUSION, 01518 CONSTR_FOREIGN, 01519 CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */ 01520 CONSTR_ATTR_NOT_DEFERRABLE, 01521 CONSTR_ATTR_DEFERRED, 01522 CONSTR_ATTR_IMMEDIATE 01523 } ConstrType; 01524 01525 /* Foreign key action codes */ 01526 #define FKCONSTR_ACTION_NOACTION 'a' 01527 #define FKCONSTR_ACTION_RESTRICT 'r' 01528 #define FKCONSTR_ACTION_CASCADE 'c' 01529 #define FKCONSTR_ACTION_SETNULL 'n' 01530 #define FKCONSTR_ACTION_SETDEFAULT 'd' 01531 01532 /* Foreign key matchtype codes */ 01533 #define FKCONSTR_MATCH_FULL 'f' 01534 #define FKCONSTR_MATCH_PARTIAL 'p' 01535 #define FKCONSTR_MATCH_SIMPLE 's' 01536 01537 typedef struct Constraint 01538 { 01539 NodeTag type; 01540 ConstrType contype; /* see above */ 01541 01542 /* Fields used for most/all constraint types: */ 01543 char *conname; /* Constraint name, or NULL if unnamed */ 01544 bool deferrable; /* DEFERRABLE? */ 01545 bool initdeferred; /* INITIALLY DEFERRED? */ 01546 int location; /* token location, or -1 if unknown */ 01547 01548 /* Fields used for constraints with expressions (CHECK and DEFAULT): */ 01549 bool is_no_inherit; /* is constraint non-inheritable? */ 01550 Node *raw_expr; /* expr, as untransformed parse tree */ 01551 char *cooked_expr; /* expr, as nodeToString representation */ 01552 01553 /* Fields used for unique constraints (UNIQUE and PRIMARY KEY): */ 01554 List *keys; /* String nodes naming referenced column(s) */ 01555 01556 /* Fields used for EXCLUSION constraints: */ 01557 List *exclusions; /* list of (IndexElem, operator name) pairs */ 01558 01559 /* Fields used for index constraints (UNIQUE, PRIMARY KEY, EXCLUSION): */ 01560 List *options; /* options from WITH clause */ 01561 char *indexname; /* existing index to use; otherwise NULL */ 01562 char *indexspace; /* index tablespace; NULL for default */ 01563 /* These could be, but currently are not, used for UNIQUE/PKEY: */ 01564 char *access_method; /* index access method; NULL for default */ 01565 Node *where_clause; /* partial index predicate */ 01566 01567 /* Fields used for FOREIGN KEY constraints: */ 01568 RangeVar *pktable; /* Primary key table */ 01569 List *fk_attrs; /* Attributes of foreign key */ 01570 List *pk_attrs; /* Corresponding attrs in PK table */ 01571 char fk_matchtype; /* FULL, PARTIAL, SIMPLE */ 01572 char fk_upd_action; /* ON UPDATE action */ 01573 char fk_del_action; /* ON DELETE action */ 01574 List *old_conpfeqop; /* pg_constraint.conpfeqop of my former self */ 01575 01576 /* Fields used for constraints that allow a NOT VALID specification */ 01577 bool skip_validation; /* skip validation of existing rows? */ 01578 bool initially_valid; /* mark the new constraint as valid? */ 01579 } Constraint; 01580 01581 /* ---------------------- 01582 * Create/Drop Table Space Statements 01583 * ---------------------- 01584 */ 01585 01586 typedef struct CreateTableSpaceStmt 01587 { 01588 NodeTag type; 01589 char *tablespacename; 01590 char *owner; 01591 char *location; 01592 } CreateTableSpaceStmt; 01593 01594 typedef struct DropTableSpaceStmt 01595 { 01596 NodeTag type; 01597 char *tablespacename; 01598 bool missing_ok; /* skip error if missing? */ 01599 } DropTableSpaceStmt; 01600 01601 typedef struct AlterTableSpaceOptionsStmt 01602 { 01603 NodeTag type; 01604 char *tablespacename; 01605 List *options; 01606 bool isReset; 01607 } AlterTableSpaceOptionsStmt; 01608 01609 /* ---------------------- 01610 * Create/Alter Extension Statements 01611 * ---------------------- 01612 */ 01613 01614 typedef struct CreateExtensionStmt 01615 { 01616 NodeTag type; 01617 char *extname; 01618 bool if_not_exists; /* just do nothing if it already exists? */ 01619 List *options; /* List of DefElem nodes */ 01620 } CreateExtensionStmt; 01621 01622 /* Only used for ALTER EXTENSION UPDATE; later might need an action field */ 01623 typedef struct AlterExtensionStmt 01624 { 01625 NodeTag type; 01626 char *extname; 01627 List *options; /* List of DefElem nodes */ 01628 } AlterExtensionStmt; 01629 01630 typedef struct AlterExtensionContentsStmt 01631 { 01632 NodeTag type; 01633 char *extname; /* Extension's name */ 01634 int action; /* +1 = add object, -1 = drop object */ 01635 ObjectType objtype; /* Object's type */ 01636 List *objname; /* Qualified name of the object */ 01637 List *objargs; /* Arguments if needed (eg, for functions) */ 01638 } AlterExtensionContentsStmt; 01639 01640 /* ---------------------- 01641 * Create/Alter FOREIGN DATA WRAPPER Statements 01642 * ---------------------- 01643 */ 01644 01645 typedef struct CreateFdwStmt 01646 { 01647 NodeTag type; 01648 char *fdwname; /* foreign-data wrapper name */ 01649 List *func_options; /* HANDLER/VALIDATOR options */ 01650 List *options; /* generic options to FDW */ 01651 } CreateFdwStmt; 01652 01653 typedef struct AlterFdwStmt 01654 { 01655 NodeTag type; 01656 char *fdwname; /* foreign-data wrapper name */ 01657 List *func_options; /* HANDLER/VALIDATOR options */ 01658 List *options; /* generic options to FDW */ 01659 } AlterFdwStmt; 01660 01661 /* ---------------------- 01662 * Create/Alter FOREIGN SERVER Statements 01663 * ---------------------- 01664 */ 01665 01666 typedef struct CreateForeignServerStmt 01667 { 01668 NodeTag type; 01669 char *servername; /* server name */ 01670 char *servertype; /* optional server type */ 01671 char *version; /* optional server version */ 01672 char *fdwname; /* FDW name */ 01673 List *options; /* generic options to server */ 01674 } CreateForeignServerStmt; 01675 01676 typedef struct AlterForeignServerStmt 01677 { 01678 NodeTag type; 01679 char *servername; /* server name */ 01680 char *version; /* optional server version */ 01681 List *options; /* generic options to server */ 01682 bool has_version; /* version specified */ 01683 } AlterForeignServerStmt; 01684 01685 /* ---------------------- 01686 * Create FOREIGN TABLE Statements 01687 * ---------------------- 01688 */ 01689 01690 typedef struct CreateForeignTableStmt 01691 { 01692 CreateStmt base; 01693 char *servername; 01694 List *options; 01695 } CreateForeignTableStmt; 01696 01697 /* ---------------------- 01698 * Create/Drop USER MAPPING Statements 01699 * ---------------------- 01700 */ 01701 01702 typedef struct CreateUserMappingStmt 01703 { 01704 NodeTag type; 01705 char *username; /* username or PUBLIC/CURRENT_USER */ 01706 char *servername; /* server name */ 01707 List *options; /* generic options to server */ 01708 } CreateUserMappingStmt; 01709 01710 typedef struct AlterUserMappingStmt 01711 { 01712 NodeTag type; 01713 char *username; /* username or PUBLIC/CURRENT_USER */ 01714 char *servername; /* server name */ 01715 List *options; /* generic options to server */ 01716 } AlterUserMappingStmt; 01717 01718 typedef struct DropUserMappingStmt 01719 { 01720 NodeTag type; 01721 char *username; /* username or PUBLIC/CURRENT_USER */ 01722 char *servername; /* server name */ 01723 bool missing_ok; /* ignore missing mappings */ 01724 } DropUserMappingStmt; 01725 01726 /* ---------------------- 01727 * Create TRIGGER Statement 01728 * ---------------------- 01729 */ 01730 typedef struct CreateTrigStmt 01731 { 01732 NodeTag type; 01733 char *trigname; /* TRIGGER's name */ 01734 RangeVar *relation; /* relation trigger is on */ 01735 List *funcname; /* qual. name of function to call */ 01736 List *args; /* list of (T_String) Values or NIL */ 01737 bool row; /* ROW/STATEMENT */ 01738 /* timing uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */ 01739 int16 timing; /* BEFORE, AFTER, or INSTEAD */ 01740 /* events uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */ 01741 int16 events; /* "OR" of INSERT/UPDATE/DELETE/TRUNCATE */ 01742 List *columns; /* column names, or NIL for all columns */ 01743 Node *whenClause; /* qual expression, or NULL if none */ 01744 bool isconstraint; /* This is a constraint trigger */ 01745 /* The remaining fields are only used for constraint triggers */ 01746 bool deferrable; /* [NOT] DEFERRABLE */ 01747 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */ 01748 RangeVar *constrrel; /* opposite relation, if RI trigger */ 01749 } CreateTrigStmt; 01750 01751 /* ---------------------- 01752 * Create EVENT TRIGGER Statement 01753 * ---------------------- 01754 */ 01755 typedef struct CreateEventTrigStmt 01756 { 01757 NodeTag type; 01758 char *trigname; /* TRIGGER's name */ 01759 char *eventname; /* event's identifier */ 01760 List *whenclause; /* list of DefElems indicating filtering */ 01761 List *funcname; /* qual. name of function to call */ 01762 } CreateEventTrigStmt; 01763 01764 /* ---------------------- 01765 * Alter EVENT TRIGGER Statement 01766 * ---------------------- 01767 */ 01768 typedef struct AlterEventTrigStmt 01769 { 01770 NodeTag type; 01771 char *trigname; /* TRIGGER's name */ 01772 char tgenabled; /* trigger's firing configuration WRT 01773 * session_replication_role */ 01774 } AlterEventTrigStmt; 01775 01776 /* ---------------------- 01777 * Create/Drop PROCEDURAL LANGUAGE Statements 01778 * Create PROCEDURAL LANGUAGE Statements 01779 * ---------------------- 01780 */ 01781 typedef struct CreatePLangStmt 01782 { 01783 NodeTag type; 01784 bool replace; /* T => replace if already exists */ 01785 char *plname; /* PL name */ 01786 List *plhandler; /* PL call handler function (qual. name) */ 01787 List *plinline; /* optional inline function (qual. name) */ 01788 List *plvalidator; /* optional validator function (qual. name) */ 01789 bool pltrusted; /* PL is trusted */ 01790 } CreatePLangStmt; 01791 01792 /* ---------------------- 01793 * Create/Alter/Drop Role Statements 01794 * 01795 * Note: these node types are also used for the backwards-compatible 01796 * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases 01797 * there's really no need to distinguish what the original spelling was, 01798 * but for CREATE we mark the type because the defaults vary. 01799 * ---------------------- 01800 */ 01801 typedef enum RoleStmtType 01802 { 01803 ROLESTMT_ROLE, 01804 ROLESTMT_USER, 01805 ROLESTMT_GROUP 01806 } RoleStmtType; 01807 01808 typedef struct CreateRoleStmt 01809 { 01810 NodeTag type; 01811 RoleStmtType stmt_type; /* ROLE/USER/GROUP */ 01812 char *role; /* role name */ 01813 List *options; /* List of DefElem nodes */ 01814 } CreateRoleStmt; 01815 01816 typedef struct AlterRoleStmt 01817 { 01818 NodeTag type; 01819 char *role; /* role name */ 01820 List *options; /* List of DefElem nodes */ 01821 int action; /* +1 = add members, -1 = drop members */ 01822 } AlterRoleStmt; 01823 01824 typedef struct AlterRoleSetStmt 01825 { 01826 NodeTag type; 01827 char *role; /* role name */ 01828 char *database; /* database name, or NULL */ 01829 VariableSetStmt *setstmt; /* SET or RESET subcommand */ 01830 } AlterRoleSetStmt; 01831 01832 typedef struct DropRoleStmt 01833 { 01834 NodeTag type; 01835 List *roles; /* List of roles to remove */ 01836 bool missing_ok; /* skip error if a role is missing? */ 01837 } DropRoleStmt; 01838 01839 /* ---------------------- 01840 * {Create|Alter} SEQUENCE Statement 01841 * ---------------------- 01842 */ 01843 01844 typedef struct CreateSeqStmt 01845 { 01846 NodeTag type; 01847 RangeVar *sequence; /* the sequence to create */ 01848 List *options; 01849 Oid ownerId; /* ID of owner, or InvalidOid for default */ 01850 } CreateSeqStmt; 01851 01852 typedef struct AlterSeqStmt 01853 { 01854 NodeTag type; 01855 RangeVar *sequence; /* the sequence to alter */ 01856 List *options; 01857 bool missing_ok; /* skip error if a role is missing? */ 01858 } AlterSeqStmt; 01859 01860 /* ---------------------- 01861 * Create {Aggregate|Operator|Type} Statement 01862 * ---------------------- 01863 */ 01864 typedef struct DefineStmt 01865 { 01866 NodeTag type; 01867 ObjectType kind; /* aggregate, operator, type */ 01868 bool oldstyle; /* hack to signal old CREATE AGG syntax */ 01869 List *defnames; /* qualified name (list of Value strings) */ 01870 List *args; /* a list of TypeName (if needed) */ 01871 List *definition; /* a list of DefElem */ 01872 } DefineStmt; 01873 01874 /* ---------------------- 01875 * Create Domain Statement 01876 * ---------------------- 01877 */ 01878 typedef struct CreateDomainStmt 01879 { 01880 NodeTag type; 01881 List *domainname; /* qualified name (list of Value strings) */ 01882 TypeName *typeName; /* the base type */ 01883 CollateClause *collClause; /* untransformed COLLATE spec, if any */ 01884 List *constraints; /* constraints (list of Constraint nodes) */ 01885 } CreateDomainStmt; 01886 01887 /* ---------------------- 01888 * Create Operator Class Statement 01889 * ---------------------- 01890 */ 01891 typedef struct CreateOpClassStmt 01892 { 01893 NodeTag type; 01894 List *opclassname; /* qualified name (list of Value strings) */ 01895 List *opfamilyname; /* qualified name (ditto); NIL if omitted */ 01896 char *amname; /* name of index AM opclass is for */ 01897 TypeName *datatype; /* datatype of indexed column */ 01898 List *items; /* List of CreateOpClassItem nodes */ 01899 bool isDefault; /* Should be marked as default for type? */ 01900 } CreateOpClassStmt; 01901 01902 #define OPCLASS_ITEM_OPERATOR 1 01903 #define OPCLASS_ITEM_FUNCTION 2 01904 #define OPCLASS_ITEM_STORAGETYPE 3 01905 01906 typedef struct CreateOpClassItem 01907 { 01908 NodeTag type; 01909 int itemtype; /* see codes above */ 01910 /* fields used for an operator or function item: */ 01911 List *name; /* operator or function name */ 01912 List *args; /* argument types */ 01913 int number; /* strategy num or support proc num */ 01914 List *order_family; /* only used for ordering operators */ 01915 List *class_args; /* only used for functions */ 01916 /* fields used for a storagetype item: */ 01917 TypeName *storedtype; /* datatype stored in index */ 01918 } CreateOpClassItem; 01919 01920 /* ---------------------- 01921 * Create Operator Family Statement 01922 * ---------------------- 01923 */ 01924 typedef struct CreateOpFamilyStmt 01925 { 01926 NodeTag type; 01927 List *opfamilyname; /* qualified name (list of Value strings) */ 01928 char *amname; /* name of index AM opfamily is for */ 01929 } CreateOpFamilyStmt; 01930 01931 /* ---------------------- 01932 * Alter Operator Family Statement 01933 * ---------------------- 01934 */ 01935 typedef struct AlterOpFamilyStmt 01936 { 01937 NodeTag type; 01938 List *opfamilyname; /* qualified name (list of Value strings) */ 01939 char *amname; /* name of index AM opfamily is for */ 01940 bool isDrop; /* ADD or DROP the items? */ 01941 List *items; /* List of CreateOpClassItem nodes */ 01942 } AlterOpFamilyStmt; 01943 01944 /* ---------------------- 01945 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement 01946 * ---------------------- 01947 */ 01948 01949 typedef struct DropStmt 01950 { 01951 NodeTag type; 01952 List *objects; /* list of sublists of names (as Values) */ 01953 List *arguments; /* list of sublists of arguments (as Values) */ 01954 ObjectType removeType; /* object type */ 01955 DropBehavior behavior; /* RESTRICT or CASCADE behavior */ 01956 bool missing_ok; /* skip error if object is missing? */ 01957 bool concurrent; /* drop index concurrently? */ 01958 } DropStmt; 01959 01960 /* ---------------------- 01961 * Truncate Table Statement 01962 * ---------------------- 01963 */ 01964 typedef struct TruncateStmt 01965 { 01966 NodeTag type; 01967 List *relations; /* relations (RangeVars) to be truncated */ 01968 bool restart_seqs; /* restart owned sequences? */ 01969 DropBehavior behavior; /* RESTRICT or CASCADE behavior */ 01970 } TruncateStmt; 01971 01972 /* ---------------------- 01973 * Comment On Statement 01974 * ---------------------- 01975 */ 01976 typedef struct CommentStmt 01977 { 01978 NodeTag type; 01979 ObjectType objtype; /* Object's type */ 01980 List *objname; /* Qualified name of the object */ 01981 List *objargs; /* Arguments if needed (eg, for functions) */ 01982 char *comment; /* Comment to insert, or NULL to remove */ 01983 } CommentStmt; 01984 01985 /* ---------------------- 01986 * SECURITY LABEL Statement 01987 * ---------------------- 01988 */ 01989 typedef struct SecLabelStmt 01990 { 01991 NodeTag type; 01992 ObjectType objtype; /* Object's type */ 01993 List *objname; /* Qualified name of the object */ 01994 List *objargs; /* Arguments if needed (eg, for functions) */ 01995 char *provider; /* Label provider (or NULL) */ 01996 char *label; /* New security label to be assigned */ 01997 } SecLabelStmt; 01998 01999 /* ---------------------- 02000 * Declare Cursor Statement 02001 * 02002 * Note: the "query" field of DeclareCursorStmt is only used in the raw grammar 02003 * output. After parse analysis it's set to null, and the Query points to the 02004 * DeclareCursorStmt, not vice versa. 02005 * ---------------------- 02006 */ 02007 #define CURSOR_OPT_BINARY 0x0001 /* BINARY */ 02008 #define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */ 02009 #define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */ 02010 #define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */ 02011 #define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */ 02012 /* these planner-control flags do not correspond to any SQL grammar: */ 02013 #define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */ 02014 #define CURSOR_OPT_GENERIC_PLAN 0x0040 /* force use of generic plan */ 02015 #define CURSOR_OPT_CUSTOM_PLAN 0x0080 /* force use of custom plan */ 02016 02017 typedef struct DeclareCursorStmt 02018 { 02019 NodeTag type; 02020 char *portalname; /* name of the portal (cursor) */ 02021 int options; /* bitmask of options (see above) */ 02022 Node *query; /* the raw SELECT query */ 02023 } DeclareCursorStmt; 02024 02025 /* ---------------------- 02026 * Close Portal Statement 02027 * ---------------------- 02028 */ 02029 typedef struct ClosePortalStmt 02030 { 02031 NodeTag type; 02032 char *portalname; /* name of the portal (cursor) */ 02033 /* NULL means CLOSE ALL */ 02034 } ClosePortalStmt; 02035 02036 /* ---------------------- 02037 * Fetch Statement (also Move) 02038 * ---------------------- 02039 */ 02040 typedef enum FetchDirection 02041 { 02042 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */ 02043 FETCH_FORWARD, 02044 FETCH_BACKWARD, 02045 /* for these, howMany indicates a position; only one row is fetched */ 02046 FETCH_ABSOLUTE, 02047 FETCH_RELATIVE 02048 } FetchDirection; 02049 02050 #define FETCH_ALL LONG_MAX 02051 02052 typedef struct FetchStmt 02053 { 02054 NodeTag type; 02055 FetchDirection direction; /* see above */ 02056 long howMany; /* number of rows, or position argument */ 02057 char *portalname; /* name of portal (cursor) */ 02058 bool ismove; /* TRUE if MOVE */ 02059 } FetchStmt; 02060 02061 /* ---------------------- 02062 * Create Index Statement 02063 * 02064 * This represents creation of an index and/or an associated constraint. 02065 * If isconstraint is true, we should create a pg_constraint entry along 02066 * with the index. But if indexOid isn't InvalidOid, we are not creating an 02067 * index, just a UNIQUE/PKEY constraint using an existing index. isconstraint 02068 * must always be true in this case, and the fields describing the index 02069 * properties are empty. 02070 * ---------------------- 02071 */ 02072 typedef struct IndexStmt 02073 { 02074 NodeTag type; 02075 char *idxname; /* name of new index, or NULL for default */ 02076 RangeVar *relation; /* relation to build index on */ 02077 char *accessMethod; /* name of access method (eg. btree) */ 02078 char *tableSpace; /* tablespace, or NULL for default */ 02079 List *indexParams; /* columns to index: a list of IndexElem */ 02080 List *options; /* WITH clause options: a list of DefElem */ 02081 Node *whereClause; /* qualification (partial-index predicate) */ 02082 List *excludeOpNames; /* exclusion operator names, or NIL if none */ 02083 char *idxcomment; /* comment to apply to index, or NULL */ 02084 Oid indexOid; /* OID of an existing index, if any */ 02085 Oid oldNode; /* relfilenode of existing storage, if any */ 02086 bool unique; /* is index unique? */ 02087 bool primary; /* is index a primary key? */ 02088 bool isconstraint; /* is it for a pkey/unique constraint? */ 02089 bool deferrable; /* is the constraint DEFERRABLE? */ 02090 bool initdeferred; /* is the constraint INITIALLY DEFERRED? */ 02091 bool concurrent; /* should this be a concurrent index build? */ 02092 } IndexStmt; 02093 02094 /* ---------------------- 02095 * Create Function Statement 02096 * ---------------------- 02097 */ 02098 typedef struct CreateFunctionStmt 02099 { 02100 NodeTag type; 02101 bool replace; /* T => replace if already exists */ 02102 List *funcname; /* qualified name of function to create */ 02103 List *parameters; /* a list of FunctionParameter */ 02104 TypeName *returnType; /* the return type */ 02105 List *options; /* a list of DefElem */ 02106 List *withClause; /* a list of DefElem */ 02107 } CreateFunctionStmt; 02108 02109 typedef enum FunctionParameterMode 02110 { 02111 /* the assigned enum values appear in pg_proc, don't change 'em! */ 02112 FUNC_PARAM_IN = 'i', /* input only */ 02113 FUNC_PARAM_OUT = 'o', /* output only */ 02114 FUNC_PARAM_INOUT = 'b', /* both */ 02115 FUNC_PARAM_VARIADIC = 'v', /* variadic (always input) */ 02116 FUNC_PARAM_TABLE = 't' /* table function output column */ 02117 } FunctionParameterMode; 02118 02119 typedef struct FunctionParameter 02120 { 02121 NodeTag type; 02122 char *name; /* parameter name, or NULL if not given */ 02123 TypeName *argType; /* TypeName for parameter type */ 02124 FunctionParameterMode mode; /* IN/OUT/etc */ 02125 Node *defexpr; /* raw default expr, or NULL if not given */ 02126 } FunctionParameter; 02127 02128 typedef struct AlterFunctionStmt 02129 { 02130 NodeTag type; 02131 FuncWithArgs *func; /* name and args of function */ 02132 List *actions; /* list of DefElem */ 02133 } AlterFunctionStmt; 02134 02135 /* ---------------------- 02136 * DO Statement 02137 * 02138 * DoStmt is the raw parser output, InlineCodeBlock is the execution-time API 02139 * ---------------------- 02140 */ 02141 typedef struct DoStmt 02142 { 02143 NodeTag type; 02144 List *args; /* List of DefElem nodes */ 02145 } DoStmt; 02146 02147 typedef struct InlineCodeBlock 02148 { 02149 NodeTag type; 02150 char *source_text; /* source text of anonymous code block */ 02151 Oid langOid; /* OID of selected language */ 02152 bool langIsTrusted; /* trusted property of the language */ 02153 } InlineCodeBlock; 02154 02155 /* ---------------------- 02156 * Alter Object Rename Statement 02157 * ---------------------- 02158 */ 02159 typedef struct RenameStmt 02160 { 02161 NodeTag type; 02162 ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */ 02163 ObjectType relationType; /* if column name, associated relation type */ 02164 RangeVar *relation; /* in case it's a table */ 02165 List *object; /* in case it's some other object */ 02166 List *objarg; /* argument types, if applicable */ 02167 char *subname; /* name of contained object (column, rule, 02168 * trigger, etc) */ 02169 char *newname; /* the new name */ 02170 DropBehavior behavior; /* RESTRICT or CASCADE behavior */ 02171 bool missing_ok; /* skip error if missing? */ 02172 } RenameStmt; 02173 02174 /* ---------------------- 02175 * ALTER object SET SCHEMA Statement 02176 * ---------------------- 02177 */ 02178 typedef struct AlterObjectSchemaStmt 02179 { 02180 NodeTag type; 02181 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */ 02182 RangeVar *relation; /* in case it's a table */ 02183 List *object; /* in case it's some other object */ 02184 List *objarg; /* argument types, if applicable */ 02185 char *newschema; /* the new schema */ 02186 bool missing_ok; /* skip error if missing? */ 02187 } AlterObjectSchemaStmt; 02188 02189 /* ---------------------- 02190 * Alter Object Owner Statement 02191 * ---------------------- 02192 */ 02193 typedef struct AlterOwnerStmt 02194 { 02195 NodeTag type; 02196 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */ 02197 RangeVar *relation; /* in case it's a table */ 02198 List *object; /* in case it's some other object */ 02199 List *objarg; /* argument types, if applicable */ 02200 char *newowner; /* the new owner */ 02201 } AlterOwnerStmt; 02202 02203 02204 /* ---------------------- 02205 * Create Rule Statement 02206 * ---------------------- 02207 */ 02208 typedef struct RuleStmt 02209 { 02210 NodeTag type; 02211 RangeVar *relation; /* relation the rule is for */ 02212 char *rulename; /* name of the rule */ 02213 Node *whereClause; /* qualifications */ 02214 CmdType event; /* SELECT, INSERT, etc */ 02215 bool instead; /* is a 'do instead'? */ 02216 List *actions; /* the action statements */ 02217 bool replace; /* OR REPLACE */ 02218 } RuleStmt; 02219 02220 /* ---------------------- 02221 * Notify Statement 02222 * ---------------------- 02223 */ 02224 typedef struct NotifyStmt 02225 { 02226 NodeTag type; 02227 char *conditionname; /* condition name to notify */ 02228 char *payload; /* the payload string, or NULL if none */ 02229 } NotifyStmt; 02230 02231 /* ---------------------- 02232 * Listen Statement 02233 * ---------------------- 02234 */ 02235 typedef struct ListenStmt 02236 { 02237 NodeTag type; 02238 char *conditionname; /* condition name to listen on */ 02239 } ListenStmt; 02240 02241 /* ---------------------- 02242 * Unlisten Statement 02243 * ---------------------- 02244 */ 02245 typedef struct UnlistenStmt 02246 { 02247 NodeTag type; 02248 char *conditionname; /* name to unlisten on, or NULL for all */ 02249 } UnlistenStmt; 02250 02251 /* ---------------------- 02252 * {Begin|Commit|Rollback} Transaction Statement 02253 * ---------------------- 02254 */ 02255 typedef enum TransactionStmtKind 02256 { 02257 TRANS_STMT_BEGIN, 02258 TRANS_STMT_START, /* semantically identical to BEGIN */ 02259 TRANS_STMT_COMMIT, 02260 TRANS_STMT_ROLLBACK, 02261 TRANS_STMT_SAVEPOINT, 02262 TRANS_STMT_RELEASE, 02263 TRANS_STMT_ROLLBACK_TO, 02264 TRANS_STMT_PREPARE, 02265 TRANS_STMT_COMMIT_PREPARED, 02266 TRANS_STMT_ROLLBACK_PREPARED 02267 } TransactionStmtKind; 02268 02269 typedef struct TransactionStmt 02270 { 02271 NodeTag type; 02272 TransactionStmtKind kind; /* see above */ 02273 List *options; /* for BEGIN/START and savepoint commands */ 02274 char *gid; /* for two-phase-commit related commands */ 02275 } TransactionStmt; 02276 02277 /* ---------------------- 02278 * Create Type Statement, composite types 02279 * ---------------------- 02280 */ 02281 typedef struct CompositeTypeStmt 02282 { 02283 NodeTag type; 02284 RangeVar *typevar; /* the composite type to be created */ 02285 List *coldeflist; /* list of ColumnDef nodes */ 02286 } CompositeTypeStmt; 02287 02288 /* ---------------------- 02289 * Create Type Statement, enum types 02290 * ---------------------- 02291 */ 02292 typedef struct CreateEnumStmt 02293 { 02294 NodeTag type; 02295 List *typeName; /* qualified name (list of Value strings) */ 02296 List *vals; /* enum values (list of Value strings) */ 02297 } CreateEnumStmt; 02298 02299 /* ---------------------- 02300 * Create Type Statement, range types 02301 * ---------------------- 02302 */ 02303 typedef struct CreateRangeStmt 02304 { 02305 NodeTag type; 02306 List *typeName; /* qualified name (list of Value strings) */ 02307 List *params; /* range parameters (list of DefElem) */ 02308 } CreateRangeStmt; 02309 02310 /* ---------------------- 02311 * Alter Type Statement, enum types 02312 * ---------------------- 02313 */ 02314 typedef struct AlterEnumStmt 02315 { 02316 NodeTag type; 02317 List *typeName; /* qualified name (list of Value strings) */ 02318 char *newVal; /* new enum value's name */ 02319 char *newValNeighbor; /* neighboring enum value, if specified */ 02320 bool newValIsAfter; /* place new enum value after neighbor? */ 02321 bool skipIfExists; /* no error if label already exists */ 02322 } AlterEnumStmt; 02323 02324 /* ---------------------- 02325 * Create View Statement 02326 * ---------------------- 02327 */ 02328 typedef struct ViewStmt 02329 { 02330 NodeTag type; 02331 RangeVar *view; /* the view to be created */ 02332 List *aliases; /* target column names */ 02333 Node *query; /* the SELECT query */ 02334 bool replace; /* replace an existing view? */ 02335 List *options; /* options from WITH clause */ 02336 } ViewStmt; 02337 02338 /* ---------------------- 02339 * Load Statement 02340 * ---------------------- 02341 */ 02342 typedef struct LoadStmt 02343 { 02344 NodeTag type; 02345 char *filename; /* file to load */ 02346 } LoadStmt; 02347 02348 /* ---------------------- 02349 * Createdb Statement 02350 * ---------------------- 02351 */ 02352 typedef struct CreatedbStmt 02353 { 02354 NodeTag type; 02355 char *dbname; /* name of database to create */ 02356 List *options; /* List of DefElem nodes */ 02357 } CreatedbStmt; 02358 02359 /* ---------------------- 02360 * Alter Database 02361 * ---------------------- 02362 */ 02363 typedef struct AlterDatabaseStmt 02364 { 02365 NodeTag type; 02366 char *dbname; /* name of database to alter */ 02367 List *options; /* List of DefElem nodes */ 02368 } AlterDatabaseStmt; 02369 02370 typedef struct AlterDatabaseSetStmt 02371 { 02372 NodeTag type; 02373 char *dbname; /* database name */ 02374 VariableSetStmt *setstmt; /* SET or RESET subcommand */ 02375 } AlterDatabaseSetStmt; 02376 02377 /* ---------------------- 02378 * Dropdb Statement 02379 * ---------------------- 02380 */ 02381 typedef struct DropdbStmt 02382 { 02383 NodeTag type; 02384 char *dbname; /* database to drop */ 02385 bool missing_ok; /* skip error if db is missing? */ 02386 } DropdbStmt; 02387 02388 /* ---------------------- 02389 * Cluster Statement (support pbrown's cluster index implementation) 02390 * ---------------------- 02391 */ 02392 typedef struct ClusterStmt 02393 { 02394 NodeTag type; 02395 RangeVar *relation; /* relation being indexed, or NULL if all */ 02396 char *indexname; /* original index defined */ 02397 bool verbose; /* print progress info */ 02398 } ClusterStmt; 02399 02400 /* ---------------------- 02401 * Vacuum and Analyze Statements 02402 * 02403 * Even though these are nominally two statements, it's convenient to use 02404 * just one node type for both. Note that at least one of VACOPT_VACUUM 02405 * and VACOPT_ANALYZE must be set in options. VACOPT_FREEZE is an internal 02406 * convenience for the grammar and is not examined at runtime --- the 02407 * freeze_min_age and freeze_table_age fields are what matter. 02408 * ---------------------- 02409 */ 02410 typedef enum VacuumOption 02411 { 02412 VACOPT_VACUUM = 1 << 0, /* do VACUUM */ 02413 VACOPT_ANALYZE = 1 << 1, /* do ANALYZE */ 02414 VACOPT_VERBOSE = 1 << 2, /* print progress info */ 02415 VACOPT_FREEZE = 1 << 3, /* FREEZE option */ 02416 VACOPT_FULL = 1 << 4, /* FULL (non-concurrent) vacuum */ 02417 VACOPT_NOWAIT = 1 << 5 /* don't wait to get lock (autovacuum only) */ 02418 } VacuumOption; 02419 02420 typedef struct VacuumStmt 02421 { 02422 NodeTag type; 02423 int options; /* OR of VacuumOption flags */ 02424 int freeze_min_age; /* min freeze age, or -1 to use default */ 02425 int freeze_table_age; /* age at which to scan whole table */ 02426 RangeVar *relation; /* single table to process, or NULL */ 02427 List *va_cols; /* list of column names, or NIL for all */ 02428 } VacuumStmt; 02429 02430 /* ---------------------- 02431 * Explain Statement 02432 * 02433 * The "query" field is either a raw parse tree (SelectStmt, InsertStmt, etc) 02434 * or a Query node if parse analysis has been done. Note that rewriting and 02435 * planning of the query are always postponed until execution of EXPLAIN. 02436 * ---------------------- 02437 */ 02438 typedef struct ExplainStmt 02439 { 02440 NodeTag type; 02441 Node *query; /* the query (see comments above) */ 02442 List *options; /* list of DefElem nodes */ 02443 } ExplainStmt; 02444 02445 /* ---------------------- 02446 * CREATE TABLE AS Statement (a/k/a SELECT INTO) 02447 * 02448 * A query written as CREATE TABLE AS will produce this node type natively. 02449 * A query written as SELECT ... INTO will be transformed to this form during 02450 * parse analysis. 02451 * A query written as CREATE MATERIALIZED view will produce this node type, 02452 * during parse analysis, since it needs all the same data. 02453 * 02454 * The "query" field is handled similarly to EXPLAIN, though note that it 02455 * can be a SELECT or an EXECUTE, but not other DML statements. 02456 * ---------------------- 02457 */ 02458 typedef struct CreateTableAsStmt 02459 { 02460 NodeTag type; 02461 Node *query; /* the query (see comments above) */ 02462 IntoClause *into; /* destination table */ 02463 ObjectType relkind; /* OBJECT_TABLE or OBJECT_MATVIEW */ 02464 bool is_select_into; /* it was written as SELECT INTO */ 02465 } CreateTableAsStmt; 02466 02467 /* ---------------------- 02468 * REFRESH MATERIALIZED VIEW Statement 02469 * ---------------------- 02470 */ 02471 typedef struct RefreshMatViewStmt 02472 { 02473 NodeTag type; 02474 bool skipData; /* true for WITH NO DATA */ 02475 RangeVar *relation; /* relation to insert into */ 02476 } RefreshMatViewStmt; 02477 02478 /* ---------------------- 02479 * Checkpoint Statement 02480 * ---------------------- 02481 */ 02482 typedef struct CheckPointStmt 02483 { 02484 NodeTag type; 02485 } CheckPointStmt; 02486 02487 /* ---------------------- 02488 * Discard Statement 02489 * ---------------------- 02490 */ 02491 02492 typedef enum DiscardMode 02493 { 02494 DISCARD_ALL, 02495 DISCARD_PLANS, 02496 DISCARD_TEMP 02497 } DiscardMode; 02498 02499 typedef struct DiscardStmt 02500 { 02501 NodeTag type; 02502 DiscardMode target; 02503 } DiscardStmt; 02504 02505 /* ---------------------- 02506 * LOCK Statement 02507 * ---------------------- 02508 */ 02509 typedef struct LockStmt 02510 { 02511 NodeTag type; 02512 List *relations; /* relations to lock */ 02513 int mode; /* lock mode */ 02514 bool nowait; /* no wait mode */ 02515 } LockStmt; 02516 02517 /* ---------------------- 02518 * SET CONSTRAINTS Statement 02519 * ---------------------- 02520 */ 02521 typedef struct ConstraintsSetStmt 02522 { 02523 NodeTag type; 02524 List *constraints; /* List of names as RangeVars */ 02525 bool deferred; 02526 } ConstraintsSetStmt; 02527 02528 /* ---------------------- 02529 * REINDEX Statement 02530 * ---------------------- 02531 */ 02532 typedef struct ReindexStmt 02533 { 02534 NodeTag type; 02535 ObjectType kind; /* OBJECT_INDEX, OBJECT_TABLE, etc. */ 02536 RangeVar *relation; /* Table or index to reindex */ 02537 const char *name; /* name of database to reindex */ 02538 bool do_system; /* include system tables in database case */ 02539 bool do_user; /* include user tables in database case */ 02540 } ReindexStmt; 02541 02542 /* ---------------------- 02543 * CREATE CONVERSION Statement 02544 * ---------------------- 02545 */ 02546 typedef struct CreateConversionStmt 02547 { 02548 NodeTag type; 02549 List *conversion_name; /* Name of the conversion */ 02550 char *for_encoding_name; /* source encoding name */ 02551 char *to_encoding_name; /* destination encoding name */ 02552 List *func_name; /* qualified conversion function name */ 02553 bool def; /* is this a default conversion? */ 02554 } CreateConversionStmt; 02555 02556 /* ---------------------- 02557 * CREATE CAST Statement 02558 * ---------------------- 02559 */ 02560 typedef struct CreateCastStmt 02561 { 02562 NodeTag type; 02563 TypeName *sourcetype; 02564 TypeName *targettype; 02565 FuncWithArgs *func; 02566 CoercionContext context; 02567 bool inout; 02568 } CreateCastStmt; 02569 02570 /* ---------------------- 02571 * PREPARE Statement 02572 * ---------------------- 02573 */ 02574 typedef struct PrepareStmt 02575 { 02576 NodeTag type; 02577 char *name; /* Name of plan, arbitrary */ 02578 List *argtypes; /* Types of parameters (List of TypeName) */ 02579 Node *query; /* The query itself (as a raw parsetree) */ 02580 } PrepareStmt; 02581 02582 02583 /* ---------------------- 02584 * EXECUTE Statement 02585 * ---------------------- 02586 */ 02587 02588 typedef struct ExecuteStmt 02589 { 02590 NodeTag type; 02591 char *name; /* The name of the plan to execute */ 02592 List *params; /* Values to assign to parameters */ 02593 } ExecuteStmt; 02594 02595 02596 /* ---------------------- 02597 * DEALLOCATE Statement 02598 * ---------------------- 02599 */ 02600 typedef struct DeallocateStmt 02601 { 02602 NodeTag type; 02603 char *name; /* The name of the plan to remove */ 02604 /* NULL means DEALLOCATE ALL */ 02605 } DeallocateStmt; 02606 02607 /* 02608 * DROP OWNED statement 02609 */ 02610 typedef struct DropOwnedStmt 02611 { 02612 NodeTag type; 02613 List *roles; 02614 DropBehavior behavior; 02615 } DropOwnedStmt; 02616 02617 /* 02618 * REASSIGN OWNED statement 02619 */ 02620 typedef struct ReassignOwnedStmt 02621 { 02622 NodeTag type; 02623 List *roles; 02624 char *newrole; 02625 } ReassignOwnedStmt; 02626 02627 /* 02628 * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default 02629 */ 02630 typedef struct AlterTSDictionaryStmt 02631 { 02632 NodeTag type; 02633 List *dictname; /* qualified name (list of Value strings) */ 02634 List *options; /* List of DefElem nodes */ 02635 } AlterTSDictionaryStmt; 02636 02637 /* 02638 * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default 02639 */ 02640 typedef struct AlterTSConfigurationStmt 02641 { 02642 NodeTag type; 02643 List *cfgname; /* qualified name (list of Value strings) */ 02644 02645 /* 02646 * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is 02647 * NIL, but tokentype isn't, DROP MAPPING was specified. 02648 */ 02649 List *tokentype; /* list of Value strings */ 02650 List *dicts; /* list of list of Value strings */ 02651 bool override; /* if true - remove old variant */ 02652 bool replace; /* if true - replace dictionary by another */ 02653 bool missing_ok; /* for DROP - skip error if missing? */ 02654 } AlterTSConfigurationStmt; 02655 02656 #endif /* PARSENODES_H */