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