1 /*------------------------------------------------------------------------- 2 * 3 * parsenodes.h 4 * definitions for parse tree nodes 5 * 6 * Many of the node types used in parsetrees include a "location" field. 7 * This is a byte (not character) offset in the original source text, to be 8 * used for positioning an error cursor when there is an error related to 9 * the node. Access to the original source text is needed to make use of 10 * the location. At the topmost (statement) level, we also provide a 11 * statement length, likewise measured in bytes, for convenience in 12 * identifying statement boundaries in multi-statement source strings. 13 * 14 * 15 * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group 16 * Portions Copyright (c) 1994, Regents of the University of California 17 * 18 * src/include/nodes/parsenodes.h 19 * 20 *------------------------------------------------------------------------- 21 */ 22 #ifndef PARSENODES_H 23 #define PARSENODES_H 24 25 #include "nodes/bitmapset.h" 26 #include "nodes/lockoptions.h" 27 #include "nodes/primnodes.h" 28 #include "nodes/value.h" 29 #include "partitioning/partdefs.h" 30 31 32 typedef enum OverridingKind 33 { 34 OVERRIDING_NOT_SET = 0, 35 OVERRIDING_USER_VALUE, 36 OVERRIDING_SYSTEM_VALUE 37 } OverridingKind; 38 39 /* Possible sources of a Query */ 40 typedef enum QuerySource 41 { 42 QSRC_ORIGINAL, /* original parsetree (explicit query) */ 43 QSRC_PARSER, /* added by parse analysis (now unused) */ 44 QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */ 45 QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */ 46 QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */ 47 } QuerySource; 48 49 /* Sort ordering options for ORDER BY and CREATE INDEX */ 50 typedef enum SortByDir 51 { 52 SORTBY_DEFAULT, 53 SORTBY_ASC, 54 SORTBY_DESC, 55 SORTBY_USING /* not allowed in CREATE INDEX ... */ 56 } SortByDir; 57 58 typedef enum SortByNulls 59 { 60 SORTBY_NULLS_DEFAULT, 61 SORTBY_NULLS_FIRST, 62 SORTBY_NULLS_LAST 63 } SortByNulls; 64 65 /* 66 * Grantable rights are encoded so that we can OR them together in a bitmask. 67 * The present representation of AclItem limits us to 16 distinct rights, 68 * even though AclMode is defined as uint32. See utils/acl.h. 69 * 70 * Caution: changing these codes breaks stored ACLs, hence forces initdb. 71 */ 72 typedef uint32 AclMode; /* a bitmask of privilege bits */ 73 74 #define ACL_INSERT (1<<0) /* for relations */ 75 #define ACL_SELECT (1<<1) 76 #define ACL_UPDATE (1<<2) 77 #define ACL_DELETE (1<<3) 78 #define ACL_TRUNCATE (1<<4) 79 #define ACL_REFERENCES (1<<5) 80 #define ACL_TRIGGER (1<<6) 81 #define ACL_EXECUTE (1<<7) /* for functions */ 82 #define ACL_USAGE (1<<8) /* for languages, namespaces, FDWs, and 83 * servers */ 84 #define ACL_CREATE (1<<9) /* for namespaces and databases */ 85 #define ACL_CREATE_TEMP (1<<10) /* for databases */ 86 #define ACL_CONNECT (1<<11) /* for databases */ 87 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */ 88 #define ACL_NO_RIGHTS 0 89 /* Currently, SELECT ... FOR [KEY] UPDATE/SHARE requires UPDATE privileges */ 90 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE 91 92 93 /***************************************************************************** 94 * Query Tree 95 *****************************************************************************/ 96 97 /* 98 * Query - 99 * Parse analysis turns all statements into a Query tree 100 * for further processing by the rewriter and planner. 101 * 102 * Utility statements (i.e. non-optimizable statements) have the 103 * utilityStmt field set, and the rest of the Query is mostly dummy. 104 * 105 * Planning converts a Query tree into a Plan tree headed by a PlannedStmt 106 * node --- the Query structure is not used by the executor. 107 */ 108 typedef struct Query 109 { 110 NodeTag type; 111 112 CmdType commandType; /* select|insert|update|delete|utility */ 113 114 QuerySource querySource; /* where did I come from? */ 115 116 uint64 queryId; /* query identifier (can be set by plugins) */ 117 118 bool canSetTag; /* do I set the command result tag? */ 119 120 Node *utilityStmt; /* non-null if commandType == CMD_UTILITY */ 121 122 int resultRelation; /* rtable index of target relation for 123 * INSERT/UPDATE/DELETE; 0 for SELECT */ 124 125 bool hasAggs; /* has aggregates in tlist or havingQual */ 126 bool hasWindowFuncs; /* has window functions in tlist */ 127 bool hasTargetSRFs; /* has set-returning functions in tlist */ 128 bool hasSubLinks; /* has subquery SubLink */ 129 bool hasDistinctOn; /* distinctClause is from DISTINCT ON */ 130 bool hasRecursive; /* WITH RECURSIVE was specified */ 131 bool hasModifyingCTE; /* has INSERT/UPDATE/DELETE in WITH */ 132 bool hasForUpdate; /* FOR [KEY] UPDATE/SHARE was specified */ 133 bool hasRowSecurity; /* rewriter has applied some RLS policy */ 134 135 List *cteList; /* WITH list (of CommonTableExpr's) */ 136 137 List *rtable; /* list of range table entries */ 138 FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */ 139 140 List *targetList; /* target list (of TargetEntry) */ 141 142 OverridingKind override; /* OVERRIDING clause */ 143 144 OnConflictExpr *onConflict; /* ON CONFLICT DO [NOTHING | UPDATE] */ 145 146 List *returningList; /* return-values list (of TargetEntry) */ 147 148 List *groupClause; /* a list of SortGroupClause's */ 149 150 List *groupingSets; /* a list of GroupingSet's if present */ 151 152 Node *havingQual; /* qualifications applied to groups */ 153 154 List *windowClause; /* a list of WindowClause's */ 155 156 List *distinctClause; /* a list of SortGroupClause's */ 157 158 List *sortClause; /* a list of SortGroupClause's */ 159 160 Node *limitOffset; /* # of result tuples to skip (int8 expr) */ 161 Node *limitCount; /* # of result tuples to return (int8 expr) */ 162 163 List *rowMarks; /* a list of RowMarkClause's */ 164 165 Node *setOperations; /* set-operation tree if this is top level of 166 * a UNION/INTERSECT/EXCEPT query */ 167 168 List *constraintDeps; /* a list of pg_constraint OIDs that the query 169 * depends on to be semantically valid */ 170 171 List *withCheckOptions; /* a list of WithCheckOption's, which are 172 * only added during rewrite and therefore 173 * are not written out as part of Query. */ 174 175 /* 176 * The following two fields identify the portion of the source text string 177 * containing this query. They are typically only populated in top-level 178 * Queries, not in sub-queries. When not set, they might both be zero, or 179 * both be -1 meaning "unknown". 180 */ 181 int stmt_location; /* start location, or -1 if unknown */ 182 int stmt_len; /* length in bytes; 0 means "rest of string" */ 183 } Query; 184 185 186 /**************************************************************************** 187 * Supporting data structures for Parse Trees 188 * 189 * Most of these node types appear in raw parsetrees output by the grammar, 190 * and get transformed to something else by the analyzer. A few of them 191 * are used as-is in transformed querytrees. 192 ****************************************************************************/ 193 194 /* 195 * TypeName - specifies a type in definitions 196 * 197 * For TypeName structures generated internally, it is often easier to 198 * specify the type by OID than by name. If "names" is NIL then the 199 * actual type OID is given by typeOid, otherwise typeOid is unused. 200 * Similarly, if "typmods" is NIL then the actual typmod is expected to 201 * be prespecified in typemod, otherwise typemod is unused. 202 * 203 * If pct_type is true, then names is actually a field name and we look up 204 * the type of that field. Otherwise (the normal case), names is a type 205 * name possibly qualified with schema and database name. 206 */ 207 typedef struct TypeName 208 { 209 NodeTag type; 210 List *names; /* qualified name (list of Value strings) */ 211 Oid typeOid; /* type identified by OID */ 212 bool setof; /* is a set? */ 213 bool pct_type; /* %TYPE specified? */ 214 List *typmods; /* type modifier expression(s) */ 215 int32 typemod; /* prespecified type modifier */ 216 List *arrayBounds; /* array bounds */ 217 int location; /* token location, or -1 if unknown */ 218 } TypeName; 219 220 /* 221 * ColumnRef - specifies a reference to a column, or possibly a whole tuple 222 * 223 * The "fields" list must be nonempty. It can contain string Value nodes 224 * (representing names) and A_Star nodes (representing occurrence of a '*'). 225 * Currently, A_Star must appear only as the last list element --- the grammar 226 * is responsible for enforcing this! 227 * 228 * Note: any array subscripting or selection of fields from composite columns 229 * is represented by an A_Indirection node above the ColumnRef. However, 230 * for simplicity in the normal case, initial field selection from a table 231 * name is represented within ColumnRef and not by adding A_Indirection. 232 */ 233 typedef struct ColumnRef 234 { 235 NodeTag type; 236 List *fields; /* field names (Value strings) or A_Star */ 237 int location; /* token location, or -1 if unknown */ 238 } ColumnRef; 239 240 /* 241 * ParamRef - specifies a $n parameter reference 242 */ 243 typedef struct ParamRef 244 { 245 NodeTag type; 246 int number; /* the number of the parameter */ 247 int location; /* token location, or -1 if unknown */ 248 } ParamRef; 249 250 /* 251 * A_Expr - infix, prefix, and postfix expressions 252 */ 253 typedef enum A_Expr_Kind 254 { 255 AEXPR_OP, /* normal operator */ 256 AEXPR_OP_ANY, /* scalar op ANY (array) */ 257 AEXPR_OP_ALL, /* scalar op ALL (array) */ 258 AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */ 259 AEXPR_NOT_DISTINCT, /* IS NOT DISTINCT FROM - name must be "=" */ 260 AEXPR_NULLIF, /* NULLIF - name must be "=" */ 261 AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */ 262 AEXPR_IN, /* [NOT] IN - name must be "=" or "<>" */ 263 AEXPR_LIKE, /* [NOT] LIKE - name must be "~~" or "!~~" */ 264 AEXPR_ILIKE, /* [NOT] ILIKE - name must be "~~*" or "!~~*" */ 265 AEXPR_SIMILAR, /* [NOT] SIMILAR - name must be "~" or "!~" */ 266 AEXPR_BETWEEN, /* name must be "BETWEEN" */ 267 AEXPR_NOT_BETWEEN, /* name must be "NOT BETWEEN" */ 268 AEXPR_BETWEEN_SYM, /* name must be "BETWEEN SYMMETRIC" */ 269 AEXPR_NOT_BETWEEN_SYM, /* name must be "NOT BETWEEN SYMMETRIC" */ 270 AEXPR_PAREN /* nameless dummy node for parentheses */ 271 } A_Expr_Kind; 272 273 typedef struct A_Expr 274 { 275 NodeTag type; 276 A_Expr_Kind kind; /* see above */ 277 List *name; /* possibly-qualified name of operator */ 278 Node *lexpr; /* left argument, or NULL if none */ 279 Node *rexpr; /* right argument, or NULL if none */ 280 int location; /* token location, or -1 if unknown */ 281 } A_Expr; 282 283 /* 284 * A_Const - a literal constant 285 */ 286 typedef struct A_Const 287 { 288 NodeTag type; 289 Value val; /* value (includes type info, see value.h) */ 290 int location; /* token location, or -1 if unknown */ 291 } A_Const; 292 293 /* 294 * TypeCast - a CAST expression 295 */ 296 typedef struct TypeCast 297 { 298 NodeTag type; 299 Node *arg; /* the expression being casted */ 300 TypeName *typeName; /* the target type */ 301 int location; /* token location, or -1 if unknown */ 302 } TypeCast; 303 304 /* 305 * CollateClause - a COLLATE expression 306 */ 307 typedef struct CollateClause 308 { 309 NodeTag type; 310 Node *arg; /* input expression */ 311 List *collname; /* possibly-qualified collation name */ 312 int location; /* token location, or -1 if unknown */ 313 } CollateClause; 314 315 /* 316 * RoleSpec - a role name or one of a few special values. 317 */ 318 typedef enum RoleSpecType 319 { 320 ROLESPEC_CSTRING, /* role name is stored as a C string */ 321 ROLESPEC_CURRENT_USER, /* role spec is CURRENT_USER */ 322 ROLESPEC_SESSION_USER, /* role spec is SESSION_USER */ 323 ROLESPEC_PUBLIC /* role name is "public" */ 324 } RoleSpecType; 325 326 typedef struct RoleSpec 327 { 328 NodeTag type; 329 RoleSpecType roletype; /* Type of this rolespec */ 330 char *rolename; /* filled only for ROLESPEC_CSTRING */ 331 int location; /* token location, or -1 if unknown */ 332 } RoleSpec; 333 334 /* 335 * FuncCall - a function or aggregate invocation 336 * 337 * agg_order (if not NIL) indicates we saw 'foo(... ORDER BY ...)', or if 338 * agg_within_group is true, it was 'foo(...) WITHIN GROUP (ORDER BY ...)'. 339 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct 340 * indicates we saw 'foo(DISTINCT ...)'. In any of these cases, the 341 * construct *must* be an aggregate call. Otherwise, it might be either an 342 * aggregate or some other kind of function. However, if FILTER or OVER is 343 * present it had better be an aggregate or window function. 344 * 345 * Normally, you'd initialize this via makeFuncCall() and then only change the 346 * parts of the struct its defaults don't match afterwards, as needed. 347 */ 348 typedef struct FuncCall 349 { 350 NodeTag type; 351 List *funcname; /* qualified name of function */ 352 List *args; /* the arguments (list of exprs) */ 353 List *agg_order; /* ORDER BY (list of SortBy) */ 354 Node *agg_filter; /* FILTER clause, if any */ 355 bool agg_within_group; /* ORDER BY appeared in WITHIN GROUP */ 356 bool agg_star; /* argument was really '*' */ 357 bool agg_distinct; /* arguments were labeled DISTINCT */ 358 bool func_variadic; /* last argument was labeled VARIADIC */ 359 struct WindowDef *over; /* OVER clause, if any */ 360 int location; /* token location, or -1 if unknown */ 361 } FuncCall; 362 363 /* 364 * A_Star - '*' representing all columns of a table or compound field 365 * 366 * This can appear within ColumnRef.fields, A_Indirection.indirection, and 367 * ResTarget.indirection lists. 368 */ 369 typedef struct A_Star 370 { 371 NodeTag type; 372 } A_Star; 373 374 /* 375 * A_Indices - array subscript or slice bounds ([idx] or [lidx:uidx]) 376 * 377 * In slice case, either or both of lidx and uidx can be NULL (omitted). 378 * In non-slice case, uidx holds the single subscript and lidx is always NULL. 379 */ 380 typedef struct A_Indices 381 { 382 NodeTag type; 383 bool is_slice; /* true if slice (i.e., colon present) */ 384 Node *lidx; /* slice lower bound, if any */ 385 Node *uidx; /* subscript, or slice upper bound if any */ 386 } A_Indices; 387 388 /* 389 * A_Indirection - select a field and/or array element from an expression 390 * 391 * The indirection list can contain A_Indices nodes (representing 392 * subscripting), string Value nodes (representing field selection --- the 393 * string value is the name of the field to select), and A_Star nodes 394 * (representing selection of all fields of a composite type). 395 * For example, a complex selection operation like 396 * (foo).field1[42][7].field2 397 * would be represented with a single A_Indirection node having a 4-element 398 * indirection list. 399 * 400 * Currently, A_Star must appear only as the last list element --- the grammar 401 * is responsible for enforcing this! 402 */ 403 typedef struct A_Indirection 404 { 405 NodeTag type; 406 Node *arg; /* the thing being selected from */ 407 List *indirection; /* subscripts and/or field names and/or * */ 408 } A_Indirection; 409 410 /* 411 * A_ArrayExpr - an ARRAY[] construct 412 */ 413 typedef struct A_ArrayExpr 414 { 415 NodeTag type; 416 List *elements; /* array element expressions */ 417 int location; /* token location, or -1 if unknown */ 418 } A_ArrayExpr; 419 420 /* 421 * ResTarget - 422 * result target (used in target list of pre-transformed parse trees) 423 * 424 * In a SELECT target list, 'name' is the column label from an 425 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the 426 * value expression itself. The 'indirection' field is not used. 427 * 428 * INSERT uses ResTarget in its target-column-names list. Here, 'name' is 429 * the name of the destination column, 'indirection' stores any subscripts 430 * attached to the destination, and 'val' is not used. 431 * 432 * In an UPDATE target list, 'name' is the name of the destination column, 433 * 'indirection' stores any subscripts attached to the destination, and 434 * 'val' is the expression to assign. 435 * 436 * See A_Indirection for more info about what can appear in 'indirection'. 437 */ 438 typedef struct ResTarget 439 { 440 NodeTag type; 441 char *name; /* column name or NULL */ 442 List *indirection; /* subscripts, field names, and '*', or NIL */ 443 Node *val; /* the value expression to compute or assign */ 444 int location; /* token location, or -1 if unknown */ 445 } ResTarget; 446 447 /* 448 * MultiAssignRef - element of a row source expression for UPDATE 449 * 450 * In an UPDATE target list, when we have SET (a,b,c) = row-valued-expression, 451 * we generate separate ResTarget items for each of a,b,c. Their "val" trees 452 * are MultiAssignRef nodes numbered 1..n, linking to a common copy of the 453 * row-valued-expression (which parse analysis will process only once, when 454 * handling the MultiAssignRef with colno=1). 455 */ 456 typedef struct MultiAssignRef 457 { 458 NodeTag type; 459 Node *source; /* the row-valued expression */ 460 int colno; /* column number for this target (1..n) */ 461 int ncolumns; /* number of targets in the construct */ 462 } MultiAssignRef; 463 464 /* 465 * SortBy - for ORDER BY clause 466 */ 467 typedef struct SortBy 468 { 469 NodeTag type; 470 Node *node; /* expression to sort on */ 471 SortByDir sortby_dir; /* ASC/DESC/USING/default */ 472 SortByNulls sortby_nulls; /* NULLS FIRST/LAST */ 473 List *useOp; /* name of op to use, if SORTBY_USING */ 474 int location; /* operator location, or -1 if none/unknown */ 475 } SortBy; 476 477 /* 478 * WindowDef - raw representation of WINDOW and OVER clauses 479 * 480 * For entries in a WINDOW list, "name" is the window name being defined. 481 * For OVER clauses, we use "name" for the "OVER window" syntax, or "refname" 482 * for the "OVER (window)" syntax, which is subtly different --- the latter 483 * implies overriding the window frame clause. 484 */ 485 typedef struct WindowDef 486 { 487 NodeTag type; 488 char *name; /* window's own name */ 489 char *refname; /* referenced window name, if any */ 490 List *partitionClause; /* PARTITION BY expression list */ 491 List *orderClause; /* ORDER BY (list of SortBy) */ 492 int frameOptions; /* frame_clause options, see below */ 493 Node *startOffset; /* expression for starting bound, if any */ 494 Node *endOffset; /* expression for ending bound, if any */ 495 int location; /* parse location, or -1 if none/unknown */ 496 } WindowDef; 497 498 /* 499 * frameOptions is an OR of these bits. The NONDEFAULT and BETWEEN bits are 500 * used so that ruleutils.c can tell which properties were specified and 501 * which were defaulted; the correct behavioral bits must be set either way. 502 * The START_foo and END_foo options must come in pairs of adjacent bits for 503 * the convenience of gram.y, even though some of them are useless/invalid. 504 */ 505 #define FRAMEOPTION_NONDEFAULT 0x00001 /* any specified? */ 506 #define FRAMEOPTION_RANGE 0x00002 /* RANGE behavior */ 507 #define FRAMEOPTION_ROWS 0x00004 /* ROWS behavior */ 508 #define FRAMEOPTION_GROUPS 0x00008 /* GROUPS behavior */ 509 #define FRAMEOPTION_BETWEEN 0x00010 /* BETWEEN given? */ 510 #define FRAMEOPTION_START_UNBOUNDED_PRECEDING 0x00020 /* start is U. P. */ 511 #define FRAMEOPTION_END_UNBOUNDED_PRECEDING 0x00040 /* (disallowed) */ 512 #define FRAMEOPTION_START_UNBOUNDED_FOLLOWING 0x00080 /* (disallowed) */ 513 #define FRAMEOPTION_END_UNBOUNDED_FOLLOWING 0x00100 /* end is U. F. */ 514 #define FRAMEOPTION_START_CURRENT_ROW 0x00200 /* start is C. R. */ 515 #define FRAMEOPTION_END_CURRENT_ROW 0x00400 /* end is C. R. */ 516 #define FRAMEOPTION_START_OFFSET_PRECEDING 0x00800 /* start is O. P. */ 517 #define FRAMEOPTION_END_OFFSET_PRECEDING 0x01000 /* end is O. P. */ 518 #define FRAMEOPTION_START_OFFSET_FOLLOWING 0x02000 /* start is O. F. */ 519 #define FRAMEOPTION_END_OFFSET_FOLLOWING 0x04000 /* end is O. F. */ 520 #define FRAMEOPTION_EXCLUDE_CURRENT_ROW 0x08000 /* omit C.R. */ 521 #define FRAMEOPTION_EXCLUDE_GROUP 0x10000 /* omit C.R. & peers */ 522 #define FRAMEOPTION_EXCLUDE_TIES 0x20000 /* omit C.R.'s peers */ 523 524 #define FRAMEOPTION_START_OFFSET \ 525 (FRAMEOPTION_START_OFFSET_PRECEDING | FRAMEOPTION_START_OFFSET_FOLLOWING) 526 #define FRAMEOPTION_END_OFFSET \ 527 (FRAMEOPTION_END_OFFSET_PRECEDING | FRAMEOPTION_END_OFFSET_FOLLOWING) 528 #define FRAMEOPTION_EXCLUSION \ 529 (FRAMEOPTION_EXCLUDE_CURRENT_ROW | FRAMEOPTION_EXCLUDE_GROUP | \ 530 FRAMEOPTION_EXCLUDE_TIES) 531 532 #define FRAMEOPTION_DEFAULTS \ 533 (FRAMEOPTION_RANGE | FRAMEOPTION_START_UNBOUNDED_PRECEDING | \ 534 FRAMEOPTION_END_CURRENT_ROW) 535 536 /* 537 * RangeSubselect - subquery appearing in a FROM clause 538 */ 539 typedef struct RangeSubselect 540 { 541 NodeTag type; 542 bool lateral; /* does it have LATERAL prefix? */ 543 Node *subquery; /* the untransformed sub-select clause */ 544 Alias *alias; /* table alias & optional column aliases */ 545 } RangeSubselect; 546 547 /* 548 * RangeFunction - function call appearing in a FROM clause 549 * 550 * functions is a List because we use this to represent the construct 551 * ROWS FROM(func1(...), func2(...), ...). Each element of this list is a 552 * two-element sublist, the first element being the untransformed function 553 * call tree, and the second element being a possibly-empty list of ColumnDef 554 * nodes representing any columndef list attached to that function within the 555 * ROWS FROM() syntax. 556 * 557 * alias and coldeflist represent any alias and/or columndef list attached 558 * at the top level. (We disallow coldeflist appearing both here and 559 * per-function, but that's checked in parse analysis, not by the grammar.) 560 */ 561 typedef struct RangeFunction 562 { 563 NodeTag type; 564 bool lateral; /* does it have LATERAL prefix? */ 565 bool ordinality; /* does it have WITH ORDINALITY suffix? */ 566 bool is_rowsfrom; /* is result of ROWS FROM() syntax? */ 567 List *functions; /* per-function information, see above */ 568 Alias *alias; /* table alias & optional column aliases */ 569 List *coldeflist; /* list of ColumnDef nodes to describe result 570 * of function returning RECORD */ 571 } RangeFunction; 572 573 /* 574 * RangeTableFunc - raw form of "table functions" such as XMLTABLE 575 */ 576 typedef struct RangeTableFunc 577 { 578 NodeTag type; 579 bool lateral; /* does it have LATERAL prefix? */ 580 Node *docexpr; /* document expression */ 581 Node *rowexpr; /* row generator expression */ 582 List *namespaces; /* list of namespaces as ResTarget */ 583 List *columns; /* list of RangeTableFuncCol */ 584 Alias *alias; /* table alias & optional column aliases */ 585 int location; /* token location, or -1 if unknown */ 586 } RangeTableFunc; 587 588 /* 589 * RangeTableFuncCol - one column in a RangeTableFunc->columns 590 * 591 * If for_ordinality is true (FOR ORDINALITY), then the column is an int4 592 * column and the rest of the fields are ignored. 593 */ 594 typedef struct RangeTableFuncCol 595 { 596 NodeTag type; 597 char *colname; /* name of generated column */ 598 TypeName *typeName; /* type of generated column */ 599 bool for_ordinality; /* does it have FOR ORDINALITY? */ 600 bool is_not_null; /* does it have NOT NULL? */ 601 Node *colexpr; /* column filter expression */ 602 Node *coldefexpr; /* column default value expression */ 603 int location; /* token location, or -1 if unknown */ 604 } RangeTableFuncCol; 605 606 /* 607 * RangeTableSample - TABLESAMPLE appearing in a raw FROM clause 608 * 609 * This node, appearing only in raw parse trees, represents 610 * <relation> TABLESAMPLE <method> (<params>) REPEATABLE (<num>) 611 * Currently, the <relation> can only be a RangeVar, but we might in future 612 * allow RangeSubselect and other options. Note that the RangeTableSample 613 * is wrapped around the node representing the <relation>, rather than being 614 * a subfield of it. 615 */ 616 typedef struct RangeTableSample 617 { 618 NodeTag type; 619 Node *relation; /* relation to be sampled */ 620 List *method; /* sampling method name (possibly qualified) */ 621 List *args; /* argument(s) for sampling method */ 622 Node *repeatable; /* REPEATABLE expression, or NULL if none */ 623 int location; /* method name location, or -1 if unknown */ 624 } RangeTableSample; 625 626 /* 627 * ColumnDef - column definition (used in various creates) 628 * 629 * If the column has a default value, we may have the value expression 630 * in either "raw" form (an untransformed parse tree) or "cooked" form 631 * (a post-parse-analysis, executable expression tree), depending on 632 * how this ColumnDef node was created (by parsing, or by inheritance 633 * from an existing relation). We should never have both in the same node! 634 * 635 * Similarly, we may have a COLLATE specification in either raw form 636 * (represented as a CollateClause with arg==NULL) or cooked form 637 * (the collation's OID). 638 * 639 * The constraints list may contain a CONSTR_DEFAULT item in a raw 640 * parsetree produced by gram.y, but transformCreateStmt will remove 641 * the item and set raw_default instead. CONSTR_DEFAULT items 642 * should not appear in any subsequent processing. 643 */ 644 typedef struct ColumnDef 645 { 646 NodeTag type; 647 char *colname; /* name of column */ 648 TypeName *typeName; /* type of column */ 649 int inhcount; /* number of times column is inherited */ 650 bool is_local; /* column has local (non-inherited) def'n */ 651 bool is_not_null; /* NOT NULL constraint specified? */ 652 bool is_from_type; /* column definition came from table type */ 653 bool is_from_parent; /* XXX unused */ 654 char storage; /* attstorage setting, or 0 for default */ 655 Node *raw_default; /* default value (untransformed parse tree) */ 656 Node *cooked_default; /* default value (transformed expr tree) */ 657 char identity; /* attidentity setting */ 658 RangeVar *identitySequence; /* to store identity sequence name for 659 * ALTER TABLE ... ADD COLUMN */ 660 CollateClause *collClause; /* untransformed COLLATE spec, if any */ 661 Oid collOid; /* collation OID (InvalidOid if not set) */ 662 List *constraints; /* other constraints on column */ 663 List *fdwoptions; /* per-column FDW options */ 664 int location; /* parse location, or -1 if none/unknown */ 665 } ColumnDef; 666 667 /* 668 * TableLikeClause - CREATE TABLE ( ... LIKE ... ) clause 669 */ 670 typedef struct TableLikeClause 671 { 672 NodeTag type; 673 RangeVar *relation; 674 bits32 options; /* OR of TableLikeOption flags */ 675 Oid relationOid; /* If table has been looked up, its OID */ 676 } TableLikeClause; 677 678 typedef enum TableLikeOption 679 { 680 CREATE_TABLE_LIKE_COMMENTS = 1 << 0, 681 CREATE_TABLE_LIKE_CONSTRAINTS = 1 << 1, 682 CREATE_TABLE_LIKE_DEFAULTS = 1 << 2, 683 CREATE_TABLE_LIKE_IDENTITY = 1 << 3, 684 CREATE_TABLE_LIKE_INDEXES = 1 << 4, 685 CREATE_TABLE_LIKE_STATISTICS = 1 << 5, 686 CREATE_TABLE_LIKE_STORAGE = 1 << 6, 687 CREATE_TABLE_LIKE_ALL = PG_INT32_MAX 688 } TableLikeOption; 689 690 /* 691 * IndexElem - index parameters (used in CREATE INDEX, and in ON CONFLICT) 692 * 693 * For a plain index attribute, 'name' is the name of the table column to 694 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and 695 * 'expr' is the expression tree. 696 */ 697 typedef struct IndexElem 698 { 699 NodeTag type; 700 char *name; /* name of attribute to index, or NULL */ 701 Node *expr; /* expression to index, or NULL */ 702 char *indexcolname; /* name for index column; NULL = default */ 703 List *collation; /* name of collation; NIL = default */ 704 List *opclass; /* name of desired opclass; NIL = default */ 705 SortByDir ordering; /* ASC/DESC/default */ 706 SortByNulls nulls_ordering; /* FIRST/LAST/default */ 707 } IndexElem; 708 709 /* 710 * DefElem - a generic "name = value" option definition 711 * 712 * In some contexts the name can be qualified. Also, certain SQL commands 713 * allow a SET/ADD/DROP action to be attached to option settings, so it's 714 * convenient to carry a field for that too. (Note: currently, it is our 715 * practice that the grammar allows namespace and action only in statements 716 * where they are relevant; C code can just ignore those fields in other 717 * statements.) 718 */ 719 typedef enum DefElemAction 720 { 721 DEFELEM_UNSPEC, /* no action given */ 722 DEFELEM_SET, 723 DEFELEM_ADD, 724 DEFELEM_DROP 725 } DefElemAction; 726 727 typedef struct DefElem 728 { 729 NodeTag type; 730 char *defnamespace; /* NULL if unqualified name */ 731 char *defname; 732 Node *arg; /* a (Value *) or a (TypeName *) */ 733 DefElemAction defaction; /* unspecified action, or SET/ADD/DROP */ 734 int location; /* token location, or -1 if unknown */ 735 } DefElem; 736 737 /* 738 * LockingClause - raw representation of FOR [NO KEY] UPDATE/[KEY] SHARE 739 * options 740 * 741 * Note: lockedRels == NIL means "all relations in query". Otherwise it 742 * is a list of RangeVar nodes. (We use RangeVar mainly because it carries 743 * a location field --- currently, parse analysis insists on unqualified 744 * names in LockingClause.) 745 */ 746 typedef struct LockingClause 747 { 748 NodeTag type; 749 List *lockedRels; /* FOR [KEY] UPDATE/SHARE relations */ 750 LockClauseStrength strength; 751 LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */ 752 } LockingClause; 753 754 /* 755 * XMLSERIALIZE (in raw parse tree only) 756 */ 757 typedef struct XmlSerialize 758 { 759 NodeTag type; 760 XmlOptionType xmloption; /* DOCUMENT or CONTENT */ 761 Node *expr; 762 TypeName *typeName; 763 int location; /* token location, or -1 if unknown */ 764 } XmlSerialize; 765 766 /* Partitioning related definitions */ 767 768 /* 769 * PartitionElem - parse-time representation of a single partition key 770 * 771 * expr can be either a raw expression tree or a parse-analyzed expression. 772 * We don't store these on-disk, though. 773 */ 774 typedef struct PartitionElem 775 { 776 NodeTag type; 777 char *name; /* name of column to partition on, or NULL */ 778 Node *expr; /* expression to partition on, or NULL */ 779 List *collation; /* name of collation; NIL = default */ 780 List *opclass; /* name of desired opclass; NIL = default */ 781 int location; /* token location, or -1 if unknown */ 782 } PartitionElem; 783 784 /* 785 * PartitionSpec - parse-time representation of a partition key specification 786 * 787 * This represents the key space we will be partitioning on. 788 */ 789 typedef struct PartitionSpec 790 { 791 NodeTag type; 792 char *strategy; /* partitioning strategy ('hash', 'list' or 793 * 'range') */ 794 List *partParams; /* List of PartitionElems */ 795 int location; /* token location, or -1 if unknown */ 796 } PartitionSpec; 797 798 /* Internal codes for partitioning strategies */ 799 #define PARTITION_STRATEGY_HASH 'h' 800 #define PARTITION_STRATEGY_LIST 'l' 801 #define PARTITION_STRATEGY_RANGE 'r' 802 803 /* 804 * PartitionBoundSpec - a partition bound specification 805 * 806 * This represents the portion of the partition key space assigned to a 807 * particular partition. These are stored on disk in pg_class.relpartbound. 808 */ 809 struct PartitionBoundSpec 810 { 811 NodeTag type; 812 813 char strategy; /* see PARTITION_STRATEGY codes above */ 814 bool is_default; /* is it a default partition bound? */ 815 816 /* Partitioning info for HASH strategy: */ 817 int modulus; 818 int remainder; 819 820 /* Partitioning info for LIST strategy: */ 821 List *listdatums; /* List of Consts (or A_Consts in raw tree) */ 822 823 /* Partitioning info for RANGE strategy: */ 824 List *lowerdatums; /* List of PartitionRangeDatums */ 825 List *upperdatums; /* List of PartitionRangeDatums */ 826 827 int location; /* token location, or -1 if unknown */ 828 }; 829 830 /* 831 * PartitionRangeDatum - one of the values in a range partition bound 832 * 833 * This can be MINVALUE, MAXVALUE or a specific bounded value. 834 */ 835 typedef enum PartitionRangeDatumKind 836 { 837 PARTITION_RANGE_DATUM_MINVALUE = -1, /* less than any other value */ 838 PARTITION_RANGE_DATUM_VALUE = 0, /* a specific (bounded) value */ 839 PARTITION_RANGE_DATUM_MAXVALUE = 1 /* greater than any other value */ 840 } PartitionRangeDatumKind; 841 842 typedef struct PartitionRangeDatum 843 { 844 NodeTag type; 845 846 PartitionRangeDatumKind kind; 847 Node *value; /* Const (or A_Const in raw tree), if kind is 848 * PARTITION_RANGE_DATUM_VALUE, else NULL */ 849 850 int location; /* token location, or -1 if unknown */ 851 } PartitionRangeDatum; 852 853 /* 854 * PartitionCmd - info for ALTER TABLE/INDEX ATTACH/DETACH PARTITION commands 855 */ 856 typedef struct PartitionCmd 857 { 858 NodeTag type; 859 RangeVar *name; /* name of partition to attach/detach */ 860 PartitionBoundSpec *bound; /* FOR VALUES, if attaching */ 861 } PartitionCmd; 862 863 /**************************************************************************** 864 * Nodes for a Query tree 865 ****************************************************************************/ 866 867 /*-------------------- 868 * RangeTblEntry - 869 * A range table is a List of RangeTblEntry nodes. 870 * 871 * A range table entry may represent a plain relation, a sub-select in 872 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax 873 * produces an RTE, not the implicit join resulting from multiple FROM 874 * items. This is because we only need the RTE to deal with SQL features 875 * like outer joins and join-output-column aliasing.) Other special 876 * RTE types also exist, as indicated by RTEKind. 877 * 878 * Note that we consider RTE_RELATION to cover anything that has a pg_class 879 * entry. relkind distinguishes the sub-cases. 880 * 881 * alias is an Alias node representing the AS alias-clause attached to the 882 * FROM expression, or NULL if no clause. 883 * 884 * eref is the table reference name and column reference names (either 885 * real or aliases). Note that system columns (OID etc) are not included 886 * in the column list. 887 * eref->aliasname is required to be present, and should generally be used 888 * to identify the RTE for error messages etc. 889 * 890 * In RELATION RTEs, the colnames in both alias and eref are indexed by 891 * physical attribute number; this means there must be colname entries for 892 * dropped columns. When building an RTE we insert empty strings ("") for 893 * dropped columns. Note however that a stored rule may have nonempty 894 * colnames for columns dropped since the rule was created (and for that 895 * matter the colnames might be out of date due to column renamings). 896 * The same comments apply to FUNCTION RTEs when a function's return type 897 * is a named composite type. 898 * 899 * In JOIN RTEs, the colnames in both alias and eref are one-to-one with 900 * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when 901 * those columns are known to be dropped at parse time. Again, however, 902 * a stored rule might contain entries for columns dropped since the rule 903 * was created. (This is only possible for columns not actually referenced 904 * in the rule.) When loading a stored rule, we replace the joinaliasvars 905 * items for any such columns with null pointers. (We can't simply delete 906 * them from the joinaliasvars list, because that would affect the attnums 907 * of Vars referencing the rest of the list.) 908 * 909 * inh is true for relation references that should be expanded to include 910 * inheritance children, if the rel has any. This *must* be false for 911 * RTEs other than RTE_RELATION entries. 912 * 913 * inFromCl marks those range variables that are listed in the FROM clause. 914 * It's false for RTEs that are added to a query behind the scenes, such 915 * as the NEW and OLD variables for a rule, or the subqueries of a UNION. 916 * This flag is not used during parsing (except in transformLockingClause, 917 * q.v.); the parser now uses a separate "namespace" data structure to 918 * control visibility. But it is needed by ruleutils.c to determine 919 * whether RTEs should be shown in decompiled queries. 920 * 921 * requiredPerms and checkAsUser specify run-time access permissions 922 * checks to be performed at query startup. The user must have *all* 923 * of the permissions that are OR'd together in requiredPerms (zero 924 * indicates no permissions checking). If checkAsUser is not zero, 925 * then do the permissions checks using the access rights of that user, 926 * not the current effective user ID. (This allows rules to act as 927 * setuid gateways.) Permissions checks only apply to RELATION RTEs. 928 * 929 * For SELECT/INSERT/UPDATE permissions, if the user doesn't have 930 * table-wide permissions then it is sufficient to have the permissions 931 * on all columns identified in selectedCols (for SELECT) and/or 932 * insertedCols and/or updatedCols (INSERT with ON CONFLICT DO UPDATE may 933 * have all 3). selectedCols, insertedCols and updatedCols are bitmapsets, 934 * which cannot have negative integer members, so we subtract 935 * FirstLowInvalidHeapAttributeNumber from column numbers before storing 936 * them in these fields. A whole-row Var reference is represented by 937 * setting the bit for InvalidAttrNumber. 938 * 939 * securityQuals is a list of security barrier quals (boolean expressions), 940 * to be tested in the listed order before returning a row from the 941 * relation. It is always NIL in parser output. Entries are added by the 942 * rewriter to implement security-barrier views and/or row-level security. 943 * Note that the planner turns each boolean expression into an implicitly 944 * AND'ed sublist, as is its usual habit with qualification expressions. 945 *-------------------- 946 */ 947 typedef enum RTEKind 948 { 949 RTE_RELATION, /* ordinary relation reference */ 950 RTE_SUBQUERY, /* subquery in FROM */ 951 RTE_JOIN, /* join */ 952 RTE_FUNCTION, /* function in FROM */ 953 RTE_TABLEFUNC, /* TableFunc(.., column list) */ 954 RTE_VALUES, /* VALUES (<exprlist>), (<exprlist>), ... */ 955 RTE_CTE, /* common table expr (WITH list element) */ 956 RTE_NAMEDTUPLESTORE /* tuplestore, e.g. for AFTER triggers */ 957 } RTEKind; 958 959 typedef struct RangeTblEntry 960 { 961 NodeTag type; 962 963 RTEKind rtekind; /* see above */ 964 965 /* 966 * XXX the fields applicable to only some rte kinds should be merged into 967 * a union. I didn't do this yet because the diffs would impact a lot of 968 * code that is being actively worked on. FIXME someday. 969 */ 970 971 /* 972 * Fields valid for a plain relation RTE (else zero): 973 * 974 * As a special case, RTE_NAMEDTUPLESTORE can also set relid to indicate 975 * that the tuple format of the tuplestore is the same as the referenced 976 * relation. This allows plans referencing AFTER trigger transition 977 * tables to be invalidated if the underlying table is altered. 978 */ 979 Oid relid; /* OID of the relation */ 980 char relkind; /* relation kind (see pg_class.relkind) */ 981 struct TableSampleClause *tablesample; /* sampling info, or NULL */ 982 983 /* 984 * Fields valid for a subquery RTE (else NULL): 985 */ 986 Query *subquery; /* the sub-query */ 987 bool security_barrier; /* is from security_barrier view? */ 988 989 /* 990 * Fields valid for a join RTE (else NULL/zero): 991 * 992 * joinaliasvars is a list of (usually) Vars corresponding to the columns 993 * of the join result. An alias Var referencing column K of the join 994 * result can be replaced by the K'th element of joinaliasvars --- but to 995 * simplify the task of reverse-listing aliases correctly, we do not do 996 * that until planning time. In detail: an element of joinaliasvars can 997 * be a Var of one of the join's input relations, or such a Var with an 998 * implicit coercion to the join's output column type, or a COALESCE 999 * expression containing the two input column Vars (possibly coerced). 1000 * Within a Query loaded from a stored rule, it is also possible for 1001 * joinaliasvars items to be null pointers, which are placeholders for 1002 * (necessarily unreferenced) columns dropped since the rule was made. 1003 * Also, once planning begins, joinaliasvars items can be almost anything, 1004 * as a result of subquery-flattening substitutions. 1005 */ 1006 JoinType jointype; /* type of join */ 1007 List *joinaliasvars; /* list of alias-var expansions */ 1008 1009 /* 1010 * Fields valid for a function RTE (else NIL/zero): 1011 * 1012 * When funcordinality is true, the eref->colnames list includes an alias 1013 * for the ordinality column. The ordinality column is otherwise 1014 * implicit, and must be accounted for "by hand" in places such as 1015 * expandRTE(). 1016 */ 1017 List *functions; /* list of RangeTblFunction nodes */ 1018 bool funcordinality; /* is this called WITH ORDINALITY? */ 1019 1020 /* 1021 * Fields valid for a TableFunc RTE (else NULL): 1022 */ 1023 TableFunc *tablefunc; 1024 1025 /* 1026 * Fields valid for a values RTE (else NIL): 1027 */ 1028 List *values_lists; /* list of expression lists */ 1029 1030 /* 1031 * Fields valid for a CTE RTE (else NULL/zero): 1032 */ 1033 char *ctename; /* name of the WITH list item */ 1034 Index ctelevelsup; /* number of query levels up */ 1035 bool self_reference; /* is this a recursive self-reference? */ 1036 1037 /* 1038 * Fields valid for CTE, VALUES, ENR, and TableFunc RTEs (else NIL): 1039 * 1040 * We need these for CTE RTEs so that the types of self-referential 1041 * columns are well-defined. For VALUES RTEs, storing these explicitly 1042 * saves having to re-determine the info by scanning the values_lists. For 1043 * ENRs, we store the types explicitly here (we could get the information 1044 * from the catalogs if 'relid' was supplied, but we'd still need these 1045 * for TupleDesc-based ENRs, so we might as well always store the type 1046 * info here). For TableFuncs, these fields are redundant with data in 1047 * the TableFunc node, but keeping them here allows some code sharing with 1048 * the other cases. 1049 * 1050 * For ENRs only, we have to consider the possibility of dropped columns. 1051 * A dropped column is included in these lists, but it will have zeroes in 1052 * all three lists (as well as an empty-string entry in eref). Testing 1053 * for zero coltype is the standard way to detect a dropped column. 1054 */ 1055 List *coltypes; /* OID list of column type OIDs */ 1056 List *coltypmods; /* integer list of column typmods */ 1057 List *colcollations; /* OID list of column collation OIDs */ 1058 1059 /* 1060 * Fields valid for ENR RTEs (else NULL/zero): 1061 */ 1062 char *enrname; /* name of ephemeral named relation */ 1063 double enrtuples; /* estimated or actual from caller */ 1064 1065 /* 1066 * Fields valid in all RTEs: 1067 */ 1068 Alias *alias; /* user-written alias clause, if any */ 1069 Alias *eref; /* expanded reference names */ 1070 bool lateral; /* subquery, function, or values is LATERAL? */ 1071 bool inh; /* inheritance requested? */ 1072 bool inFromCl; /* present in FROM clause? */ 1073 AclMode requiredPerms; /* bitmask of required access permissions */ 1074 Oid checkAsUser; /* if valid, check access as this role */ 1075 Bitmapset *selectedCols; /* columns needing SELECT permission */ 1076 Bitmapset *insertedCols; /* columns needing INSERT permission */ 1077 Bitmapset *updatedCols; /* columns needing UPDATE permission */ 1078 List *securityQuals; /* security barrier quals to apply, if any */ 1079 } RangeTblEntry; 1080 1081 /* 1082 * RangeTblFunction - 1083 * RangeTblEntry subsidiary data for one function in a FUNCTION RTE. 1084 * 1085 * If the function had a column definition list (required for an 1086 * otherwise-unspecified RECORD result), funccolnames lists the names given 1087 * in the definition list, funccoltypes lists their declared column types, 1088 * funccoltypmods lists their typmods, funccolcollations their collations. 1089 * Otherwise, those fields are NIL. 1090 * 1091 * Notice we don't attempt to store info about the results of functions 1092 * returning named composite types, because those can change from time to 1093 * time. We do however remember how many columns we thought the type had 1094 * (including dropped columns!), so that we can successfully ignore any 1095 * columns added after the query was parsed. 1096 */ 1097 typedef struct RangeTblFunction 1098 { 1099 NodeTag type; 1100 1101 Node *funcexpr; /* expression tree for func call */ 1102 int funccolcount; /* number of columns it contributes to RTE */ 1103 /* These fields record the contents of a column definition list, if any: */ 1104 List *funccolnames; /* column names (list of String) */ 1105 List *funccoltypes; /* OID list of column type OIDs */ 1106 List *funccoltypmods; /* integer list of column typmods */ 1107 List *funccolcollations; /* OID list of column collation OIDs */ 1108 /* This is set during planning for use by the executor: */ 1109 Bitmapset *funcparams; /* PARAM_EXEC Param IDs affecting this func */ 1110 } RangeTblFunction; 1111 1112 /* 1113 * TableSampleClause - TABLESAMPLE appearing in a transformed FROM clause 1114 * 1115 * Unlike RangeTableSample, this is a subnode of the relevant RangeTblEntry. 1116 */ 1117 typedef struct TableSampleClause 1118 { 1119 NodeTag type; 1120 Oid tsmhandler; /* OID of the tablesample handler function */ 1121 List *args; /* tablesample argument expression(s) */ 1122 Expr *repeatable; /* REPEATABLE expression, or NULL if none */ 1123 } TableSampleClause; 1124 1125 /* 1126 * WithCheckOption - 1127 * representation of WITH CHECK OPTION checks to be applied to new tuples 1128 * when inserting/updating an auto-updatable view, or RLS WITH CHECK 1129 * policies to be applied when inserting/updating a relation with RLS. 1130 */ 1131 typedef enum WCOKind 1132 { 1133 WCO_VIEW_CHECK, /* WCO on an auto-updatable view */ 1134 WCO_RLS_INSERT_CHECK, /* RLS INSERT WITH CHECK policy */ 1135 WCO_RLS_UPDATE_CHECK, /* RLS UPDATE WITH CHECK policy */ 1136 WCO_RLS_CONFLICT_CHECK /* RLS ON CONFLICT DO UPDATE USING policy */ 1137 } WCOKind; 1138 1139 typedef struct WithCheckOption 1140 { 1141 NodeTag type; 1142 WCOKind kind; /* kind of WCO */ 1143 char *relname; /* name of relation that specified the WCO */ 1144 char *polname; /* name of RLS policy being checked */ 1145 Node *qual; /* constraint qual to check */ 1146 bool cascaded; /* true for a cascaded WCO on a view */ 1147 } WithCheckOption; 1148 1149 /* 1150 * SortGroupClause - 1151 * representation of ORDER BY, GROUP BY, PARTITION BY, 1152 * DISTINCT, DISTINCT ON items 1153 * 1154 * You might think that ORDER BY is only interested in defining ordering, 1155 * and GROUP/DISTINCT are only interested in defining equality. However, 1156 * one way to implement grouping is to sort and then apply a "uniq"-like 1157 * filter. So it's also interesting to keep track of possible sort operators 1158 * for GROUP/DISTINCT, and in particular to try to sort for the grouping 1159 * in a way that will also yield a requested ORDER BY ordering. So we need 1160 * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates 1161 * the decision to give them the same representation. 1162 * 1163 * tleSortGroupRef must match ressortgroupref of exactly one entry of the 1164 * query's targetlist; that is the expression to be sorted or grouped by. 1165 * eqop is the OID of the equality operator. 1166 * sortop is the OID of the ordering operator (a "<" or ">" operator), 1167 * or InvalidOid if not available. 1168 * nulls_first means about what you'd expect. If sortop is InvalidOid 1169 * then nulls_first is meaningless and should be set to false. 1170 * hashable is true if eqop is hashable (note this condition also depends 1171 * on the datatype of the input expression). 1172 * 1173 * In an ORDER BY item, all fields must be valid. (The eqop isn't essential 1174 * here, but it's cheap to get it along with the sortop, and requiring it 1175 * to be valid eases comparisons to grouping items.) Note that this isn't 1176 * actually enough information to determine an ordering: if the sortop is 1177 * collation-sensitive, a collation OID is needed too. We don't store the 1178 * collation in SortGroupClause because it's not available at the time the 1179 * parser builds the SortGroupClause; instead, consult the exposed collation 1180 * of the referenced targetlist expression to find out what it is. 1181 * 1182 * In a grouping item, eqop must be valid. If the eqop is a btree equality 1183 * operator, then sortop should be set to a compatible ordering operator. 1184 * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that 1185 * the query presents for the same tlist item. If there is none, we just 1186 * use the default ordering op for the datatype. 1187 * 1188 * If the tlist item's type has a hash opclass but no btree opclass, then 1189 * we will set eqop to the hash equality operator, sortop to InvalidOid, 1190 * and nulls_first to false. A grouping item of this kind can only be 1191 * implemented by hashing, and of course it'll never match an ORDER BY item. 1192 * 1193 * The hashable flag is provided since we generally have the requisite 1194 * information readily available when the SortGroupClause is constructed, 1195 * and it's relatively expensive to get it again later. Note there is no 1196 * need for a "sortable" flag since OidIsValid(sortop) serves the purpose. 1197 * 1198 * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses. 1199 * In SELECT DISTINCT, the distinctClause list is as long or longer than the 1200 * sortClause list, while in SELECT DISTINCT ON it's typically shorter. 1201 * The two lists must match up to the end of the shorter one --- the parser 1202 * rearranges the distinctClause if necessary to make this true. (This 1203 * restriction ensures that only one sort step is needed to both satisfy the 1204 * ORDER BY and set up for the Unique step. This is semantically necessary 1205 * for DISTINCT ON, and presents no real drawback for DISTINCT.) 1206 */ 1207 typedef struct SortGroupClause 1208 { 1209 NodeTag type; 1210 Index tleSortGroupRef; /* reference into targetlist */ 1211 Oid eqop; /* the equality operator ('=' op) */ 1212 Oid sortop; /* the ordering operator ('<' op), or 0 */ 1213 bool nulls_first; /* do NULLs come before normal values? */ 1214 bool hashable; /* can eqop be implemented by hashing? */ 1215 } SortGroupClause; 1216 1217 /* 1218 * GroupingSet - 1219 * representation of CUBE, ROLLUP and GROUPING SETS clauses 1220 * 1221 * In a Query with grouping sets, the groupClause contains a flat list of 1222 * SortGroupClause nodes for each distinct expression used. The actual 1223 * structure of the GROUP BY clause is given by the groupingSets tree. 1224 * 1225 * In the raw parser output, GroupingSet nodes (of all types except SIMPLE 1226 * which is not used) are potentially mixed in with the expressions in the 1227 * groupClause of the SelectStmt. (An expression can't contain a GroupingSet, 1228 * but a list may mix GroupingSet and expression nodes.) At this stage, the 1229 * content of each node is a list of expressions, some of which may be RowExprs 1230 * which represent sublists rather than actual row constructors, and nested 1231 * GroupingSet nodes where legal in the grammar. The structure directly 1232 * reflects the query syntax. 1233 * 1234 * In parse analysis, the transformed expressions are used to build the tlist 1235 * and groupClause list (of SortGroupClause nodes), and the groupingSets tree 1236 * is eventually reduced to a fixed format: 1237 * 1238 * EMPTY nodes represent (), and obviously have no content 1239 * 1240 * SIMPLE nodes represent a list of one or more expressions to be treated as an 1241 * atom by the enclosing structure; the content is an integer list of 1242 * ressortgroupref values (see SortGroupClause) 1243 * 1244 * CUBE and ROLLUP nodes contain a list of one or more SIMPLE nodes. 1245 * 1246 * SETS nodes contain a list of EMPTY, SIMPLE, CUBE or ROLLUP nodes, but after 1247 * parse analysis they cannot contain more SETS nodes; enough of the syntactic 1248 * transforms of the spec have been applied that we no longer have arbitrarily 1249 * deep nesting (though we still preserve the use of cube/rollup). 1250 * 1251 * Note that if the groupingSets tree contains no SIMPLE nodes (only EMPTY 1252 * nodes at the leaves), then the groupClause will be empty, but this is still 1253 * an aggregation query (similar to using aggs or HAVING without GROUP BY). 1254 * 1255 * As an example, the following clause: 1256 * 1257 * GROUP BY GROUPING SETS ((a,b), CUBE(c,(d,e))) 1258 * 1259 * looks like this after raw parsing: 1260 * 1261 * SETS( RowExpr(a,b) , CUBE( c, RowExpr(d,e) ) ) 1262 * 1263 * and parse analysis converts it to: 1264 * 1265 * SETS( SIMPLE(1,2), CUBE( SIMPLE(3), SIMPLE(4,5) ) ) 1266 */ 1267 typedef enum 1268 { 1269 GROUPING_SET_EMPTY, 1270 GROUPING_SET_SIMPLE, 1271 GROUPING_SET_ROLLUP, 1272 GROUPING_SET_CUBE, 1273 GROUPING_SET_SETS 1274 } GroupingSetKind; 1275 1276 typedef struct GroupingSet 1277 { 1278 NodeTag type; 1279 GroupingSetKind kind; 1280 List *content; 1281 int location; 1282 } GroupingSet; 1283 1284 /* 1285 * WindowClause - 1286 * transformed representation of WINDOW and OVER clauses 1287 * 1288 * A parsed Query's windowClause list contains these structs. "name" is set 1289 * if the clause originally came from WINDOW, and is NULL if it originally 1290 * was an OVER clause (but note that we collapse out duplicate OVERs). 1291 * partitionClause and orderClause are lists of SortGroupClause structs. 1292 * If we have RANGE with offset PRECEDING/FOLLOWING, the semantics of that are 1293 * specified by startInRangeFunc/inRangeColl/inRangeAsc/inRangeNullsFirst 1294 * for the start offset, or endInRangeFunc/inRange* for the end offset. 1295 * winref is an ID number referenced by WindowFunc nodes; it must be unique 1296 * among the members of a Query's windowClause list. 1297 * When refname isn't null, the partitionClause is always copied from there; 1298 * the orderClause might or might not be copied (see copiedOrder); the framing 1299 * options are never copied, per spec. 1300 */ 1301 typedef struct WindowClause 1302 { 1303 NodeTag type; 1304 char *name; /* window name (NULL in an OVER clause) */ 1305 char *refname; /* referenced window name, if any */ 1306 List *partitionClause; /* PARTITION BY list */ 1307 List *orderClause; /* ORDER BY list */ 1308 int frameOptions; /* frame_clause options, see WindowDef */ 1309 Node *startOffset; /* expression for starting bound, if any */ 1310 Node *endOffset; /* expression for ending bound, if any */ 1311 Oid startInRangeFunc; /* in_range function for startOffset */ 1312 Oid endInRangeFunc; /* in_range function for endOffset */ 1313 Oid inRangeColl; /* collation for in_range tests */ 1314 bool inRangeAsc; /* use ASC sort order for in_range tests? */ 1315 bool inRangeNullsFirst; /* nulls sort first for in_range tests? */ 1316 Index winref; /* ID referenced by window functions */ 1317 bool copiedOrder; /* did we copy orderClause from refname? */ 1318 } WindowClause; 1319 1320 /* 1321 * RowMarkClause - 1322 * parser output representation of FOR [KEY] UPDATE/SHARE clauses 1323 * 1324 * Query.rowMarks contains a separate RowMarkClause node for each relation 1325 * identified as a FOR [KEY] UPDATE/SHARE target. If one of these clauses 1326 * is applied to a subquery, we generate RowMarkClauses for all normal and 1327 * subquery rels in the subquery, but they are marked pushedDown = true to 1328 * distinguish them from clauses that were explicitly written at this query 1329 * level. Also, Query.hasForUpdate tells whether there were explicit FOR 1330 * UPDATE/SHARE/KEY SHARE clauses in the current query level. 1331 */ 1332 typedef struct RowMarkClause 1333 { 1334 NodeTag type; 1335 Index rti; /* range table index of target relation */ 1336 LockClauseStrength strength; 1337 LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */ 1338 bool pushedDown; /* pushed down from higher query level? */ 1339 } RowMarkClause; 1340 1341 /* 1342 * WithClause - 1343 * representation of WITH clause 1344 * 1345 * Note: WithClause does not propagate into the Query representation; 1346 * but CommonTableExpr does. 1347 */ 1348 typedef struct WithClause 1349 { 1350 NodeTag type; 1351 List *ctes; /* list of CommonTableExprs */ 1352 bool recursive; /* true = WITH RECURSIVE */ 1353 int location; /* token location, or -1 if unknown */ 1354 } WithClause; 1355 1356 /* 1357 * InferClause - 1358 * ON CONFLICT unique index inference clause 1359 * 1360 * Note: InferClause does not propagate into the Query representation. 1361 */ 1362 typedef struct InferClause 1363 { 1364 NodeTag type; 1365 List *indexElems; /* IndexElems to infer unique index */ 1366 Node *whereClause; /* qualification (partial-index predicate) */ 1367 char *conname; /* Constraint name, or NULL if unnamed */ 1368 int location; /* token location, or -1 if unknown */ 1369 } InferClause; 1370 1371 /* 1372 * OnConflictClause - 1373 * representation of ON CONFLICT clause 1374 * 1375 * Note: OnConflictClause does not propagate into the Query representation. 1376 */ 1377 typedef struct OnConflictClause 1378 { 1379 NodeTag type; 1380 OnConflictAction action; /* DO NOTHING or UPDATE? */ 1381 InferClause *infer; /* Optional index inference clause */ 1382 List *targetList; /* the target list (of ResTarget) */ 1383 Node *whereClause; /* qualifications */ 1384 int location; /* token location, or -1 if unknown */ 1385 } OnConflictClause; 1386 1387 /* 1388 * CommonTableExpr - 1389 * representation of WITH list element 1390 * 1391 * We don't currently support the SEARCH or CYCLE clause. 1392 */ 1393 typedef struct CommonTableExpr 1394 { 1395 NodeTag type; 1396 char *ctename; /* query name (never qualified) */ 1397 List *aliascolnames; /* optional list of column names */ 1398 /* SelectStmt/InsertStmt/etc before parse analysis, Query afterwards: */ 1399 Node *ctequery; /* the CTE's subquery */ 1400 int location; /* token location, or -1 if unknown */ 1401 /* These fields are set during parse analysis: */ 1402 bool cterecursive; /* is this CTE actually recursive? */ 1403 int cterefcount; /* number of RTEs referencing this CTE 1404 * (excluding internal self-references) */ 1405 List *ctecolnames; /* list of output column names */ 1406 List *ctecoltypes; /* OID list of output column type OIDs */ 1407 List *ctecoltypmods; /* integer list of output column typmods */ 1408 List *ctecolcollations; /* OID list of column collation OIDs */ 1409 } CommonTableExpr; 1410 1411 /* Convenience macro to get the output tlist of a CTE's query */ 1412 #define GetCTETargetList(cte) \ 1413 (AssertMacro(IsA((cte)->ctequery, Query)), \ 1414 ((Query *) (cte)->ctequery)->commandType == CMD_SELECT ? \ 1415 ((Query *) (cte)->ctequery)->targetList : \ 1416 ((Query *) (cte)->ctequery)->returningList) 1417 1418 /* 1419 * TriggerTransition - 1420 * representation of transition row or table naming clause 1421 * 1422 * Only transition tables are initially supported in the syntax, and only for 1423 * AFTER triggers, but other permutations are accepted by the parser so we can 1424 * give a meaningful message from C code. 1425 */ 1426 typedef struct TriggerTransition 1427 { 1428 NodeTag type; 1429 char *name; 1430 bool isNew; 1431 bool isTable; 1432 } TriggerTransition; 1433 1434 /***************************************************************************** 1435 * Raw Grammar Output Statements 1436 *****************************************************************************/ 1437 1438 /* 1439 * RawStmt --- container for any one statement's raw parse tree 1440 * 1441 * Parse analysis converts a raw parse tree headed by a RawStmt node into 1442 * an analyzed statement headed by a Query node. For optimizable statements, 1443 * the conversion is complex. For utility statements, the parser usually just 1444 * transfers the raw parse tree (sans RawStmt) into the utilityStmt field of 1445 * the Query node, and all the useful work happens at execution time. 1446 * 1447 * stmt_location/stmt_len identify the portion of the source text string 1448 * containing this raw statement (useful for multi-statement strings). 1449 */ 1450 typedef struct RawStmt 1451 { 1452 NodeTag type; 1453 Node *stmt; /* raw parse tree */ 1454 int stmt_location; /* start location, or -1 if unknown */ 1455 int stmt_len; /* length in bytes; 0 means "rest of string" */ 1456 } RawStmt; 1457 1458 /***************************************************************************** 1459 * Optimizable Statements 1460 *****************************************************************************/ 1461 1462 /* ---------------------- 1463 * Insert Statement 1464 * 1465 * The source expression is represented by SelectStmt for both the 1466 * SELECT and VALUES cases. If selectStmt is NULL, then the query 1467 * is INSERT ... DEFAULT VALUES. 1468 * ---------------------- 1469 */ 1470 typedef struct InsertStmt 1471 { 1472 NodeTag type; 1473 RangeVar *relation; /* relation to insert into */ 1474 List *cols; /* optional: names of the target columns */ 1475 Node *selectStmt; /* the source SELECT/VALUES, or NULL */ 1476 OnConflictClause *onConflictClause; /* ON CONFLICT clause */ 1477 List *returningList; /* list of expressions to return */ 1478 WithClause *withClause; /* WITH clause */ 1479 OverridingKind override; /* OVERRIDING clause */ 1480 } InsertStmt; 1481 1482 /* ---------------------- 1483 * Delete Statement 1484 * ---------------------- 1485 */ 1486 typedef struct DeleteStmt 1487 { 1488 NodeTag type; 1489 RangeVar *relation; /* relation to delete from */ 1490 List *usingClause; /* optional using clause for more tables */ 1491 Node *whereClause; /* qualifications */ 1492 List *returningList; /* list of expressions to return */ 1493 WithClause *withClause; /* WITH clause */ 1494 } DeleteStmt; 1495 1496 /* ---------------------- 1497 * Update Statement 1498 * ---------------------- 1499 */ 1500 typedef struct UpdateStmt 1501 { 1502 NodeTag type; 1503 RangeVar *relation; /* relation to update */ 1504 List *targetList; /* the target list (of ResTarget) */ 1505 Node *whereClause; /* qualifications */ 1506 List *fromClause; /* optional from clause for more tables */ 1507 List *returningList; /* list of expressions to return */ 1508 WithClause *withClause; /* WITH clause */ 1509 } UpdateStmt; 1510 1511 /* ---------------------- 1512 * Select Statement 1513 * 1514 * A "simple" SELECT is represented in the output of gram.y by a single 1515 * SelectStmt node; so is a VALUES construct. A query containing set 1516 * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt 1517 * nodes, in which the leaf nodes are component SELECTs and the internal nodes 1518 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node 1519 * type for both leaf and internal nodes allows gram.y to stick ORDER BY, 1520 * LIMIT, etc, clause values into a SELECT statement without worrying 1521 * whether it is a simple or compound SELECT. 1522 * ---------------------- 1523 */ 1524 typedef enum SetOperation 1525 { 1526 SETOP_NONE = 0, 1527 SETOP_UNION, 1528 SETOP_INTERSECT, 1529 SETOP_EXCEPT 1530 } SetOperation; 1531 1532 typedef struct SelectStmt 1533 { 1534 NodeTag type; 1535 1536 /* 1537 * These fields are used only in "leaf" SelectStmts. 1538 */ 1539 List *distinctClause; /* NULL, list of DISTINCT ON exprs, or 1540 * lcons(NIL,NIL) for all (SELECT DISTINCT) */ 1541 IntoClause *intoClause; /* target for SELECT INTO */ 1542 List *targetList; /* the target list (of ResTarget) */ 1543 List *fromClause; /* the FROM clause */ 1544 Node *whereClause; /* WHERE qualification */ 1545 List *groupClause; /* GROUP BY clauses */ 1546 Node *havingClause; /* HAVING conditional-expression */ 1547 List *windowClause; /* WINDOW window_name AS (...), ... */ 1548 1549 /* 1550 * In a "leaf" node representing a VALUES list, the above fields are all 1551 * null, and instead this field is set. Note that the elements of the 1552 * sublists are just expressions, without ResTarget decoration. Also note 1553 * that a list element can be DEFAULT (represented as a SetToDefault 1554 * node), regardless of the context of the VALUES list. It's up to parse 1555 * analysis to reject that where not valid. 1556 */ 1557 List *valuesLists; /* untransformed list of expression lists */ 1558 1559 /* 1560 * These fields are used in both "leaf" SelectStmts and upper-level 1561 * SelectStmts. 1562 */ 1563 List *sortClause; /* sort clause (a list of SortBy's) */ 1564 Node *limitOffset; /* # of result tuples to skip */ 1565 Node *limitCount; /* # of result tuples to return */ 1566 List *lockingClause; /* FOR UPDATE (list of LockingClause's) */ 1567 WithClause *withClause; /* WITH clause */ 1568 1569 /* 1570 * These fields are used only in upper-level SelectStmts. 1571 */ 1572 SetOperation op; /* type of set op */ 1573 bool all; /* ALL specified? */ 1574 struct SelectStmt *larg; /* left child */ 1575 struct SelectStmt *rarg; /* right child */ 1576 /* Eventually add fields for CORRESPONDING spec here */ 1577 } SelectStmt; 1578 1579 1580 /* ---------------------- 1581 * Set Operation node for post-analysis query trees 1582 * 1583 * After parse analysis, a SELECT with set operations is represented by a 1584 * top-level Query node containing the leaf SELECTs as subqueries in its 1585 * range table. Its setOperations field shows the tree of set operations, 1586 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal 1587 * nodes replaced by SetOperationStmt nodes. Information about the output 1588 * column types is added, too. (Note that the child nodes do not necessarily 1589 * produce these types directly, but we've checked that their output types 1590 * can be coerced to the output column type.) Also, if it's not UNION ALL, 1591 * information about the types' sort/group semantics is provided in the form 1592 * of a SortGroupClause list (same representation as, eg, DISTINCT). 1593 * The resolved common column collations are provided too; but note that if 1594 * it's not UNION ALL, it's okay for a column to not have a common collation, 1595 * so a member of the colCollations list could be InvalidOid even though the 1596 * column has a collatable type. 1597 * ---------------------- 1598 */ 1599 typedef struct SetOperationStmt 1600 { 1601 NodeTag type; 1602 SetOperation op; /* type of set op */ 1603 bool all; /* ALL specified? */ 1604 Node *larg; /* left child */ 1605 Node *rarg; /* right child */ 1606 /* Eventually add fields for CORRESPONDING spec here */ 1607 1608 /* Fields derived during parse analysis: */ 1609 List *colTypes; /* OID list of output column type OIDs */ 1610 List *colTypmods; /* integer list of output column typmods */ 1611 List *colCollations; /* OID list of output column collation OIDs */ 1612 List *groupClauses; /* a list of SortGroupClause's */ 1613 /* groupClauses is NIL if UNION ALL, but must be set otherwise */ 1614 } SetOperationStmt; 1615 1616 1617 /***************************************************************************** 1618 * Other Statements (no optimizations required) 1619 * 1620 * These are not touched by parser/analyze.c except to put them into 1621 * the utilityStmt field of a Query. This is eventually passed to 1622 * ProcessUtility (by-passing rewriting and planning). Some of the 1623 * statements do need attention from parse analysis, and this is 1624 * done by routines in parser/parse_utilcmd.c after ProcessUtility 1625 * receives the command for execution. 1626 * DECLARE CURSOR, EXPLAIN, and CREATE TABLE AS are special cases: 1627 * they contain optimizable statements, which get processed normally 1628 * by parser/analyze.c. 1629 *****************************************************************************/ 1630 1631 /* 1632 * When a command can act on several kinds of objects with only one 1633 * parse structure required, use these constants to designate the 1634 * object type. Note that commands typically don't support all the types. 1635 */ 1636 1637 typedef enum ObjectType 1638 { 1639 OBJECT_ACCESS_METHOD, 1640 OBJECT_AGGREGATE, 1641 OBJECT_AMOP, 1642 OBJECT_AMPROC, 1643 OBJECT_ATTRIBUTE, /* type's attribute, when distinct from column */ 1644 OBJECT_CAST, 1645 OBJECT_COLUMN, 1646 OBJECT_COLLATION, 1647 OBJECT_CONVERSION, 1648 OBJECT_DATABASE, 1649 OBJECT_DEFAULT, 1650 OBJECT_DEFACL, 1651 OBJECT_DOMAIN, 1652 OBJECT_DOMCONSTRAINT, 1653 OBJECT_EVENT_TRIGGER, 1654 OBJECT_EXTENSION, 1655 OBJECT_FDW, 1656 OBJECT_FOREIGN_SERVER, 1657 OBJECT_FOREIGN_TABLE, 1658 OBJECT_FUNCTION, 1659 OBJECT_INDEX, 1660 OBJECT_LANGUAGE, 1661 OBJECT_LARGEOBJECT, 1662 OBJECT_MATVIEW, 1663 OBJECT_OPCLASS, 1664 OBJECT_OPERATOR, 1665 OBJECT_OPFAMILY, 1666 OBJECT_POLICY, 1667 OBJECT_PROCEDURE, 1668 OBJECT_PUBLICATION, 1669 OBJECT_PUBLICATION_REL, 1670 OBJECT_ROLE, 1671 OBJECT_ROUTINE, 1672 OBJECT_RULE, 1673 OBJECT_SCHEMA, 1674 OBJECT_SEQUENCE, 1675 OBJECT_SUBSCRIPTION, 1676 OBJECT_STATISTIC_EXT, 1677 OBJECT_TABCONSTRAINT, 1678 OBJECT_TABLE, 1679 OBJECT_TABLESPACE, 1680 OBJECT_TRANSFORM, 1681 OBJECT_TRIGGER, 1682 OBJECT_TSCONFIGURATION, 1683 OBJECT_TSDICTIONARY, 1684 OBJECT_TSPARSER, 1685 OBJECT_TSTEMPLATE, 1686 OBJECT_TYPE, 1687 OBJECT_USER_MAPPING, 1688 OBJECT_VIEW 1689 } ObjectType; 1690 1691 /* ---------------------- 1692 * Create Schema Statement 1693 * 1694 * NOTE: the schemaElts list contains raw parsetrees for component statements 1695 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and 1696 * executed after the schema itself is created. 1697 * ---------------------- 1698 */ 1699 typedef struct CreateSchemaStmt 1700 { 1701 NodeTag type; 1702 char *schemaname; /* the name of the schema to create */ 1703 RoleSpec *authrole; /* the owner of the created schema */ 1704 List *schemaElts; /* schema components (list of parsenodes) */ 1705 bool if_not_exists; /* just do nothing if schema already exists? */ 1706 } CreateSchemaStmt; 1707 1708 typedef enum DropBehavior 1709 { 1710 DROP_RESTRICT, /* drop fails if any dependent objects */ 1711 DROP_CASCADE /* remove dependent objects too */ 1712 } DropBehavior; 1713 1714 /* ---------------------- 1715 * Alter Table 1716 * ---------------------- 1717 */ 1718 typedef struct AlterTableStmt 1719 { 1720 NodeTag type; 1721 RangeVar *relation; /* table to work on */ 1722 List *cmds; /* list of subcommands */ 1723 ObjectType relkind; /* type of object */ 1724 bool missing_ok; /* skip error if table missing */ 1725 } AlterTableStmt; 1726 1727 typedef enum AlterTableType 1728 { 1729 AT_AddColumn, /* add column */ 1730 AT_AddColumnRecurse, /* internal to commands/tablecmds.c */ 1731 AT_AddColumnToView, /* implicitly via CREATE OR REPLACE VIEW */ 1732 AT_ColumnDefault, /* alter column default */ 1733 AT_DropNotNull, /* alter column drop not null */ 1734 AT_SetNotNull, /* alter column set not null */ 1735 AT_SetStatistics, /* alter column set statistics */ 1736 AT_SetOptions, /* alter column set ( options ) */ 1737 AT_ResetOptions, /* alter column reset ( options ) */ 1738 AT_SetStorage, /* alter column set storage */ 1739 AT_DropColumn, /* drop column */ 1740 AT_DropColumnRecurse, /* internal to commands/tablecmds.c */ 1741 AT_AddIndex, /* add index */ 1742 AT_ReAddIndex, /* internal to commands/tablecmds.c */ 1743 AT_AddConstraint, /* add constraint */ 1744 AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */ 1745 AT_ReAddConstraint, /* internal to commands/tablecmds.c */ 1746 AT_ReAddDomainConstraint, /* internal to commands/tablecmds.c */ 1747 AT_AlterConstraint, /* alter constraint */ 1748 AT_ValidateConstraint, /* validate constraint */ 1749 AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */ 1750 AT_ProcessedConstraint, /* pre-processed add constraint (local in 1751 * parser/parse_utilcmd.c) */ 1752 AT_AddIndexConstraint, /* add constraint using existing index */ 1753 AT_DropConstraint, /* drop constraint */ 1754 AT_DropConstraintRecurse, /* internal to commands/tablecmds.c */ 1755 AT_ReAddComment, /* internal to commands/tablecmds.c */ 1756 AT_AlterColumnType, /* alter column type */ 1757 AT_AlterColumnGenericOptions, /* alter column OPTIONS (...) */ 1758 AT_ChangeOwner, /* change owner */ 1759 AT_ClusterOn, /* CLUSTER ON */ 1760 AT_DropCluster, /* SET WITHOUT CLUSTER */ 1761 AT_SetLogged, /* SET LOGGED */ 1762 AT_SetUnLogged, /* SET UNLOGGED */ 1763 AT_AddOids, /* SET WITH OIDS */ 1764 AT_AddOidsRecurse, /* internal to commands/tablecmds.c */ 1765 AT_DropOids, /* SET WITHOUT OIDS */ 1766 AT_SetTableSpace, /* SET TABLESPACE */ 1767 AT_SetRelOptions, /* SET (...) -- AM specific parameters */ 1768 AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */ 1769 AT_ReplaceRelOptions, /* replace reloption list in its entirety */ 1770 AT_EnableTrig, /* ENABLE TRIGGER name */ 1771 AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */ 1772 AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */ 1773 AT_DisableTrig, /* DISABLE TRIGGER name */ 1774 AT_EnableTrigAll, /* ENABLE TRIGGER ALL */ 1775 AT_DisableTrigAll, /* DISABLE TRIGGER ALL */ 1776 AT_EnableTrigUser, /* ENABLE TRIGGER USER */ 1777 AT_DisableTrigUser, /* DISABLE TRIGGER USER */ 1778 AT_EnableRule, /* ENABLE RULE name */ 1779 AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */ 1780 AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */ 1781 AT_DisableRule, /* DISABLE RULE name */ 1782 AT_AddInherit, /* INHERIT parent */ 1783 AT_DropInherit, /* NO INHERIT parent */ 1784 AT_AddOf, /* OF <type_name> */ 1785 AT_DropOf, /* NOT OF */ 1786 AT_ReplicaIdentity, /* REPLICA IDENTITY */ 1787 AT_EnableRowSecurity, /* ENABLE ROW SECURITY */ 1788 AT_DisableRowSecurity, /* DISABLE ROW SECURITY */ 1789 AT_ForceRowSecurity, /* FORCE ROW SECURITY */ 1790 AT_NoForceRowSecurity, /* NO FORCE ROW SECURITY */ 1791 AT_GenericOptions, /* OPTIONS (...) */ 1792 AT_AttachPartition, /* ATTACH PARTITION */ 1793 AT_DetachPartition, /* DETACH PARTITION */ 1794 AT_AddIdentity, /* ADD IDENTITY */ 1795 AT_SetIdentity, /* SET identity column options */ 1796 AT_DropIdentity /* DROP IDENTITY */ 1797 } AlterTableType; 1798 1799 typedef struct ReplicaIdentityStmt 1800 { 1801 NodeTag type; 1802 char identity_type; 1803 char *name; 1804 } ReplicaIdentityStmt; 1805 1806 typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */ 1807 { 1808 NodeTag type; 1809 AlterTableType subtype; /* Type of table alteration to apply */ 1810 char *name; /* column, constraint, or trigger to act on, 1811 * or tablespace */ 1812 int16 num; /* attribute number for columns referenced by 1813 * number */ 1814 RoleSpec *newowner; 1815 Node *def; /* definition of new column, index, 1816 * constraint, or parent table */ 1817 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ 1818 bool missing_ok; /* skip error if missing? */ 1819 } AlterTableCmd; 1820 1821 1822 /* ---------------------- 1823 * Alter Collation 1824 * ---------------------- 1825 */ 1826 typedef struct AlterCollationStmt 1827 { 1828 NodeTag type; 1829 List *collname; 1830 } AlterCollationStmt; 1831 1832 1833 /* ---------------------- 1834 * Alter Domain 1835 * 1836 * The fields are used in different ways by the different variants of 1837 * this command. 1838 * ---------------------- 1839 */ 1840 typedef struct AlterDomainStmt 1841 { 1842 NodeTag type; 1843 char subtype; /*------------ 1844 * T = alter column default 1845 * N = alter column drop not null 1846 * O = alter column set not null 1847 * C = add constraint 1848 * X = drop constraint 1849 *------------ 1850 */ 1851 List *typeName; /* domain to work on */ 1852 char *name; /* column or constraint name to act on */ 1853 Node *def; /* definition of default or constraint */ 1854 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ 1855 bool missing_ok; /* skip error if missing? */ 1856 } AlterDomainStmt; 1857 1858 1859 /* ---------------------- 1860 * Grant|Revoke Statement 1861 * ---------------------- 1862 */ 1863 typedef enum GrantTargetType 1864 { 1865 ACL_TARGET_OBJECT, /* grant on specific named object(s) */ 1866 ACL_TARGET_ALL_IN_SCHEMA, /* grant on all objects in given schema(s) */ 1867 ACL_TARGET_DEFAULTS /* ALTER DEFAULT PRIVILEGES */ 1868 } GrantTargetType; 1869 1870 typedef struct GrantStmt 1871 { 1872 NodeTag type; 1873 bool is_grant; /* true = GRANT, false = REVOKE */ 1874 GrantTargetType targtype; /* type of the grant target */ 1875 ObjectType objtype; /* kind of object being operated on */ 1876 List *objects; /* list of RangeVar nodes, ObjectWithArgs 1877 * nodes, or plain names (as Value strings) */ 1878 List *privileges; /* list of AccessPriv nodes */ 1879 /* privileges == NIL denotes ALL PRIVILEGES */ 1880 List *grantees; /* list of RoleSpec nodes */ 1881 bool grant_option; /* grant or revoke grant option */ 1882 DropBehavior behavior; /* drop behavior (for REVOKE) */ 1883 } GrantStmt; 1884 1885 /* 1886 * Note: ObjectWithArgs carries only the types of the input parameters of the 1887 * function. So it is sufficient to identify an existing function, but it 1888 * is not enough info to define a function nor to call it. 1889 */ 1890 typedef struct ObjectWithArgs 1891 { 1892 NodeTag type; 1893 List *objname; /* qualified name of function/operator */ 1894 List *objargs; /* list of Typename nodes */ 1895 bool args_unspecified; /* argument list was omitted, so name must 1896 * be unique (note that objargs == NIL 1897 * means zero args) */ 1898 } ObjectWithArgs; 1899 1900 /* 1901 * An access privilege, with optional list of column names 1902 * priv_name == NULL denotes ALL PRIVILEGES (only used with a column list) 1903 * cols == NIL denotes "all columns" 1904 * Note that simple "ALL PRIVILEGES" is represented as a NIL list, not 1905 * an AccessPriv with both fields null. 1906 */ 1907 typedef struct AccessPriv 1908 { 1909 NodeTag type; 1910 char *priv_name; /* string name of privilege */ 1911 List *cols; /* list of Value strings */ 1912 } AccessPriv; 1913 1914 /* ---------------------- 1915 * Grant/Revoke Role Statement 1916 * 1917 * Note: because of the parsing ambiguity with the GRANT <privileges> 1918 * statement, granted_roles is a list of AccessPriv; the execution code 1919 * should complain if any column lists appear. grantee_roles is a list 1920 * of role names, as Value strings. 1921 * ---------------------- 1922 */ 1923 typedef struct GrantRoleStmt 1924 { 1925 NodeTag type; 1926 List *granted_roles; /* list of roles to be granted/revoked */ 1927 List *grantee_roles; /* list of member roles to add/delete */ 1928 bool is_grant; /* true = GRANT, false = REVOKE */ 1929 bool admin_opt; /* with admin option */ 1930 RoleSpec *grantor; /* set grantor to other than current role */ 1931 DropBehavior behavior; /* drop behavior (for REVOKE) */ 1932 } GrantRoleStmt; 1933 1934 /* ---------------------- 1935 * Alter Default Privileges Statement 1936 * ---------------------- 1937 */ 1938 typedef struct AlterDefaultPrivilegesStmt 1939 { 1940 NodeTag type; 1941 List *options; /* list of DefElem */ 1942 GrantStmt *action; /* GRANT/REVOKE action (with objects=NIL) */ 1943 } AlterDefaultPrivilegesStmt; 1944 1945 /* ---------------------- 1946 * Copy Statement 1947 * 1948 * We support "COPY relation FROM file", "COPY relation TO file", and 1949 * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation" 1950 * and "query" must be non-NULL. 1951 * ---------------------- 1952 */ 1953 typedef struct CopyStmt 1954 { 1955 NodeTag type; 1956 RangeVar *relation; /* the relation to copy */ 1957 Node *query; /* the query (SELECT or DML statement with 1958 * RETURNING) to copy, as a raw parse tree */ 1959 List *attlist; /* List of column names (as Strings), or NIL 1960 * for all columns */ 1961 bool is_from; /* TO or FROM */ 1962 bool is_program; /* is 'filename' a program to popen? */ 1963 char *filename; /* filename, or NULL for STDIN/STDOUT */ 1964 List *options; /* List of DefElem nodes */ 1965 } CopyStmt; 1966 1967 /* ---------------------- 1968 * SET Statement (includes RESET) 1969 * 1970 * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we 1971 * preserve the distinction in VariableSetKind for CreateCommandTag(). 1972 * ---------------------- 1973 */ 1974 typedef enum 1975 { 1976 VAR_SET_VALUE, /* SET var = value */ 1977 VAR_SET_DEFAULT, /* SET var TO DEFAULT */ 1978 VAR_SET_CURRENT, /* SET var FROM CURRENT */ 1979 VAR_SET_MULTI, /* special case for SET TRANSACTION ... */ 1980 VAR_RESET, /* RESET var */ 1981 VAR_RESET_ALL /* RESET ALL */ 1982 } VariableSetKind; 1983 1984 typedef struct VariableSetStmt 1985 { 1986 NodeTag type; 1987 VariableSetKind kind; 1988 char *name; /* variable to be set */ 1989 List *args; /* List of A_Const nodes */ 1990 bool is_local; /* SET LOCAL? */ 1991 } VariableSetStmt; 1992 1993 /* ---------------------- 1994 * Show Statement 1995 * ---------------------- 1996 */ 1997 typedef struct VariableShowStmt 1998 { 1999 NodeTag type; 2000 char *name; 2001 } VariableShowStmt; 2002 2003 /* ---------------------- 2004 * Create Table Statement 2005 * 2006 * NOTE: in the raw gram.y output, ColumnDef and Constraint nodes are 2007 * intermixed in tableElts, and constraints is NIL. After parse analysis, 2008 * tableElts contains just ColumnDefs, and constraints contains just 2009 * Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present 2010 * implementation). 2011 * ---------------------- 2012 */ 2013 2014 typedef struct CreateStmt 2015 { 2016 NodeTag type; 2017 RangeVar *relation; /* relation to create */ 2018 List *tableElts; /* column definitions (list of ColumnDef) */ 2019 List *inhRelations; /* relations to inherit from (list of 2020 * inhRelation) */ 2021 PartitionBoundSpec *partbound; /* FOR VALUES clause */ 2022 PartitionSpec *partspec; /* PARTITION BY clause */ 2023 TypeName *ofTypename; /* OF typename */ 2024 List *constraints; /* constraints (list of Constraint nodes) */ 2025 List *options; /* options from WITH clause */ 2026 OnCommitAction oncommit; /* what do we do at COMMIT? */ 2027 char *tablespacename; /* table space to use, or NULL */ 2028 bool if_not_exists; /* just do nothing if it already exists? */ 2029 } CreateStmt; 2030 2031 /* ---------- 2032 * Definitions for constraints in CreateStmt 2033 * 2034 * Note that column defaults are treated as a type of constraint, 2035 * even though that's a bit odd semantically. 2036 * 2037 * For constraints that use expressions (CONSTR_CHECK, CONSTR_DEFAULT) 2038 * we may have the expression in either "raw" form (an untransformed 2039 * parse tree) or "cooked" form (the nodeToString representation of 2040 * an executable expression tree), depending on how this Constraint 2041 * node was created (by parsing, or by inheritance from an existing 2042 * relation). We should never have both in the same node! 2043 * 2044 * FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype 2045 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are 2046 * stored into pg_constraint.confmatchtype. Changing the code values may 2047 * require an initdb! 2048 * 2049 * If skip_validation is true then we skip checking that the existing rows 2050 * in the table satisfy the constraint, and just install the catalog entries 2051 * for the constraint. A new FK constraint is marked as valid iff 2052 * initially_valid is true. (Usually skip_validation and initially_valid 2053 * are inverses, but we can set both true if the table is known empty.) 2054 * 2055 * Constraint attributes (DEFERRABLE etc) are initially represented as 2056 * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes 2057 * a pass through the constraints list to insert the info into the appropriate 2058 * Constraint node. 2059 * ---------- 2060 */ 2061 2062 typedef enum ConstrType /* types of constraints */ 2063 { 2064 CONSTR_NULL, /* not standard SQL, but a lot of people 2065 * expect it */ 2066 CONSTR_NOTNULL, 2067 CONSTR_DEFAULT, 2068 CONSTR_IDENTITY, 2069 CONSTR_CHECK, 2070 CONSTR_PRIMARY, 2071 CONSTR_UNIQUE, 2072 CONSTR_EXCLUSION, 2073 CONSTR_FOREIGN, 2074 CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */ 2075 CONSTR_ATTR_NOT_DEFERRABLE, 2076 CONSTR_ATTR_DEFERRED, 2077 CONSTR_ATTR_IMMEDIATE 2078 } ConstrType; 2079 2080 /* Foreign key action codes */ 2081 #define FKCONSTR_ACTION_NOACTION 'a' 2082 #define FKCONSTR_ACTION_RESTRICT 'r' 2083 #define FKCONSTR_ACTION_CASCADE 'c' 2084 #define FKCONSTR_ACTION_SETNULL 'n' 2085 #define FKCONSTR_ACTION_SETDEFAULT 'd' 2086 2087 /* Foreign key matchtype codes */ 2088 #define FKCONSTR_MATCH_FULL 'f' 2089 #define FKCONSTR_MATCH_PARTIAL 'p' 2090 #define FKCONSTR_MATCH_SIMPLE 's' 2091 2092 typedef struct Constraint 2093 { 2094 NodeTag type; 2095 ConstrType contype; /* see above */ 2096 2097 /* Fields used for most/all constraint types: */ 2098 char *conname; /* Constraint name, or NULL if unnamed */ 2099 bool deferrable; /* DEFERRABLE? */ 2100 bool initdeferred; /* INITIALLY DEFERRED? */ 2101 int location; /* token location, or -1 if unknown */ 2102 2103 /* Fields used for constraints with expressions (CHECK and DEFAULT): */ 2104 bool is_no_inherit; /* is constraint non-inheritable? */ 2105 Node *raw_expr; /* expr, as untransformed parse tree */ 2106 char *cooked_expr; /* expr, as nodeToString representation */ 2107 char generated_when; 2108 2109 /* Fields used for unique constraints (UNIQUE and PRIMARY KEY): */ 2110 List *keys; /* String nodes naming referenced key 2111 * column(s) */ 2112 List *including; /* String nodes naming referenced nonkey 2113 * column(s) */ 2114 2115 /* Fields used for EXCLUSION constraints: */ 2116 List *exclusions; /* list of (IndexElem, operator name) pairs */ 2117 2118 /* Fields used for index constraints (UNIQUE, PRIMARY KEY, EXCLUSION): */ 2119 List *options; /* options from WITH clause */ 2120 char *indexname; /* existing index to use; otherwise NULL */ 2121 char *indexspace; /* index tablespace; NULL for default */ 2122 /* These could be, but currently are not, used for UNIQUE/PKEY: */ 2123 char *access_method; /* index access method; NULL for default */ 2124 Node *where_clause; /* partial index predicate */ 2125 2126 /* Fields used for FOREIGN KEY constraints: */ 2127 RangeVar *pktable; /* Primary key table */ 2128 List *fk_attrs; /* Attributes of foreign key */ 2129 List *pk_attrs; /* Corresponding attrs in PK table */ 2130 char fk_matchtype; /* FULL, PARTIAL, SIMPLE */ 2131 char fk_upd_action; /* ON UPDATE action */ 2132 char fk_del_action; /* ON DELETE action */ 2133 List *old_conpfeqop; /* pg_constraint.conpfeqop of my former self */ 2134 Oid old_pktable_oid; /* pg_constraint.confrelid of my former 2135 * self */ 2136 2137 /* Fields used for constraints that allow a NOT VALID specification */ 2138 bool skip_validation; /* skip validation of existing rows? */ 2139 bool initially_valid; /* mark the new constraint as valid? */ 2140 } Constraint; 2141 2142 /* ---------------------- 2143 * Create/Drop Table Space Statements 2144 * ---------------------- 2145 */ 2146 2147 typedef struct CreateTableSpaceStmt 2148 { 2149 NodeTag type; 2150 char *tablespacename; 2151 RoleSpec *owner; 2152 char *location; 2153 List *options; 2154 } CreateTableSpaceStmt; 2155 2156 typedef struct DropTableSpaceStmt 2157 { 2158 NodeTag type; 2159 char *tablespacename; 2160 bool missing_ok; /* skip error if missing? */ 2161 } DropTableSpaceStmt; 2162 2163 typedef struct AlterTableSpaceOptionsStmt 2164 { 2165 NodeTag type; 2166 char *tablespacename; 2167 List *options; 2168 bool isReset; 2169 } AlterTableSpaceOptionsStmt; 2170 2171 typedef struct AlterTableMoveAllStmt 2172 { 2173 NodeTag type; 2174 char *orig_tablespacename; 2175 ObjectType objtype; /* Object type to move */ 2176 List *roles; /* List of roles to move objects of */ 2177 char *new_tablespacename; 2178 bool nowait; 2179 } AlterTableMoveAllStmt; 2180 2181 /* ---------------------- 2182 * Create/Alter Extension Statements 2183 * ---------------------- 2184 */ 2185 2186 typedef struct CreateExtensionStmt 2187 { 2188 NodeTag type; 2189 char *extname; 2190 bool if_not_exists; /* just do nothing if it already exists? */ 2191 List *options; /* List of DefElem nodes */ 2192 } CreateExtensionStmt; 2193 2194 /* Only used for ALTER EXTENSION UPDATE; later might need an action field */ 2195 typedef struct AlterExtensionStmt 2196 { 2197 NodeTag type; 2198 char *extname; 2199 List *options; /* List of DefElem nodes */ 2200 } AlterExtensionStmt; 2201 2202 typedef struct AlterExtensionContentsStmt 2203 { 2204 NodeTag type; 2205 char *extname; /* Extension's name */ 2206 int action; /* +1 = add object, -1 = drop object */ 2207 ObjectType objtype; /* Object's type */ 2208 Node *object; /* Qualified name of the object */ 2209 } AlterExtensionContentsStmt; 2210 2211 /* ---------------------- 2212 * Create/Alter FOREIGN DATA WRAPPER Statements 2213 * ---------------------- 2214 */ 2215 2216 typedef struct CreateFdwStmt 2217 { 2218 NodeTag type; 2219 char *fdwname; /* foreign-data wrapper name */ 2220 List *func_options; /* HANDLER/VALIDATOR options */ 2221 List *options; /* generic options to FDW */ 2222 } CreateFdwStmt; 2223 2224 typedef struct AlterFdwStmt 2225 { 2226 NodeTag type; 2227 char *fdwname; /* foreign-data wrapper name */ 2228 List *func_options; /* HANDLER/VALIDATOR options */ 2229 List *options; /* generic options to FDW */ 2230 } AlterFdwStmt; 2231 2232 /* ---------------------- 2233 * Create/Alter FOREIGN SERVER Statements 2234 * ---------------------- 2235 */ 2236 2237 typedef struct CreateForeignServerStmt 2238 { 2239 NodeTag type; 2240 char *servername; /* server name */ 2241 char *servertype; /* optional server type */ 2242 char *version; /* optional server version */ 2243 char *fdwname; /* FDW name */ 2244 bool if_not_exists; /* just do nothing if it already exists? */ 2245 List *options; /* generic options to server */ 2246 } CreateForeignServerStmt; 2247 2248 typedef struct AlterForeignServerStmt 2249 { 2250 NodeTag type; 2251 char *servername; /* server name */ 2252 char *version; /* optional server version */ 2253 List *options; /* generic options to server */ 2254 bool has_version; /* version specified */ 2255 } AlterForeignServerStmt; 2256 2257 /* ---------------------- 2258 * Create FOREIGN TABLE Statement 2259 * ---------------------- 2260 */ 2261 2262 typedef struct CreateForeignTableStmt 2263 { 2264 CreateStmt base; 2265 char *servername; 2266 List *options; 2267 } CreateForeignTableStmt; 2268 2269 /* ---------------------- 2270 * Create/Drop USER MAPPING Statements 2271 * ---------------------- 2272 */ 2273 2274 typedef struct CreateUserMappingStmt 2275 { 2276 NodeTag type; 2277 RoleSpec *user; /* user role */ 2278 char *servername; /* server name */ 2279 bool if_not_exists; /* just do nothing if it already exists? */ 2280 List *options; /* generic options to server */ 2281 } CreateUserMappingStmt; 2282 2283 typedef struct AlterUserMappingStmt 2284 { 2285 NodeTag type; 2286 RoleSpec *user; /* user role */ 2287 char *servername; /* server name */ 2288 List *options; /* generic options to server */ 2289 } AlterUserMappingStmt; 2290 2291 typedef struct DropUserMappingStmt 2292 { 2293 NodeTag type; 2294 RoleSpec *user; /* user role */ 2295 char *servername; /* server name */ 2296 bool missing_ok; /* ignore missing mappings */ 2297 } DropUserMappingStmt; 2298 2299 /* ---------------------- 2300 * Import Foreign Schema Statement 2301 * ---------------------- 2302 */ 2303 2304 typedef enum ImportForeignSchemaType 2305 { 2306 FDW_IMPORT_SCHEMA_ALL, /* all relations wanted */ 2307 FDW_IMPORT_SCHEMA_LIMIT_TO, /* include only listed tables in import */ 2308 FDW_IMPORT_SCHEMA_EXCEPT /* exclude listed tables from import */ 2309 } ImportForeignSchemaType; 2310 2311 typedef struct ImportForeignSchemaStmt 2312 { 2313 NodeTag type; 2314 char *server_name; /* FDW server name */ 2315 char *remote_schema; /* remote schema name to query */ 2316 char *local_schema; /* local schema to create objects in */ 2317 ImportForeignSchemaType list_type; /* type of table list */ 2318 List *table_list; /* List of RangeVar */ 2319 List *options; /* list of options to pass to FDW */ 2320 } ImportForeignSchemaStmt; 2321 2322 /*---------------------- 2323 * Create POLICY Statement 2324 *---------------------- 2325 */ 2326 typedef struct CreatePolicyStmt 2327 { 2328 NodeTag type; 2329 char *policy_name; /* Policy's name */ 2330 RangeVar *table; /* the table name the policy applies to */ 2331 char *cmd_name; /* the command name the policy applies to */ 2332 bool permissive; /* restrictive or permissive policy */ 2333 List *roles; /* the roles associated with the policy */ 2334 Node *qual; /* the policy's condition */ 2335 Node *with_check; /* the policy's WITH CHECK condition. */ 2336 } CreatePolicyStmt; 2337 2338 /*---------------------- 2339 * Alter POLICY Statement 2340 *---------------------- 2341 */ 2342 typedef struct AlterPolicyStmt 2343 { 2344 NodeTag type; 2345 char *policy_name; /* Policy's name */ 2346 RangeVar *table; /* the table name the policy applies to */ 2347 List *roles; /* the roles associated with the policy */ 2348 Node *qual; /* the policy's condition */ 2349 Node *with_check; /* the policy's WITH CHECK condition. */ 2350 } AlterPolicyStmt; 2351 2352 /*---------------------- 2353 * Create ACCESS METHOD Statement 2354 *---------------------- 2355 */ 2356 typedef struct CreateAmStmt 2357 { 2358 NodeTag type; 2359 char *amname; /* access method name */ 2360 List *handler_name; /* handler function name */ 2361 char amtype; /* type of access method */ 2362 } CreateAmStmt; 2363 2364 /* ---------------------- 2365 * Create TRIGGER Statement 2366 * ---------------------- 2367 */ 2368 typedef struct CreateTrigStmt 2369 { 2370 NodeTag type; 2371 char *trigname; /* TRIGGER's name */ 2372 RangeVar *relation; /* relation trigger is on */ 2373 List *funcname; /* qual. name of function to call */ 2374 List *args; /* list of (T_String) Values or NIL */ 2375 bool row; /* ROW/STATEMENT */ 2376 /* timing uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */ 2377 int16 timing; /* BEFORE, AFTER, or INSTEAD */ 2378 /* events uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */ 2379 int16 events; /* "OR" of INSERT/UPDATE/DELETE/TRUNCATE */ 2380 List *columns; /* column names, or NIL for all columns */ 2381 Node *whenClause; /* qual expression, or NULL if none */ 2382 bool isconstraint; /* This is a constraint trigger */ 2383 /* explicitly named transition data */ 2384 List *transitionRels; /* TriggerTransition nodes, or NIL if none */ 2385 /* The remaining fields are only used for constraint triggers */ 2386 bool deferrable; /* [NOT] DEFERRABLE */ 2387 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */ 2388 RangeVar *constrrel; /* opposite relation, if RI trigger */ 2389 } CreateTrigStmt; 2390 2391 /* ---------------------- 2392 * Create EVENT TRIGGER Statement 2393 * ---------------------- 2394 */ 2395 typedef struct CreateEventTrigStmt 2396 { 2397 NodeTag type; 2398 char *trigname; /* TRIGGER's name */ 2399 char *eventname; /* event's identifier */ 2400 List *whenclause; /* list of DefElems indicating filtering */ 2401 List *funcname; /* qual. name of function to call */ 2402 } CreateEventTrigStmt; 2403 2404 /* ---------------------- 2405 * Alter EVENT TRIGGER Statement 2406 * ---------------------- 2407 */ 2408 typedef struct AlterEventTrigStmt 2409 { 2410 NodeTag type; 2411 char *trigname; /* TRIGGER's name */ 2412 char tgenabled; /* trigger's firing configuration WRT 2413 * session_replication_role */ 2414 } AlterEventTrigStmt; 2415 2416 /* ---------------------- 2417 * Create/Drop PROCEDURAL LANGUAGE Statements 2418 * Create PROCEDURAL LANGUAGE Statements 2419 * ---------------------- 2420 */ 2421 typedef struct CreatePLangStmt 2422 { 2423 NodeTag type; 2424 bool replace; /* T => replace if already exists */ 2425 char *plname; /* PL name */ 2426 List *plhandler; /* PL call handler function (qual. name) */ 2427 List *plinline; /* optional inline function (qual. name) */ 2428 List *plvalidator; /* optional validator function (qual. name) */ 2429 bool pltrusted; /* PL is trusted */ 2430 } CreatePLangStmt; 2431 2432 /* ---------------------- 2433 * Create/Alter/Drop Role Statements 2434 * 2435 * Note: these node types are also used for the backwards-compatible 2436 * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases 2437 * there's really no need to distinguish what the original spelling was, 2438 * but for CREATE we mark the type because the defaults vary. 2439 * ---------------------- 2440 */ 2441 typedef enum RoleStmtType 2442 { 2443 ROLESTMT_ROLE, 2444 ROLESTMT_USER, 2445 ROLESTMT_GROUP 2446 } RoleStmtType; 2447 2448 typedef struct CreateRoleStmt 2449 { 2450 NodeTag type; 2451 RoleStmtType stmt_type; /* ROLE/USER/GROUP */ 2452 char *role; /* role name */ 2453 List *options; /* List of DefElem nodes */ 2454 } CreateRoleStmt; 2455 2456 typedef struct AlterRoleStmt 2457 { 2458 NodeTag type; 2459 RoleSpec *role; /* role */ 2460 List *options; /* List of DefElem nodes */ 2461 int action; /* +1 = add members, -1 = drop members */ 2462 } AlterRoleStmt; 2463 2464 typedef struct AlterRoleSetStmt 2465 { 2466 NodeTag type; 2467 RoleSpec *role; /* role */ 2468 char *database; /* database name, or NULL */ 2469 VariableSetStmt *setstmt; /* SET or RESET subcommand */ 2470 } AlterRoleSetStmt; 2471 2472 typedef struct DropRoleStmt 2473 { 2474 NodeTag type; 2475 List *roles; /* List of roles to remove */ 2476 bool missing_ok; /* skip error if a role is missing? */ 2477 } DropRoleStmt; 2478 2479 /* ---------------------- 2480 * {Create|Alter} SEQUENCE Statement 2481 * ---------------------- 2482 */ 2483 2484 typedef struct CreateSeqStmt 2485 { 2486 NodeTag type; 2487 RangeVar *sequence; /* the sequence to create */ 2488 List *options; 2489 Oid ownerId; /* ID of owner, or InvalidOid for default */ 2490 bool for_identity; 2491 bool if_not_exists; /* just do nothing if it already exists? */ 2492 } CreateSeqStmt; 2493 2494 typedef struct AlterSeqStmt 2495 { 2496 NodeTag type; 2497 RangeVar *sequence; /* the sequence to alter */ 2498 List *options; 2499 bool for_identity; 2500 bool missing_ok; /* skip error if a role is missing? */ 2501 } AlterSeqStmt; 2502 2503 /* ---------------------- 2504 * Create {Aggregate|Operator|Type} Statement 2505 * ---------------------- 2506 */ 2507 typedef struct DefineStmt 2508 { 2509 NodeTag type; 2510 ObjectType kind; /* aggregate, operator, type */ 2511 bool oldstyle; /* hack to signal old CREATE AGG syntax */ 2512 List *defnames; /* qualified name (list of Value strings) */ 2513 List *args; /* a list of TypeName (if needed) */ 2514 List *definition; /* a list of DefElem */ 2515 bool if_not_exists; /* just do nothing if it already exists? */ 2516 } DefineStmt; 2517 2518 /* ---------------------- 2519 * Create Domain Statement 2520 * ---------------------- 2521 */ 2522 typedef struct CreateDomainStmt 2523 { 2524 NodeTag type; 2525 List *domainname; /* qualified name (list of Value strings) */ 2526 TypeName *typeName; /* the base type */ 2527 CollateClause *collClause; /* untransformed COLLATE spec, if any */ 2528 List *constraints; /* constraints (list of Constraint nodes) */ 2529 } CreateDomainStmt; 2530 2531 /* ---------------------- 2532 * Create Operator Class Statement 2533 * ---------------------- 2534 */ 2535 typedef struct CreateOpClassStmt 2536 { 2537 NodeTag type; 2538 List *opclassname; /* qualified name (list of Value strings) */ 2539 List *opfamilyname; /* qualified name (ditto); NIL if omitted */ 2540 char *amname; /* name of index AM opclass is for */ 2541 TypeName *datatype; /* datatype of indexed column */ 2542 List *items; /* List of CreateOpClassItem nodes */ 2543 bool isDefault; /* Should be marked as default for type? */ 2544 } CreateOpClassStmt; 2545 2546 #define OPCLASS_ITEM_OPERATOR 1 2547 #define OPCLASS_ITEM_FUNCTION 2 2548 #define OPCLASS_ITEM_STORAGETYPE 3 2549 2550 typedef struct CreateOpClassItem 2551 { 2552 NodeTag type; 2553 int itemtype; /* see codes above */ 2554 ObjectWithArgs *name; /* operator or function name and args */ 2555 int number; /* strategy num or support proc num */ 2556 List *order_family; /* only used for ordering operators */ 2557 List *class_args; /* amproclefttype/amprocrighttype or 2558 * amoplefttype/amoprighttype */ 2559 /* fields used for a storagetype item: */ 2560 TypeName *storedtype; /* datatype stored in index */ 2561 } CreateOpClassItem; 2562 2563 /* ---------------------- 2564 * Create Operator Family Statement 2565 * ---------------------- 2566 */ 2567 typedef struct CreateOpFamilyStmt 2568 { 2569 NodeTag type; 2570 List *opfamilyname; /* qualified name (list of Value strings) */ 2571 char *amname; /* name of index AM opfamily is for */ 2572 } CreateOpFamilyStmt; 2573 2574 /* ---------------------- 2575 * Alter Operator Family Statement 2576 * ---------------------- 2577 */ 2578 typedef struct AlterOpFamilyStmt 2579 { 2580 NodeTag type; 2581 List *opfamilyname; /* qualified name (list of Value strings) */ 2582 char *amname; /* name of index AM opfamily is for */ 2583 bool isDrop; /* ADD or DROP the items? */ 2584 List *items; /* List of CreateOpClassItem nodes */ 2585 } AlterOpFamilyStmt; 2586 2587 /* ---------------------- 2588 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement 2589 * ---------------------- 2590 */ 2591 2592 typedef struct DropStmt 2593 { 2594 NodeTag type; 2595 List *objects; /* list of names */ 2596 ObjectType removeType; /* object type */ 2597 DropBehavior behavior; /* RESTRICT or CASCADE behavior */ 2598 bool missing_ok; /* skip error if object is missing? */ 2599 bool concurrent; /* drop index concurrently? */ 2600 } DropStmt; 2601 2602 /* ---------------------- 2603 * Truncate Table Statement 2604 * ---------------------- 2605 */ 2606 typedef struct TruncateStmt 2607 { 2608 NodeTag type; 2609 List *relations; /* relations (RangeVars) to be truncated */ 2610 bool restart_seqs; /* restart owned sequences? */ 2611 DropBehavior behavior; /* RESTRICT or CASCADE behavior */ 2612 } TruncateStmt; 2613 2614 /* ---------------------- 2615 * Comment On Statement 2616 * ---------------------- 2617 */ 2618 typedef struct CommentStmt 2619 { 2620 NodeTag type; 2621 ObjectType objtype; /* Object's type */ 2622 Node *object; /* Qualified name of the object */ 2623 char *comment; /* Comment to insert, or NULL to remove */ 2624 } CommentStmt; 2625 2626 /* ---------------------- 2627 * SECURITY LABEL Statement 2628 * ---------------------- 2629 */ 2630 typedef struct SecLabelStmt 2631 { 2632 NodeTag type; 2633 ObjectType objtype; /* Object's type */ 2634 Node *object; /* Qualified name of the object */ 2635 char *provider; /* Label provider (or NULL) */ 2636 char *label; /* New security label to be assigned */ 2637 } SecLabelStmt; 2638 2639 /* ---------------------- 2640 * Declare Cursor Statement 2641 * 2642 * The "query" field is initially a raw parse tree, and is converted to a 2643 * Query node during parse analysis. Note that rewriting and planning 2644 * of the query are always postponed until execution. 2645 * ---------------------- 2646 */ 2647 #define CURSOR_OPT_BINARY 0x0001 /* BINARY */ 2648 #define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */ 2649 #define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */ 2650 #define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */ 2651 #define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */ 2652 /* these planner-control flags do not correspond to any SQL grammar: */ 2653 #define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */ 2654 #define CURSOR_OPT_GENERIC_PLAN 0x0040 /* force use of generic plan */ 2655 #define CURSOR_OPT_CUSTOM_PLAN 0x0080 /* force use of custom plan */ 2656 #define CURSOR_OPT_PARALLEL_OK 0x0100 /* parallel mode OK */ 2657 2658 typedef struct DeclareCursorStmt 2659 { 2660 NodeTag type; 2661 char *portalname; /* name of the portal (cursor) */ 2662 int options; /* bitmask of options (see above) */ 2663 Node *query; /* the query (see comments above) */ 2664 } DeclareCursorStmt; 2665 2666 /* ---------------------- 2667 * Close Portal Statement 2668 * ---------------------- 2669 */ 2670 typedef struct ClosePortalStmt 2671 { 2672 NodeTag type; 2673 char *portalname; /* name of the portal (cursor) */ 2674 /* NULL means CLOSE ALL */ 2675 } ClosePortalStmt; 2676 2677 /* ---------------------- 2678 * Fetch Statement (also Move) 2679 * ---------------------- 2680 */ 2681 typedef enum FetchDirection 2682 { 2683 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */ 2684 FETCH_FORWARD, 2685 FETCH_BACKWARD, 2686 /* for these, howMany indicates a position; only one row is fetched */ 2687 FETCH_ABSOLUTE, 2688 FETCH_RELATIVE 2689 } FetchDirection; 2690 2691 #define FETCH_ALL LONG_MAX 2692 2693 typedef struct FetchStmt 2694 { 2695 NodeTag type; 2696 FetchDirection direction; /* see above */ 2697 long howMany; /* number of rows, or position argument */ 2698 char *portalname; /* name of portal (cursor) */ 2699 bool ismove; /* true if MOVE */ 2700 } FetchStmt; 2701 2702 /* ---------------------- 2703 * Create Index Statement 2704 * 2705 * This represents creation of an index and/or an associated constraint. 2706 * If isconstraint is true, we should create a pg_constraint entry along 2707 * with the index. But if indexOid isn't InvalidOid, we are not creating an 2708 * index, just a UNIQUE/PKEY constraint using an existing index. isconstraint 2709 * must always be true in this case, and the fields describing the index 2710 * properties are empty. 2711 * 2712 * The relation to build the index on can be represented either by name 2713 * (in which case the RangeVar indicates whether to recurse or not) or by OID 2714 * (in which case the command is always recursive). 2715 * ---------------------- 2716 */ 2717 typedef struct IndexStmt 2718 { 2719 NodeTag type; 2720 char *idxname; /* name of new index, or NULL for default */ 2721 RangeVar *relation; /* relation to build index on */ 2722 Oid relationId; /* OID of relation to build index on */ 2723 char *accessMethod; /* name of access method (eg. btree) */ 2724 char *tableSpace; /* tablespace, or NULL for default */ 2725 List *indexParams; /* columns to index: a list of IndexElem */ 2726 List *indexIncludingParams; /* additional columns to index: a list 2727 * of IndexElem */ 2728 List *options; /* WITH clause options: a list of DefElem */ 2729 Node *whereClause; /* qualification (partial-index predicate) */ 2730 List *excludeOpNames; /* exclusion operator names, or NIL if none */ 2731 char *idxcomment; /* comment to apply to index, or NULL */ 2732 Oid indexOid; /* OID of an existing index, if any */ 2733 Oid oldNode; /* relfilenode of existing storage, if any */ 2734 bool unique; /* is index unique? */ 2735 bool primary; /* is index a primary key? */ 2736 bool isconstraint; /* is it for a pkey/unique constraint? */ 2737 bool deferrable; /* is the constraint DEFERRABLE? */ 2738 bool initdeferred; /* is the constraint INITIALLY DEFERRED? */ 2739 bool transformed; /* true when transformIndexStmt is finished */ 2740 bool concurrent; /* should this be a concurrent index build? */ 2741 bool if_not_exists; /* just do nothing if index already exists? */ 2742 } IndexStmt; 2743 2744 /* ---------------------- 2745 * Create Statistics Statement 2746 * ---------------------- 2747 */ 2748 typedef struct CreateStatsStmt 2749 { 2750 NodeTag type; 2751 List *defnames; /* qualified name (list of Value strings) */ 2752 List *stat_types; /* stat types (list of Value strings) */ 2753 List *exprs; /* expressions to build statistics on */ 2754 List *relations; /* rels to build stats on (list of RangeVar) */ 2755 char *stxcomment; /* comment to apply to stats, or NULL */ 2756 bool if_not_exists; /* do nothing if stats name already exists */ 2757 } CreateStatsStmt; 2758 2759 /* ---------------------- 2760 * Create Function Statement 2761 * ---------------------- 2762 */ 2763 typedef struct CreateFunctionStmt 2764 { 2765 NodeTag type; 2766 bool is_procedure; /* it's really CREATE PROCEDURE */ 2767 bool replace; /* T => replace if already exists */ 2768 List *funcname; /* qualified name of function to create */ 2769 List *parameters; /* a list of FunctionParameter */ 2770 TypeName *returnType; /* the return type */ 2771 List *options; /* a list of DefElem */ 2772 } CreateFunctionStmt; 2773 2774 typedef enum FunctionParameterMode 2775 { 2776 /* the assigned enum values appear in pg_proc, don't change 'em! */ 2777 FUNC_PARAM_IN = 'i', /* input only */ 2778 FUNC_PARAM_OUT = 'o', /* output only */ 2779 FUNC_PARAM_INOUT = 'b', /* both */ 2780 FUNC_PARAM_VARIADIC = 'v', /* variadic (always input) */ 2781 FUNC_PARAM_TABLE = 't' /* table function output column */ 2782 } FunctionParameterMode; 2783 2784 typedef struct FunctionParameter 2785 { 2786 NodeTag type; 2787 char *name; /* parameter name, or NULL if not given */ 2788 TypeName *argType; /* TypeName for parameter type */ 2789 FunctionParameterMode mode; /* IN/OUT/etc */ 2790 Node *defexpr; /* raw default expr, or NULL if not given */ 2791 } FunctionParameter; 2792 2793 typedef struct AlterFunctionStmt 2794 { 2795 NodeTag type; 2796 ObjectType objtype; 2797 ObjectWithArgs *func; /* name and args of function */ 2798 List *actions; /* list of DefElem */ 2799 } AlterFunctionStmt; 2800 2801 /* ---------------------- 2802 * DO Statement 2803 * 2804 * DoStmt is the raw parser output, InlineCodeBlock is the execution-time API 2805 * ---------------------- 2806 */ 2807 typedef struct DoStmt 2808 { 2809 NodeTag type; 2810 List *args; /* List of DefElem nodes */ 2811 } DoStmt; 2812 2813 typedef struct InlineCodeBlock 2814 { 2815 NodeTag type; 2816 char *source_text; /* source text of anonymous code block */ 2817 Oid langOid; /* OID of selected language */ 2818 bool langIsTrusted; /* trusted property of the language */ 2819 bool atomic; /* atomic execution context */ 2820 } InlineCodeBlock; 2821 2822 /* ---------------------- 2823 * CALL statement 2824 * ---------------------- 2825 */ 2826 typedef struct CallStmt 2827 { 2828 NodeTag type; 2829 FuncCall *funccall; /* from the parser */ 2830 FuncExpr *funcexpr; /* transformed */ 2831 } CallStmt; 2832 2833 typedef struct CallContext 2834 { 2835 NodeTag type; 2836 bool atomic; 2837 } CallContext; 2838 2839 /* ---------------------- 2840 * Alter Object Rename Statement 2841 * ---------------------- 2842 */ 2843 typedef struct RenameStmt 2844 { 2845 NodeTag type; 2846 ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */ 2847 ObjectType relationType; /* if column name, associated relation type */ 2848 RangeVar *relation; /* in case it's a table */ 2849 Node *object; /* in case it's some other object */ 2850 char *subname; /* name of contained object (column, rule, 2851 * trigger, etc) */ 2852 char *newname; /* the new name */ 2853 DropBehavior behavior; /* RESTRICT or CASCADE behavior */ 2854 bool missing_ok; /* skip error if missing? */ 2855 } RenameStmt; 2856 2857 /* ---------------------- 2858 * ALTER object DEPENDS ON EXTENSION extname 2859 * ---------------------- 2860 */ 2861 typedef struct AlterObjectDependsStmt 2862 { 2863 NodeTag type; 2864 ObjectType objectType; /* OBJECT_FUNCTION, OBJECT_TRIGGER, etc */ 2865 RangeVar *relation; /* in case a table is involved */ 2866 Node *object; /* name of the object */ 2867 Value *extname; /* extension name */ 2868 } AlterObjectDependsStmt; 2869 2870 /* ---------------------- 2871 * ALTER object SET SCHEMA Statement 2872 * ---------------------- 2873 */ 2874 typedef struct AlterObjectSchemaStmt 2875 { 2876 NodeTag type; 2877 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */ 2878 RangeVar *relation; /* in case it's a table */ 2879 Node *object; /* in case it's some other object */ 2880 char *newschema; /* the new schema */ 2881 bool missing_ok; /* skip error if missing? */ 2882 } AlterObjectSchemaStmt; 2883 2884 /* ---------------------- 2885 * Alter Object Owner Statement 2886 * ---------------------- 2887 */ 2888 typedef struct AlterOwnerStmt 2889 { 2890 NodeTag type; 2891 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */ 2892 RangeVar *relation; /* in case it's a table */ 2893 Node *object; /* in case it's some other object */ 2894 RoleSpec *newowner; /* the new owner */ 2895 } AlterOwnerStmt; 2896 2897 2898 /* ---------------------- 2899 * Alter Operator Set Restrict, Join 2900 * ---------------------- 2901 */ 2902 typedef struct AlterOperatorStmt 2903 { 2904 NodeTag type; 2905 ObjectWithArgs *opername; /* operator name and argument types */ 2906 List *options; /* List of DefElem nodes */ 2907 } AlterOperatorStmt; 2908 2909 2910 /* ---------------------- 2911 * Create Rule Statement 2912 * ---------------------- 2913 */ 2914 typedef struct RuleStmt 2915 { 2916 NodeTag type; 2917 RangeVar *relation; /* relation the rule is for */ 2918 char *rulename; /* name of the rule */ 2919 Node *whereClause; /* qualifications */ 2920 CmdType event; /* SELECT, INSERT, etc */ 2921 bool instead; /* is a 'do instead'? */ 2922 List *actions; /* the action statements */ 2923 bool replace; /* OR REPLACE */ 2924 } RuleStmt; 2925 2926 /* ---------------------- 2927 * Notify Statement 2928 * ---------------------- 2929 */ 2930 typedef struct NotifyStmt 2931 { 2932 NodeTag type; 2933 char *conditionname; /* condition name to notify */ 2934 char *payload; /* the payload string, or NULL if none */ 2935 } NotifyStmt; 2936 2937 /* ---------------------- 2938 * Listen Statement 2939 * ---------------------- 2940 */ 2941 typedef struct ListenStmt 2942 { 2943 NodeTag type; 2944 char *conditionname; /* condition name to listen on */ 2945 } ListenStmt; 2946 2947 /* ---------------------- 2948 * Unlisten Statement 2949 * ---------------------- 2950 */ 2951 typedef struct UnlistenStmt 2952 { 2953 NodeTag type; 2954 char *conditionname; /* name to unlisten on, or NULL for all */ 2955 } UnlistenStmt; 2956 2957 /* ---------------------- 2958 * {Begin|Commit|Rollback} Transaction Statement 2959 * ---------------------- 2960 */ 2961 typedef enum TransactionStmtKind 2962 { 2963 TRANS_STMT_BEGIN, 2964 TRANS_STMT_START, /* semantically identical to BEGIN */ 2965 TRANS_STMT_COMMIT, 2966 TRANS_STMT_ROLLBACK, 2967 TRANS_STMT_SAVEPOINT, 2968 TRANS_STMT_RELEASE, 2969 TRANS_STMT_ROLLBACK_TO, 2970 TRANS_STMT_PREPARE, 2971 TRANS_STMT_COMMIT_PREPARED, 2972 TRANS_STMT_ROLLBACK_PREPARED 2973 } TransactionStmtKind; 2974 2975 typedef struct TransactionStmt 2976 { 2977 NodeTag type; 2978 TransactionStmtKind kind; /* see above */ 2979 List *options; /* for BEGIN/START commands */ 2980 char *savepoint_name; /* for savepoint commands */ 2981 char *gid; /* for two-phase-commit related commands */ 2982 } TransactionStmt; 2983 2984 /* ---------------------- 2985 * Create Type Statement, composite types 2986 * ---------------------- 2987 */ 2988 typedef struct CompositeTypeStmt 2989 { 2990 NodeTag type; 2991 RangeVar *typevar; /* the composite type to be created */ 2992 List *coldeflist; /* list of ColumnDef nodes */ 2993 } CompositeTypeStmt; 2994 2995 /* ---------------------- 2996 * Create Type Statement, enum types 2997 * ---------------------- 2998 */ 2999 typedef struct CreateEnumStmt 3000 { 3001 NodeTag type; 3002 List *typeName; /* qualified name (list of Value strings) */ 3003 List *vals; /* enum values (list of Value strings) */ 3004 } CreateEnumStmt; 3005 3006 /* ---------------------- 3007 * Create Type Statement, range types 3008 * ---------------------- 3009 */ 3010 typedef struct CreateRangeStmt 3011 { 3012 NodeTag type; 3013 List *typeName; /* qualified name (list of Value strings) */ 3014 List *params; /* range parameters (list of DefElem) */ 3015 } CreateRangeStmt; 3016 3017 /* ---------------------- 3018 * Alter Type Statement, enum types 3019 * ---------------------- 3020 */ 3021 typedef struct AlterEnumStmt 3022 { 3023 NodeTag type; 3024 List *typeName; /* qualified name (list of Value strings) */ 3025 char *oldVal; /* old enum value's name, if renaming */ 3026 char *newVal; /* new enum value's name */ 3027 char *newValNeighbor; /* neighboring enum value, if specified */ 3028 bool newValIsAfter; /* place new enum value after neighbor? */ 3029 bool skipIfNewValExists; /* no error if new already exists? */ 3030 } AlterEnumStmt; 3031 3032 /* ---------------------- 3033 * Create View Statement 3034 * ---------------------- 3035 */ 3036 typedef enum ViewCheckOption 3037 { 3038 NO_CHECK_OPTION, 3039 LOCAL_CHECK_OPTION, 3040 CASCADED_CHECK_OPTION 3041 } ViewCheckOption; 3042 3043 typedef struct ViewStmt 3044 { 3045 NodeTag type; 3046 RangeVar *view; /* the view to be created */ 3047 List *aliases; /* target column names */ 3048 Node *query; /* the SELECT query (as a raw parse tree) */ 3049 bool replace; /* replace an existing view? */ 3050 List *options; /* options from WITH clause */ 3051 ViewCheckOption withCheckOption; /* WITH CHECK OPTION */ 3052 } ViewStmt; 3053 3054 /* ---------------------- 3055 * Load Statement 3056 * ---------------------- 3057 */ 3058 typedef struct LoadStmt 3059 { 3060 NodeTag type; 3061 char *filename; /* file to load */ 3062 } LoadStmt; 3063 3064 /* ---------------------- 3065 * Createdb Statement 3066 * ---------------------- 3067 */ 3068 typedef struct CreatedbStmt 3069 { 3070 NodeTag type; 3071 char *dbname; /* name of database to create */ 3072 List *options; /* List of DefElem nodes */ 3073 } CreatedbStmt; 3074 3075 /* ---------------------- 3076 * Alter Database 3077 * ---------------------- 3078 */ 3079 typedef struct AlterDatabaseStmt 3080 { 3081 NodeTag type; 3082 char *dbname; /* name of database to alter */ 3083 List *options; /* List of DefElem nodes */ 3084 } AlterDatabaseStmt; 3085 3086 typedef struct AlterDatabaseSetStmt 3087 { 3088 NodeTag type; 3089 char *dbname; /* database name */ 3090 VariableSetStmt *setstmt; /* SET or RESET subcommand */ 3091 } AlterDatabaseSetStmt; 3092 3093 /* ---------------------- 3094 * Dropdb Statement 3095 * ---------------------- 3096 */ 3097 typedef struct DropdbStmt 3098 { 3099 NodeTag type; 3100 char *dbname; /* database to drop */ 3101 bool missing_ok; /* skip error if db is missing? */ 3102 } DropdbStmt; 3103 3104 /* ---------------------- 3105 * Alter System Statement 3106 * ---------------------- 3107 */ 3108 typedef struct AlterSystemStmt 3109 { 3110 NodeTag type; 3111 VariableSetStmt *setstmt; /* SET subcommand */ 3112 } AlterSystemStmt; 3113 3114 /* ---------------------- 3115 * Cluster Statement (support pbrown's cluster index implementation) 3116 * ---------------------- 3117 */ 3118 typedef struct ClusterStmt 3119 { 3120 NodeTag type; 3121 RangeVar *relation; /* relation being indexed, or NULL if all */ 3122 char *indexname; /* original index defined */ 3123 bool verbose; /* print progress info */ 3124 } ClusterStmt; 3125 3126 /* ---------------------- 3127 * Vacuum and Analyze Statements 3128 * 3129 * Even though these are nominally two statements, it's convenient to use 3130 * just one node type for both. Note that at least one of VACOPT_VACUUM 3131 * and VACOPT_ANALYZE must be set in options. 3132 * ---------------------- 3133 */ 3134 typedef enum VacuumOption 3135 { 3136 VACOPT_VACUUM = 1 << 0, /* do VACUUM */ 3137 VACOPT_ANALYZE = 1 << 1, /* do ANALYZE */ 3138 VACOPT_VERBOSE = 1 << 2, /* print progress info */ 3139 VACOPT_FREEZE = 1 << 3, /* FREEZE option */ 3140 VACOPT_FULL = 1 << 4, /* FULL (non-concurrent) vacuum */ 3141 VACOPT_NOWAIT = 1 << 5, /* don't wait to get lock (autovacuum only) */ 3142 VACOPT_SKIPTOAST = 1 << 6, /* don't process the TOAST table, if any */ 3143 VACOPT_DISABLE_PAGE_SKIPPING = 1 << 7 /* don't skip any pages */ 3144 } VacuumOption; 3145 3146 /* 3147 * Info about a single target table of VACUUM/ANALYZE. 3148 * 3149 * If the OID field is set, it always identifies the table to process. 3150 * Then the relation field can be NULL; if it isn't, it's used only to report 3151 * failure to open/lock the relation. 3152 */ 3153 typedef struct VacuumRelation 3154 { 3155 NodeTag type; 3156 RangeVar *relation; /* table name to process, or NULL */ 3157 Oid oid; /* table's OID; InvalidOid if not looked up */ 3158 List *va_cols; /* list of column names, or NIL for all */ 3159 } VacuumRelation; 3160 3161 typedef struct VacuumStmt 3162 { 3163 NodeTag type; 3164 int options; /* OR of VacuumOption flags */ 3165 List *rels; /* list of VacuumRelation, or NIL for all */ 3166 } VacuumStmt; 3167 3168 /* ---------------------- 3169 * Explain Statement 3170 * 3171 * The "query" field is initially a raw parse tree, and is converted to a 3172 * Query node during parse analysis. Note that rewriting and planning 3173 * of the query are always postponed until execution. 3174 * ---------------------- 3175 */ 3176 typedef struct ExplainStmt 3177 { 3178 NodeTag type; 3179 Node *query; /* the query (see comments above) */ 3180 List *options; /* list of DefElem nodes */ 3181 } ExplainStmt; 3182 3183 /* ---------------------- 3184 * CREATE TABLE AS Statement (a/k/a SELECT INTO) 3185 * 3186 * A query written as CREATE TABLE AS will produce this node type natively. 3187 * A query written as SELECT ... INTO will be transformed to this form during 3188 * parse analysis. 3189 * A query written as CREATE MATERIALIZED view will produce this node type, 3190 * during parse analysis, since it needs all the same data. 3191 * 3192 * The "query" field is handled similarly to EXPLAIN, though note that it 3193 * can be a SELECT or an EXECUTE, but not other DML statements. 3194 * ---------------------- 3195 */ 3196 typedef struct CreateTableAsStmt 3197 { 3198 NodeTag type; 3199 Node *query; /* the query (see comments above) */ 3200 IntoClause *into; /* destination table */ 3201 ObjectType relkind; /* OBJECT_TABLE or OBJECT_MATVIEW */ 3202 bool is_select_into; /* it was written as SELECT INTO */ 3203 bool if_not_exists; /* just do nothing if it already exists? */ 3204 } CreateTableAsStmt; 3205 3206 /* ---------------------- 3207 * REFRESH MATERIALIZED VIEW Statement 3208 * ---------------------- 3209 */ 3210 typedef struct RefreshMatViewStmt 3211 { 3212 NodeTag type; 3213 bool concurrent; /* allow concurrent access? */ 3214 bool skipData; /* true for WITH NO DATA */ 3215 RangeVar *relation; /* relation to insert into */ 3216 } RefreshMatViewStmt; 3217 3218 /* ---------------------- 3219 * Checkpoint Statement 3220 * ---------------------- 3221 */ 3222 typedef struct CheckPointStmt 3223 { 3224 NodeTag type; 3225 } CheckPointStmt; 3226 3227 /* ---------------------- 3228 * Discard Statement 3229 * ---------------------- 3230 */ 3231 3232 typedef enum DiscardMode 3233 { 3234 DISCARD_ALL, 3235 DISCARD_PLANS, 3236 DISCARD_SEQUENCES, 3237 DISCARD_TEMP 3238 } DiscardMode; 3239 3240 typedef struct DiscardStmt 3241 { 3242 NodeTag type; 3243 DiscardMode target; 3244 } DiscardStmt; 3245 3246 /* ---------------------- 3247 * LOCK Statement 3248 * ---------------------- 3249 */ 3250 typedef struct LockStmt 3251 { 3252 NodeTag type; 3253 List *relations; /* relations to lock */ 3254 int mode; /* lock mode */ 3255 bool nowait; /* no wait mode */ 3256 } LockStmt; 3257 3258 /* ---------------------- 3259 * SET CONSTRAINTS Statement 3260 * ---------------------- 3261 */ 3262 typedef struct ConstraintsSetStmt 3263 { 3264 NodeTag type; 3265 List *constraints; /* List of names as RangeVars */ 3266 bool deferred; 3267 } ConstraintsSetStmt; 3268 3269 /* ---------------------- 3270 * REINDEX Statement 3271 * ---------------------- 3272 */ 3273 3274 /* Reindex options */ 3275 #define REINDEXOPT_VERBOSE (1 << 0) /* print progress info */ 3276 3277 typedef enum ReindexObjectType 3278 { 3279 REINDEX_OBJECT_INDEX, /* index */ 3280 REINDEX_OBJECT_TABLE, /* table or materialized view */ 3281 REINDEX_OBJECT_SCHEMA, /* schema */ 3282 REINDEX_OBJECT_SYSTEM, /* system catalogs */ 3283 REINDEX_OBJECT_DATABASE /* database */ 3284 } ReindexObjectType; 3285 3286 typedef struct ReindexStmt 3287 { 3288 NodeTag type; 3289 ReindexObjectType kind; /* REINDEX_OBJECT_INDEX, REINDEX_OBJECT_TABLE, 3290 * etc. */ 3291 RangeVar *relation; /* Table or index to reindex */ 3292 const char *name; /* name of database to reindex */ 3293 int options; /* Reindex options flags */ 3294 } ReindexStmt; 3295 3296 /* ---------------------- 3297 * CREATE CONVERSION Statement 3298 * ---------------------- 3299 */ 3300 typedef struct CreateConversionStmt 3301 { 3302 NodeTag type; 3303 List *conversion_name; /* Name of the conversion */ 3304 char *for_encoding_name; /* source encoding name */ 3305 char *to_encoding_name; /* destination encoding name */ 3306 List *func_name; /* qualified conversion function name */ 3307 bool def; /* is this a default conversion? */ 3308 } CreateConversionStmt; 3309 3310 /* ---------------------- 3311 * CREATE CAST Statement 3312 * ---------------------- 3313 */ 3314 typedef struct CreateCastStmt 3315 { 3316 NodeTag type; 3317 TypeName *sourcetype; 3318 TypeName *targettype; 3319 ObjectWithArgs *func; 3320 CoercionContext context; 3321 bool inout; 3322 } CreateCastStmt; 3323 3324 /* ---------------------- 3325 * CREATE TRANSFORM Statement 3326 * ---------------------- 3327 */ 3328 typedef struct CreateTransformStmt 3329 { 3330 NodeTag type; 3331 bool replace; 3332 TypeName *type_name; 3333 char *lang; 3334 ObjectWithArgs *fromsql; 3335 ObjectWithArgs *tosql; 3336 } CreateTransformStmt; 3337 3338 /* ---------------------- 3339 * PREPARE Statement 3340 * ---------------------- 3341 */ 3342 typedef struct PrepareStmt 3343 { 3344 NodeTag type; 3345 char *name; /* Name of plan, arbitrary */ 3346 List *argtypes; /* Types of parameters (List of TypeName) */ 3347 Node *query; /* The query itself (as a raw parsetree) */ 3348 } PrepareStmt; 3349 3350 3351 /* ---------------------- 3352 * EXECUTE Statement 3353 * ---------------------- 3354 */ 3355 3356 typedef struct ExecuteStmt 3357 { 3358 NodeTag type; 3359 char *name; /* The name of the plan to execute */ 3360 List *params; /* Values to assign to parameters */ 3361 } ExecuteStmt; 3362 3363 3364 /* ---------------------- 3365 * DEALLOCATE Statement 3366 * ---------------------- 3367 */ 3368 typedef struct DeallocateStmt 3369 { 3370 NodeTag type; 3371 char *name; /* The name of the plan to remove */ 3372 /* NULL means DEALLOCATE ALL */ 3373 } DeallocateStmt; 3374 3375 /* 3376 * DROP OWNED statement 3377 */ 3378 typedef struct DropOwnedStmt 3379 { 3380 NodeTag type; 3381 List *roles; 3382 DropBehavior behavior; 3383 } DropOwnedStmt; 3384 3385 /* 3386 * REASSIGN OWNED statement 3387 */ 3388 typedef struct ReassignOwnedStmt 3389 { 3390 NodeTag type; 3391 List *roles; 3392 RoleSpec *newrole; 3393 } ReassignOwnedStmt; 3394 3395 /* 3396 * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default 3397 */ 3398 typedef struct AlterTSDictionaryStmt 3399 { 3400 NodeTag type; 3401 List *dictname; /* qualified name (list of Value strings) */ 3402 List *options; /* List of DefElem nodes */ 3403 } AlterTSDictionaryStmt; 3404 3405 /* 3406 * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default 3407 */ 3408 typedef enum AlterTSConfigType 3409 { 3410 ALTER_TSCONFIG_ADD_MAPPING, 3411 ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN, 3412 ALTER_TSCONFIG_REPLACE_DICT, 3413 ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN, 3414 ALTER_TSCONFIG_DROP_MAPPING 3415 } AlterTSConfigType; 3416 3417 typedef struct AlterTSConfigurationStmt 3418 { 3419 NodeTag type; 3420 AlterTSConfigType kind; /* ALTER_TSCONFIG_ADD_MAPPING, etc */ 3421 List *cfgname; /* qualified name (list of Value strings) */ 3422 3423 /* 3424 * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is 3425 * NIL, but tokentype isn't, DROP MAPPING was specified. 3426 */ 3427 List *tokentype; /* list of Value strings */ 3428 List *dicts; /* list of list of Value strings */ 3429 bool override; /* if true - remove old variant */ 3430 bool replace; /* if true - replace dictionary by another */ 3431 bool missing_ok; /* for DROP - skip error if missing? */ 3432 } AlterTSConfigurationStmt; 3433 3434 3435 typedef struct CreatePublicationStmt 3436 { 3437 NodeTag type; 3438 char *pubname; /* Name of the publication */ 3439 List *options; /* List of DefElem nodes */ 3440 List *tables; /* Optional list of tables to add */ 3441 bool for_all_tables; /* Special publication for all tables in db */ 3442 } CreatePublicationStmt; 3443 3444 typedef struct AlterPublicationStmt 3445 { 3446 NodeTag type; 3447 char *pubname; /* Name of the publication */ 3448 3449 /* parameters used for ALTER PUBLICATION ... WITH */ 3450 List *options; /* List of DefElem nodes */ 3451 3452 /* parameters used for ALTER PUBLICATION ... ADD/DROP TABLE */ 3453 List *tables; /* List of tables to add/drop */ 3454 bool for_all_tables; /* Special publication for all tables in db */ 3455 DefElemAction tableAction; /* What action to perform with the tables */ 3456 } AlterPublicationStmt; 3457 3458 typedef struct CreateSubscriptionStmt 3459 { 3460 NodeTag type; 3461 char *subname; /* Name of the subscription */ 3462 char *conninfo; /* Connection string to publisher */ 3463 List *publication; /* One or more publication to subscribe to */ 3464 List *options; /* List of DefElem nodes */ 3465 } CreateSubscriptionStmt; 3466 3467 typedef enum AlterSubscriptionType 3468 { 3469 ALTER_SUBSCRIPTION_OPTIONS, 3470 ALTER_SUBSCRIPTION_CONNECTION, 3471 ALTER_SUBSCRIPTION_PUBLICATION, 3472 ALTER_SUBSCRIPTION_REFRESH, 3473 ALTER_SUBSCRIPTION_ENABLED 3474 } AlterSubscriptionType; 3475 3476 typedef struct AlterSubscriptionStmt 3477 { 3478 NodeTag type; 3479 AlterSubscriptionType kind; /* ALTER_SUBSCRIPTION_OPTIONS, etc */ 3480 char *subname; /* Name of the subscription */ 3481 char *conninfo; /* Connection string to publisher */ 3482 List *publication; /* One or more publication to subscribe to */ 3483 List *options; /* List of DefElem nodes */ 3484 } AlterSubscriptionStmt; 3485 3486 typedef struct DropSubscriptionStmt 3487 { 3488 NodeTag type; 3489 char *subname; /* Name of the subscription */ 3490 bool missing_ok; /* Skip error if missing? */ 3491 DropBehavior behavior; /* RESTRICT or CASCADE behavior */ 3492 } DropSubscriptionStmt; 3493 3494 #endif /* PARSENODES_H */ 3495