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