1 /*-------------------------------------------------------------------------
4 * definitions for parse tree nodes
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.
15 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
16 * Portions Copyright (c) 1994, Regents of the University of California
18 * src/include/nodes/parsenodes.h
20 *-------------------------------------------------------------------------
25 #include "nodes/bitmapset.h"
26 #include "nodes/lockoptions.h"
27 #include "nodes/primnodes.h"
28 #include "nodes/value.h"
30 typedef enum OverridingKind
32 OVERRIDING_NOT_SET = 0,
33 OVERRIDING_USER_VALUE,
34 OVERRIDING_SYSTEM_VALUE
37 /* Possible sources of a Query */
38 typedef enum QuerySource
40 QSRC_ORIGINAL, /* original parsetree (explicit query) */
41 QSRC_PARSER, /* added by parse analysis (now unused) */
42 QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */
43 QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */
44 QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */
47 /* Sort ordering options for ORDER BY and CREATE INDEX */
48 typedef enum SortByDir
53 SORTBY_USING /* not allowed in CREATE INDEX ... */
56 typedef enum SortByNulls
64 * Grantable rights are encoded so that we can OR them together in a bitmask.
65 * The present representation of AclItem limits us to 16 distinct rights,
66 * even though AclMode is defined as uint32. See utils/acl.h.
68 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
70 typedef uint32 AclMode; /* a bitmask of privilege bits */
72 #define ACL_INSERT (1<<0) /* for relations */
73 #define ACL_SELECT (1<<1)
74 #define ACL_UPDATE (1<<2)
75 #define ACL_DELETE (1<<3)
76 #define ACL_TRUNCATE (1<<4)
77 #define ACL_REFERENCES (1<<5)
78 #define ACL_TRIGGER (1<<6)
79 #define ACL_EXECUTE (1<<7) /* for functions */
80 #define ACL_USAGE (1<<8) /* for languages, namespaces, FDWs, and
82 #define ACL_CREATE (1<<9) /* for namespaces and databases */
83 #define ACL_CREATE_TEMP (1<<10) /* for databases */
84 #define ACL_CONNECT (1<<11) /* for databases */
85 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */
86 #define ACL_NO_RIGHTS 0
87 /* Currently, SELECT ... FOR [KEY] UPDATE/SHARE requires UPDATE privileges */
88 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE
91 /*****************************************************************************
93 *****************************************************************************/
97 * Parse analysis turns all statements into a Query tree
98 * for further processing by the rewriter and planner.
100 * Utility statements (i.e. non-optimizable statements) have the
101 * utilityStmt field set, and the rest of the Query is mostly dummy.
103 * Planning converts a Query tree into a Plan tree headed by a PlannedStmt
104 * node --- the Query structure is not used by the executor.
110 CmdType commandType; /* select|insert|update|delete|utility */
112 QuerySource querySource; /* where did I come from? */
114 uint32 queryId; /* query identifier (can be set by plugins) */
116 bool canSetTag; /* do I set the command result tag? */
118 Node *utilityStmt; /* non-null if commandType == CMD_UTILITY */
120 int resultRelation; /* rtable index of target relation for
121 * INSERT/UPDATE/DELETE; 0 for SELECT */
123 bool hasAggs; /* has aggregates in tlist or havingQual */
124 bool hasWindowFuncs; /* has window functions in tlist */
125 bool hasTargetSRFs; /* has set-returning functions in tlist */
126 bool hasSubLinks; /* has subquery SubLink */
127 bool hasDistinctOn; /* distinctClause is from DISTINCT ON */
128 bool hasRecursive; /* WITH RECURSIVE was specified */
129 bool hasModifyingCTE; /* has INSERT/UPDATE/DELETE in WITH */
130 bool hasForUpdate; /* FOR [KEY] UPDATE/SHARE was specified */
131 bool hasRowSecurity; /* rewriter has applied some RLS policy */
133 List *cteList; /* WITH list (of CommonTableExpr's) */
135 List *rtable; /* list of range table entries */
136 FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */
138 List *targetList; /* target list (of TargetEntry) */
140 OverridingKind override; /* OVERRIDING clause */
142 OnConflictExpr *onConflict; /* ON CONFLICT DO [NOTHING | UPDATE] */
144 List *returningList; /* return-values list (of TargetEntry) */
146 List *groupClause; /* a list of SortGroupClause's */
148 List *groupingSets; /* a list of GroupingSet's if present */
150 Node *havingQual; /* qualifications applied to groups */
152 List *windowClause; /* a list of WindowClause's */
154 List *distinctClause; /* a list of SortGroupClause's */
156 List *sortClause; /* a list of SortGroupClause's */
158 Node *limitOffset; /* # of result tuples to skip (int8 expr) */
159 Node *limitCount; /* # of result tuples to return (int8 expr) */
161 List *rowMarks; /* a list of RowMarkClause's */
163 Node *setOperations; /* set-operation tree if this is top level of
164 * a UNION/INTERSECT/EXCEPT query */
166 List *constraintDeps; /* a list of pg_constraint OIDs that the query
167 * depends on to be semantically valid */
169 List *withCheckOptions; /* a list of WithCheckOption's, which are
170 * only added during rewrite and therefore
171 * are not written out as part of Query. */
174 * The following two fields identify the portion of the source text string
175 * containing this query. They are typically only populated in top-level
176 * Queries, not in sub-queries. When not set, they might both be zero, or
177 * both be -1 meaning "unknown".
179 int stmt_location; /* start location, or -1 if unknown */
180 int stmt_len; /* length in bytes; 0 means "rest of string" */
184 /****************************************************************************
185 * Supporting data structures for Parse Trees
187 * Most of these node types appear in raw parsetrees output by the grammar,
188 * and get transformed to something else by the analyzer. A few of them
189 * are used as-is in transformed querytrees.
190 ****************************************************************************/
193 * TypeName - specifies a type in definitions
195 * For TypeName structures generated internally, it is often easier to
196 * specify the type by OID than by name. If "names" is NIL then the
197 * actual type OID is given by typeOid, otherwise typeOid is unused.
198 * Similarly, if "typmods" is NIL then the actual typmod is expected to
199 * be prespecified in typemod, otherwise typemod is unused.
201 * If pct_type is TRUE, then names is actually a field name and we look up
202 * the type of that field. Otherwise (the normal case), names is a type
203 * name possibly qualified with schema and database name.
205 typedef struct TypeName
208 List *names; /* qualified name (list of Value strings) */
209 Oid typeOid; /* type identified by OID */
210 bool setof; /* is a set? */
211 bool pct_type; /* %TYPE specified? */
212 List *typmods; /* type modifier expression(s) */
213 int32 typemod; /* prespecified type modifier */
214 List *arrayBounds; /* array bounds */
215 int location; /* token location, or -1 if unknown */
219 * ColumnRef - specifies a reference to a column, or possibly a whole tuple
221 * The "fields" list must be nonempty. It can contain string Value nodes
222 * (representing names) and A_Star nodes (representing occurrence of a '*').
223 * Currently, A_Star must appear only as the last list element --- the grammar
224 * is responsible for enforcing this!
226 * Note: any array subscripting or selection of fields from composite columns
227 * is represented by an A_Indirection node above the ColumnRef. However,
228 * for simplicity in the normal case, initial field selection from a table
229 * name is represented within ColumnRef and not by adding A_Indirection.
231 typedef struct ColumnRef
234 List *fields; /* field names (Value strings) or A_Star */
235 int location; /* token location, or -1 if unknown */
239 * ParamRef - specifies a $n parameter reference
241 typedef struct ParamRef
244 int number; /* the number of the parameter */
245 int location; /* token location, or -1 if unknown */
249 * A_Expr - infix, prefix, and postfix expressions
251 typedef enum A_Expr_Kind
253 AEXPR_OP, /* normal operator */
254 AEXPR_OP_ANY, /* scalar op ANY (array) */
255 AEXPR_OP_ALL, /* scalar op ALL (array) */
256 AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */
257 AEXPR_NOT_DISTINCT, /* IS NOT DISTINCT FROM - name must be "=" */
258 AEXPR_NULLIF, /* NULLIF - name must be "=" */
259 AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */
260 AEXPR_IN, /* [NOT] IN - name must be "=" or "<>" */
261 AEXPR_LIKE, /* [NOT] LIKE - name must be "~~" or "!~~" */
262 AEXPR_ILIKE, /* [NOT] ILIKE - name must be "~~*" or "!~~*" */
263 AEXPR_SIMILAR, /* [NOT] SIMILAR - name must be "~" or "!~" */
264 AEXPR_BETWEEN, /* name must be "BETWEEN" */
265 AEXPR_NOT_BETWEEN, /* name must be "NOT BETWEEN" */
266 AEXPR_BETWEEN_SYM, /* name must be "BETWEEN SYMMETRIC" */
267 AEXPR_NOT_BETWEEN_SYM, /* name must be "NOT BETWEEN SYMMETRIC" */
268 AEXPR_PAREN /* nameless dummy node for parentheses */
271 typedef struct A_Expr
274 A_Expr_Kind kind; /* see above */
275 List *name; /* possibly-qualified name of operator */
276 Node *lexpr; /* left argument, or NULL if none */
277 Node *rexpr; /* right argument, or NULL if none */
278 int location; /* token location, or -1 if unknown */
282 * A_Const - a literal constant
284 typedef struct A_Const
287 Value val; /* value (includes type info, see value.h) */
288 int location; /* token location, or -1 if unknown */
292 * TypeCast - a CAST expression
294 typedef struct TypeCast
297 Node *arg; /* the expression being casted */
298 TypeName *typeName; /* the target type */
299 int location; /* token location, or -1 if unknown */
303 * CollateClause - a COLLATE expression
305 typedef struct CollateClause
308 Node *arg; /* input expression */
309 List *collname; /* possibly-qualified collation name */
310 int location; /* token location, or -1 if unknown */
314 * RoleSpec - a role name or one of a few special values.
316 typedef enum RoleSpecType
318 ROLESPEC_CSTRING, /* role name is stored as a C string */
319 ROLESPEC_CURRENT_USER, /* role spec is CURRENT_USER */
320 ROLESPEC_SESSION_USER, /* role spec is SESSION_USER */
321 ROLESPEC_PUBLIC /* role name is "public" */
324 typedef struct RoleSpec
327 RoleSpecType roletype; /* Type of this rolespec */
328 char *rolename; /* filled only for ROLESPEC_CSTRING */
329 int location; /* token location, or -1 if unknown */
333 * FuncCall - a function or aggregate invocation
335 * agg_order (if not NIL) indicates we saw 'foo(... ORDER BY ...)', or if
336 * agg_within_group is true, it was 'foo(...) WITHIN GROUP (ORDER BY ...)'.
337 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
338 * indicates we saw 'foo(DISTINCT ...)'. In any of these cases, the
339 * construct *must* be an aggregate call. Otherwise, it might be either an
340 * aggregate or some other kind of function. However, if FILTER or OVER is
341 * present it had better be an aggregate or window function.
343 * Normally, you'd initialize this via makeFuncCall() and then only change the
344 * parts of the struct its defaults don't match afterwards, as needed.
346 typedef struct FuncCall
349 List *funcname; /* qualified name of function */
350 List *args; /* the arguments (list of exprs) */
351 List *agg_order; /* ORDER BY (list of SortBy) */
352 Node *agg_filter; /* FILTER clause, if any */
353 bool agg_within_group; /* ORDER BY appeared in WITHIN GROUP */
354 bool agg_star; /* argument was really '*' */
355 bool agg_distinct; /* arguments were labeled DISTINCT */
356 bool func_variadic; /* last argument was labeled VARIADIC */
357 struct WindowDef *over; /* OVER clause, if any */
358 int location; /* token location, or -1 if unknown */
362 * A_Star - '*' representing all columns of a table or compound field
364 * This can appear within ColumnRef.fields, A_Indirection.indirection, and
365 * ResTarget.indirection lists.
367 typedef struct A_Star
373 * A_Indices - array subscript or slice bounds ([idx] or [lidx:uidx])
375 * In slice case, either or both of lidx and uidx can be NULL (omitted).
376 * In non-slice case, uidx holds the single subscript and lidx is always NULL.
378 typedef struct A_Indices
381 bool is_slice; /* true if slice (i.e., colon present) */
382 Node *lidx; /* slice lower bound, if any */
383 Node *uidx; /* subscript, or slice upper bound if any */
387 * A_Indirection - select a field and/or array element from an expression
389 * The indirection list can contain A_Indices nodes (representing
390 * subscripting), string Value nodes (representing field selection --- the
391 * string value is the name of the field to select), and A_Star nodes
392 * (representing selection of all fields of a composite type).
393 * For example, a complex selection operation like
394 * (foo).field1[42][7].field2
395 * would be represented with a single A_Indirection node having a 4-element
398 * Currently, A_Star must appear only as the last list element --- the grammar
399 * is responsible for enforcing this!
401 typedef struct A_Indirection
404 Node *arg; /* the thing being selected from */
405 List *indirection; /* subscripts and/or field names and/or * */
409 * A_ArrayExpr - an ARRAY[] construct
411 typedef struct A_ArrayExpr
414 List *elements; /* array element expressions */
415 int location; /* token location, or -1 if unknown */
420 * result target (used in target list of pre-transformed parse trees)
422 * In a SELECT target list, 'name' is the column label from an
423 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
424 * value expression itself. The 'indirection' field is not used.
426 * INSERT uses ResTarget in its target-column-names list. Here, 'name' is
427 * the name of the destination column, 'indirection' stores any subscripts
428 * attached to the destination, and 'val' is not used.
430 * In an UPDATE target list, 'name' is the name of the destination column,
431 * 'indirection' stores any subscripts attached to the destination, and
432 * 'val' is the expression to assign.
434 * See A_Indirection for more info about what can appear in 'indirection'.
436 typedef struct ResTarget
439 char *name; /* column name or NULL */
440 List *indirection; /* subscripts, field names, and '*', or NIL */
441 Node *val; /* the value expression to compute or assign */
442 int location; /* token location, or -1 if unknown */
446 * MultiAssignRef - element of a row source expression for UPDATE
448 * In an UPDATE target list, when we have SET (a,b,c) = row-valued-expression,
449 * we generate separate ResTarget items for each of a,b,c. Their "val" trees
450 * are MultiAssignRef nodes numbered 1..n, linking to a common copy of the
451 * row-valued-expression (which parse analysis will process only once, when
452 * handling the MultiAssignRef with colno=1).
454 typedef struct MultiAssignRef
457 Node *source; /* the row-valued expression */
458 int colno; /* column number for this target (1..n) */
459 int ncolumns; /* number of targets in the construct */
463 * SortBy - for ORDER BY clause
465 typedef struct SortBy
468 Node *node; /* expression to sort on */
469 SortByDir sortby_dir; /* ASC/DESC/USING/default */
470 SortByNulls sortby_nulls; /* NULLS FIRST/LAST */
471 List *useOp; /* name of op to use, if SORTBY_USING */
472 int location; /* operator location, or -1 if none/unknown */
476 * WindowDef - raw representation of WINDOW and OVER clauses
478 * For entries in a WINDOW list, "name" is the window name being defined.
479 * For OVER clauses, we use "name" for the "OVER window" syntax, or "refname"
480 * for the "OVER (window)" syntax, which is subtly different --- the latter
481 * implies overriding the window frame clause.
483 typedef struct WindowDef
486 char *name; /* window's own name */
487 char *refname; /* referenced window name, if any */
488 List *partitionClause; /* PARTITION BY expression list */
489 List *orderClause; /* ORDER BY (list of SortBy) */
490 int frameOptions; /* frame_clause options, see below */
491 Node *startOffset; /* expression for starting bound, if any */
492 Node *endOffset; /* expression for ending bound, if any */
493 int location; /* parse location, or -1 if none/unknown */
497 * frameOptions is an OR of these bits. The NONDEFAULT and BETWEEN bits are
498 * used so that ruleutils.c can tell which properties were specified and
499 * which were defaulted; the correct behavioral bits must be set either way.
500 * The START_foo and END_foo options must come in pairs of adjacent bits for
501 * the convenience of gram.y, even though some of them are useless/invalid.
502 * We will need more bits (and fields) to cover the full SQL:2008 option set.
504 #define FRAMEOPTION_NONDEFAULT 0x00001 /* any specified? */
505 #define FRAMEOPTION_RANGE 0x00002 /* RANGE behavior */
506 #define FRAMEOPTION_ROWS 0x00004 /* ROWS behavior */
507 #define FRAMEOPTION_BETWEEN 0x00008 /* BETWEEN given? */
508 #define FRAMEOPTION_START_UNBOUNDED_PRECEDING 0x00010 /* start is U. P. */
509 #define FRAMEOPTION_END_UNBOUNDED_PRECEDING 0x00020 /* (disallowed) */
510 #define FRAMEOPTION_START_UNBOUNDED_FOLLOWING 0x00040 /* (disallowed) */
511 #define FRAMEOPTION_END_UNBOUNDED_FOLLOWING 0x00080 /* end is U. F. */
512 #define FRAMEOPTION_START_CURRENT_ROW 0x00100 /* start is C. R. */
513 #define FRAMEOPTION_END_CURRENT_ROW 0x00200 /* end is C. R. */
514 #define FRAMEOPTION_START_VALUE_PRECEDING 0x00400 /* start is V. P. */
515 #define FRAMEOPTION_END_VALUE_PRECEDING 0x00800 /* end is V. P. */
516 #define FRAMEOPTION_START_VALUE_FOLLOWING 0x01000 /* start is V. F. */
517 #define FRAMEOPTION_END_VALUE_FOLLOWING 0x02000 /* end is V. F. */
519 #define FRAMEOPTION_START_VALUE \
520 (FRAMEOPTION_START_VALUE_PRECEDING | FRAMEOPTION_START_VALUE_FOLLOWING)
521 #define FRAMEOPTION_END_VALUE \
522 (FRAMEOPTION_END_VALUE_PRECEDING | FRAMEOPTION_END_VALUE_FOLLOWING)
524 #define FRAMEOPTION_DEFAULTS \
525 (FRAMEOPTION_RANGE | FRAMEOPTION_START_UNBOUNDED_PRECEDING | \
526 FRAMEOPTION_END_CURRENT_ROW)
529 * RangeSubselect - subquery appearing in a FROM clause
531 typedef struct RangeSubselect
534 bool lateral; /* does it have LATERAL prefix? */
535 Node *subquery; /* the untransformed sub-select clause */
536 Alias *alias; /* table alias & optional column aliases */
540 * RangeFunction - function call appearing in a FROM clause
542 * functions is a List because we use this to represent the construct
543 * ROWS FROM(func1(...), func2(...), ...). Each element of this list is a
544 * two-element sublist, the first element being the untransformed function
545 * call tree, and the second element being a possibly-empty list of ColumnDef
546 * nodes representing any columndef list attached to that function within the
547 * ROWS FROM() syntax.
549 * alias and coldeflist represent any alias and/or columndef list attached
550 * at the top level. (We disallow coldeflist appearing both here and
551 * per-function, but that's checked in parse analysis, not by the grammar.)
553 typedef struct RangeFunction
556 bool lateral; /* does it have LATERAL prefix? */
557 bool ordinality; /* does it have WITH ORDINALITY suffix? */
558 bool is_rowsfrom; /* is result of ROWS FROM() syntax? */
559 List *functions; /* per-function information, see above */
560 Alias *alias; /* table alias & optional column aliases */
561 List *coldeflist; /* list of ColumnDef nodes to describe result
562 * of function returning RECORD */
566 * RangeTableFunc - raw form of "table functions" such as XMLTABLE
568 typedef struct RangeTableFunc
571 bool lateral; /* does it have LATERAL prefix? */
572 Node *docexpr; /* document expression */
573 Node *rowexpr; /* row generator expression */
574 List *namespaces; /* list of namespaces as ResTarget */
575 List *columns; /* list of RangeTableFuncCol */
576 Alias *alias; /* table alias & optional column aliases */
577 int location; /* token location, or -1 if unknown */
581 * RangeTableFuncCol - one column in a RangeTableFunc->columns
583 * If for_ordinality is true (FOR ORDINALITY), then the column is an int4
584 * column and the rest of the fields are ignored.
586 typedef struct RangeTableFuncCol
589 char *colname; /* name of generated column */
590 TypeName *typeName; /* type of generated column */
591 bool for_ordinality; /* does it have FOR ORDINALITY? */
592 bool is_not_null; /* does it have NOT NULL? */
593 Node *colexpr; /* column filter expression */
594 Node *coldefexpr; /* column default value expression */
595 int location; /* token location, or -1 if unknown */
599 * RangeTableSample - TABLESAMPLE appearing in a raw FROM clause
601 * This node, appearing only in raw parse trees, represents
602 * <relation> TABLESAMPLE <method> (<params>) REPEATABLE (<num>)
603 * Currently, the <relation> can only be a RangeVar, but we might in future
604 * allow RangeSubselect and other options. Note that the RangeTableSample
605 * is wrapped around the node representing the <relation>, rather than being
608 typedef struct RangeTableSample
611 Node *relation; /* relation to be sampled */
612 List *method; /* sampling method name (possibly qualified) */
613 List *args; /* argument(s) for sampling method */
614 Node *repeatable; /* REPEATABLE expression, or NULL if none */
615 int location; /* method name location, or -1 if unknown */
619 * ColumnDef - column definition (used in various creates)
621 * If the column has a default value, we may have the value expression
622 * in either "raw" form (an untransformed parse tree) or "cooked" form
623 * (a post-parse-analysis, executable expression tree), depending on
624 * how this ColumnDef node was created (by parsing, or by inheritance
625 * from an existing relation). We should never have both in the same node!
627 * Similarly, we may have a COLLATE specification in either raw form
628 * (represented as a CollateClause with arg==NULL) or cooked form
629 * (the collation's OID).
631 * The constraints list may contain a CONSTR_DEFAULT item in a raw
632 * parsetree produced by gram.y, but transformCreateStmt will remove
633 * the item and set raw_default instead. CONSTR_DEFAULT items
634 * should not appear in any subsequent processing.
636 typedef struct ColumnDef
639 char *colname; /* name of column */
640 TypeName *typeName; /* type of column */
641 int inhcount; /* number of times column is inherited */
642 bool is_local; /* column has local (non-inherited) def'n */
643 bool is_not_null; /* NOT NULL constraint specified? */
644 bool is_from_type; /* column definition came from table type */
645 bool is_from_parent; /* column def came from partition parent */
646 char storage; /* attstorage setting, or 0 for default */
647 Node *raw_default; /* default value (untransformed parse tree) */
648 Node *cooked_default; /* default value (transformed expr tree) */
649 char identity; /* attidentity setting */
650 CollateClause *collClause; /* untransformed COLLATE spec, if any */
651 Oid collOid; /* collation OID (InvalidOid if not set) */
652 List *constraints; /* other constraints on column */
653 List *fdwoptions; /* per-column FDW options */
654 int location; /* parse location, or -1 if none/unknown */
658 * TableLikeClause - CREATE TABLE ( ... LIKE ... ) clause
660 typedef struct TableLikeClause
664 bits32 options; /* OR of TableLikeOption flags */
667 typedef enum TableLikeOption
669 CREATE_TABLE_LIKE_DEFAULTS = 1 << 0,
670 CREATE_TABLE_LIKE_CONSTRAINTS = 1 << 1,
671 CREATE_TABLE_LIKE_IDENTITY = 1 << 2,
672 CREATE_TABLE_LIKE_INDEXES = 1 << 3,
673 CREATE_TABLE_LIKE_STORAGE = 1 << 4,
674 CREATE_TABLE_LIKE_COMMENTS = 1 << 5,
675 CREATE_TABLE_LIKE_ALL = PG_INT32_MAX
679 * IndexElem - index parameters (used in CREATE INDEX, and in ON CONFLICT)
681 * For a plain index attribute, 'name' is the name of the table column to
682 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and
683 * 'expr' is the expression tree.
685 typedef struct IndexElem
688 char *name; /* name of attribute to index, or NULL */
689 Node *expr; /* expression to index, or NULL */
690 char *indexcolname; /* name for index column; NULL = default */
691 List *collation; /* name of collation; NIL = default */
692 List *opclass; /* name of desired opclass; NIL = default */
693 SortByDir ordering; /* ASC/DESC/default */
694 SortByNulls nulls_ordering; /* FIRST/LAST/default */
698 * DefElem - a generic "name = value" option definition
700 * In some contexts the name can be qualified. Also, certain SQL commands
701 * allow a SET/ADD/DROP action to be attached to option settings, so it's
702 * convenient to carry a field for that too. (Note: currently, it is our
703 * practice that the grammar allows namespace and action only in statements
704 * where they are relevant; C code can just ignore those fields in other
707 typedef enum DefElemAction
709 DEFELEM_UNSPEC, /* no action given */
715 typedef struct DefElem
718 char *defnamespace; /* NULL if unqualified name */
720 Node *arg; /* a (Value *) or a (TypeName *) */
721 DefElemAction defaction; /* unspecified action, or SET/ADD/DROP */
722 int location; /* token location, or -1 if unknown */
726 * LockingClause - raw representation of FOR [NO KEY] UPDATE/[KEY] SHARE
729 * Note: lockedRels == NIL means "all relations in query". Otherwise it
730 * is a list of RangeVar nodes. (We use RangeVar mainly because it carries
731 * a location field --- currently, parse analysis insists on unqualified
732 * names in LockingClause.)
734 typedef struct LockingClause
737 List *lockedRels; /* FOR [KEY] UPDATE/SHARE relations */
738 LockClauseStrength strength;
739 LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */
743 * XMLSERIALIZE (in raw parse tree only)
745 typedef struct XmlSerialize
748 XmlOptionType xmloption; /* DOCUMENT or CONTENT */
751 int location; /* token location, or -1 if unknown */
754 /* Partitioning related definitions */
757 * PartitionElem - parse-time representation of a single partition key
759 * expr can be either a raw expression tree or a parse-analyzed expression.
760 * We don't store these on-disk, though.
762 typedef struct PartitionElem
765 char *name; /* name of column to partition on, or NULL */
766 Node *expr; /* expression to partition on, or NULL */
767 List *collation; /* name of collation; NIL = default */
768 List *opclass; /* name of desired opclass; NIL = default */
769 int location; /* token location, or -1 if unknown */
773 * PartitionSpec - parse-time representation of a partition key specification
775 * This represents the key space we will be partitioning on.
777 typedef struct PartitionSpec
780 char *strategy; /* partitioning strategy ('list' or 'range') */
781 List *partParams; /* List of PartitionElems */
782 int location; /* token location, or -1 if unknown */
785 /* Internal codes for partitioning strategies */
786 #define PARTITION_STRATEGY_LIST 'l'
787 #define PARTITION_STRATEGY_RANGE 'r'
790 * PartitionBoundSpec - a partition bound specification
792 * This represents the portion of the partition key space assigned to a
793 * particular partition. These are stored on disk in pg_class.relpartbound.
795 typedef struct PartitionBoundSpec
799 char strategy; /* see PARTITION_STRATEGY codes above */
801 /* Partitioning info for LIST strategy: */
802 List *listdatums; /* List of Consts (or A_Consts in raw tree) */
804 /* Partitioning info for RANGE strategy: */
805 List *lowerdatums; /* List of PartitionRangeDatums */
806 List *upperdatums; /* List of PartitionRangeDatums */
808 int location; /* token location, or -1 if unknown */
809 } PartitionBoundSpec;
812 * PartitionRangeDatum - can be either a value or UNBOUNDED
814 * "value" is an A_Const in raw grammar output, a Const after analysis
816 typedef struct PartitionRangeDatum
820 bool infinite; /* true if UNBOUNDED */
821 Node *value; /* null if UNBOUNDED */
823 int location; /* token location, or -1 if unknown */
824 } PartitionRangeDatum;
827 * PartitionCmd - info for ALTER TABLE ATTACH/DETACH PARTITION commands
829 typedef struct PartitionCmd
832 RangeVar *name; /* name of partition to attach/detach */
833 PartitionBoundSpec *bound; /* FOR VALUES, if attaching */
836 /****************************************************************************
837 * Nodes for a Query tree
838 ****************************************************************************/
840 /*--------------------
842 * A range table is a List of RangeTblEntry nodes.
844 * A range table entry may represent a plain relation, a sub-select in
845 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax
846 * produces an RTE, not the implicit join resulting from multiple FROM
847 * items. This is because we only need the RTE to deal with SQL features
848 * like outer joins and join-output-column aliasing.) Other special
849 * RTE types also exist, as indicated by RTEKind.
851 * Note that we consider RTE_RELATION to cover anything that has a pg_class
852 * entry. relkind distinguishes the sub-cases.
854 * alias is an Alias node representing the AS alias-clause attached to the
855 * FROM expression, or NULL if no clause.
857 * eref is the table reference name and column reference names (either
858 * real or aliases). Note that system columns (OID etc) are not included
859 * in the column list.
860 * eref->aliasname is required to be present, and should generally be used
861 * to identify the RTE for error messages etc.
863 * In RELATION RTEs, the colnames in both alias and eref are indexed by
864 * physical attribute number; this means there must be colname entries for
865 * dropped columns. When building an RTE we insert empty strings ("") for
866 * dropped columns. Note however that a stored rule may have nonempty
867 * colnames for columns dropped since the rule was created (and for that
868 * matter the colnames might be out of date due to column renamings).
869 * The same comments apply to FUNCTION RTEs when a function's return type
870 * is a named composite type.
872 * In JOIN RTEs, the colnames in both alias and eref are one-to-one with
873 * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when
874 * those columns are known to be dropped at parse time. Again, however,
875 * a stored rule might contain entries for columns dropped since the rule
876 * was created. (This is only possible for columns not actually referenced
877 * in the rule.) When loading a stored rule, we replace the joinaliasvars
878 * items for any such columns with null pointers. (We can't simply delete
879 * them from the joinaliasvars list, because that would affect the attnums
880 * of Vars referencing the rest of the list.)
882 * inh is TRUE for relation references that should be expanded to include
883 * inheritance children, if the rel has any. This *must* be FALSE for
884 * RTEs other than RTE_RELATION entries.
886 * inFromCl marks those range variables that are listed in the FROM clause.
887 * It's false for RTEs that are added to a query behind the scenes, such
888 * as the NEW and OLD variables for a rule, or the subqueries of a UNION.
889 * This flag is not used anymore during parsing, since the parser now uses
890 * a separate "namespace" data structure to control visibility, but it is
891 * needed by ruleutils.c to determine whether RTEs should be shown in
892 * decompiled queries.
894 * requiredPerms and checkAsUser specify run-time access permissions
895 * checks to be performed at query startup. The user must have *all*
896 * of the permissions that are OR'd together in requiredPerms (zero
897 * indicates no permissions checking). If checkAsUser is not zero,
898 * then do the permissions checks using the access rights of that user,
899 * not the current effective user ID. (This allows rules to act as
900 * setuid gateways.) Permissions checks only apply to RELATION RTEs.
902 * For SELECT/INSERT/UPDATE permissions, if the user doesn't have
903 * table-wide permissions then it is sufficient to have the permissions
904 * on all columns identified in selectedCols (for SELECT) and/or
905 * insertedCols and/or updatedCols (INSERT with ON CONFLICT DO UPDATE may
906 * have all 3). selectedCols, insertedCols and updatedCols are bitmapsets,
907 * which cannot have negative integer members, so we subtract
908 * FirstLowInvalidHeapAttributeNumber from column numbers before storing
909 * them in these fields. A whole-row Var reference is represented by
910 * setting the bit for InvalidAttrNumber.
912 * securityQuals is a list of security barrier quals (boolean expressions),
913 * to be tested in the listed order before returning a row from the
914 * relation. It is always NIL in parser output. Entries are added by the
915 * rewriter to implement security-barrier views and/or row-level security.
916 * Note that the planner turns each boolean expression into an implicitly
917 * AND'ed sublist, as is its usual habit with qualification expressions.
918 *--------------------
922 RTE_RELATION, /* ordinary relation reference */
923 RTE_SUBQUERY, /* subquery in FROM */
925 RTE_FUNCTION, /* function in FROM */
926 RTE_TABLEFUNC, /* TableFunc(.., column list) */
927 RTE_VALUES, /* VALUES (<exprlist>), (<exprlist>), ... */
928 RTE_CTE, /* common table expr (WITH list element) */
929 RTE_NAMEDTUPLESTORE /* tuplestore, e.g. for AFTER triggers */
932 typedef struct RangeTblEntry
936 RTEKind rtekind; /* see above */
939 * XXX the fields applicable to only some rte kinds should be merged into
940 * a union. I didn't do this yet because the diffs would impact a lot of
941 * code that is being actively worked on. FIXME someday.
945 * Fields valid for a plain relation RTE (else zero):
947 * As a special case, RTE_NAMEDTUPLESTORE can also set relid to indicate
948 * that the tuple format of the tuplestore is the same as the referenced
949 * relation. This allows plans referencing AFTER trigger transition
950 * tables to be invalidated if the underlying table is altered.
952 Oid relid; /* OID of the relation */
953 char relkind; /* relation kind (see pg_class.relkind) */
954 struct TableSampleClause *tablesample; /* sampling info, or NULL */
957 * Fields valid for a subquery RTE (else NULL):
959 Query *subquery; /* the sub-query */
960 bool security_barrier; /* is from security_barrier view? */
963 * Fields valid for a join RTE (else NULL/zero):
965 * joinaliasvars is a list of (usually) Vars corresponding to the columns
966 * of the join result. An alias Var referencing column K of the join
967 * result can be replaced by the K'th element of joinaliasvars --- but to
968 * simplify the task of reverse-listing aliases correctly, we do not do
969 * that until planning time. In detail: an element of joinaliasvars can
970 * be a Var of one of the join's input relations, or such a Var with an
971 * implicit coercion to the join's output column type, or a COALESCE
972 * expression containing the two input column Vars (possibly coerced).
973 * Within a Query loaded from a stored rule, it is also possible for
974 * joinaliasvars items to be null pointers, which are placeholders for
975 * (necessarily unreferenced) columns dropped since the rule was made.
976 * Also, once planning begins, joinaliasvars items can be almost anything,
977 * as a result of subquery-flattening substitutions.
979 JoinType jointype; /* type of join */
980 List *joinaliasvars; /* list of alias-var expansions */
983 * Fields valid for a function RTE (else NIL/zero):
985 * When funcordinality is true, the eref->colnames list includes an alias
986 * for the ordinality column. The ordinality column is otherwise
987 * implicit, and must be accounted for "by hand" in places such as
990 List *functions; /* list of RangeTblFunction nodes */
991 bool funcordinality; /* is this called WITH ORDINALITY? */
994 * Fields valid for a TableFunc RTE (else NULL):
996 TableFunc *tablefunc;
999 * Fields valid for a values RTE (else NIL):
1001 List *values_lists; /* list of expression lists */
1004 * Fields valid for a CTE RTE (else NULL/zero):
1006 char *ctename; /* name of the WITH list item */
1007 Index ctelevelsup; /* number of query levels up */
1008 bool self_reference; /* is this a recursive self-reference? */
1011 * Fields valid for table functions, values, CTE and ENR RTEs (else NIL):
1013 * We need these for CTE RTEs so that the types of self-referential
1014 * columns are well-defined. For VALUES RTEs, storing these explicitly
1015 * saves having to re-determine the info by scanning the values_lists. For
1016 * ENRs, we store the types explicitly here (we could get the information
1017 * from the catalogs if 'relid' was supplied, but we'd still need these
1018 * for TupleDesc-based ENRs, so we might as well always store the type
1021 List *coltypes; /* OID list of column type OIDs */
1022 List *coltypmods; /* integer list of column typmods */
1023 List *colcollations; /* OID list of column collation OIDs */
1026 * Fields valid for ENR RTEs (else NULL/zero):
1028 char *enrname; /* name of ephemeral named relation */
1029 double enrtuples; /* estimated or actual from caller */
1032 * Fields valid in all RTEs:
1034 Alias *alias; /* user-written alias clause, if any */
1035 Alias *eref; /* expanded reference names */
1036 bool lateral; /* subquery, function, or values is LATERAL? */
1037 bool inh; /* inheritance requested? */
1038 bool inFromCl; /* present in FROM clause? */
1039 AclMode requiredPerms; /* bitmask of required access permissions */
1040 Oid checkAsUser; /* if valid, check access as this role */
1041 Bitmapset *selectedCols; /* columns needing SELECT permission */
1042 Bitmapset *insertedCols; /* columns needing INSERT permission */
1043 Bitmapset *updatedCols; /* columns needing UPDATE permission */
1044 List *securityQuals; /* security barrier quals to apply, if any */
1048 * RangeTblFunction -
1049 * RangeTblEntry subsidiary data for one function in a FUNCTION RTE.
1051 * If the function had a column definition list (required for an
1052 * otherwise-unspecified RECORD result), funccolnames lists the names given
1053 * in the definition list, funccoltypes lists their declared column types,
1054 * funccoltypmods lists their typmods, funccolcollations their collations.
1055 * Otherwise, those fields are NIL.
1057 * Notice we don't attempt to store info about the results of functions
1058 * returning named composite types, because those can change from time to
1059 * time. We do however remember how many columns we thought the type had
1060 * (including dropped columns!), so that we can successfully ignore any
1061 * columns added after the query was parsed.
1063 typedef struct RangeTblFunction
1067 Node *funcexpr; /* expression tree for func call */
1068 int funccolcount; /* number of columns it contributes to RTE */
1069 /* These fields record the contents of a column definition list, if any: */
1070 List *funccolnames; /* column names (list of String) */
1071 List *funccoltypes; /* OID list of column type OIDs */
1072 List *funccoltypmods; /* integer list of column typmods */
1073 List *funccolcollations; /* OID list of column collation OIDs */
1074 /* This is set during planning for use by the executor: */
1075 Bitmapset *funcparams; /* PARAM_EXEC Param IDs affecting this func */
1079 * TableSampleClause - TABLESAMPLE appearing in a transformed FROM clause
1081 * Unlike RangeTableSample, this is a subnode of the relevant RangeTblEntry.
1083 typedef struct TableSampleClause
1086 Oid tsmhandler; /* OID of the tablesample handler function */
1087 List *args; /* tablesample argument expression(s) */
1088 Expr *repeatable; /* REPEATABLE expression, or NULL if none */
1089 } TableSampleClause;
1093 * representation of WITH CHECK OPTION checks to be applied to new tuples
1094 * when inserting/updating an auto-updatable view, or RLS WITH CHECK
1095 * policies to be applied when inserting/updating a relation with RLS.
1097 typedef enum WCOKind
1099 WCO_VIEW_CHECK, /* WCO on an auto-updatable view */
1100 WCO_RLS_INSERT_CHECK, /* RLS INSERT WITH CHECK policy */
1101 WCO_RLS_UPDATE_CHECK, /* RLS UPDATE WITH CHECK policy */
1102 WCO_RLS_CONFLICT_CHECK /* RLS ON CONFLICT DO UPDATE USING policy */
1105 typedef struct WithCheckOption
1108 WCOKind kind; /* kind of WCO */
1109 char *relname; /* name of relation that specified the WCO */
1110 char *polname; /* name of RLS policy being checked */
1111 Node *qual; /* constraint qual to check */
1112 bool cascaded; /* true for a cascaded WCO on a view */
1117 * representation of ORDER BY, GROUP BY, PARTITION BY,
1118 * DISTINCT, DISTINCT ON items
1120 * You might think that ORDER BY is only interested in defining ordering,
1121 * and GROUP/DISTINCT are only interested in defining equality. However,
1122 * one way to implement grouping is to sort and then apply a "uniq"-like
1123 * filter. So it's also interesting to keep track of possible sort operators
1124 * for GROUP/DISTINCT, and in particular to try to sort for the grouping
1125 * in a way that will also yield a requested ORDER BY ordering. So we need
1126 * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates
1127 * the decision to give them the same representation.
1129 * tleSortGroupRef must match ressortgroupref of exactly one entry of the
1130 * query's targetlist; that is the expression to be sorted or grouped by.
1131 * eqop is the OID of the equality operator.
1132 * sortop is the OID of the ordering operator (a "<" or ">" operator),
1133 * or InvalidOid if not available.
1134 * nulls_first means about what you'd expect. If sortop is InvalidOid
1135 * then nulls_first is meaningless and should be set to false.
1136 * hashable is TRUE if eqop is hashable (note this condition also depends
1137 * on the datatype of the input expression).
1139 * In an ORDER BY item, all fields must be valid. (The eqop isn't essential
1140 * here, but it's cheap to get it along with the sortop, and requiring it
1141 * to be valid eases comparisons to grouping items.) Note that this isn't
1142 * actually enough information to determine an ordering: if the sortop is
1143 * collation-sensitive, a collation OID is needed too. We don't store the
1144 * collation in SortGroupClause because it's not available at the time the
1145 * parser builds the SortGroupClause; instead, consult the exposed collation
1146 * of the referenced targetlist expression to find out what it is.
1148 * In a grouping item, eqop must be valid. If the eqop is a btree equality
1149 * operator, then sortop should be set to a compatible ordering operator.
1150 * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that
1151 * the query presents for the same tlist item. If there is none, we just
1152 * use the default ordering op for the datatype.
1154 * If the tlist item's type has a hash opclass but no btree opclass, then
1155 * we will set eqop to the hash equality operator, sortop to InvalidOid,
1156 * and nulls_first to false. A grouping item of this kind can only be
1157 * implemented by hashing, and of course it'll never match an ORDER BY item.
1159 * The hashable flag is provided since we generally have the requisite
1160 * information readily available when the SortGroupClause is constructed,
1161 * and it's relatively expensive to get it again later. Note there is no
1162 * need for a "sortable" flag since OidIsValid(sortop) serves the purpose.
1164 * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses.
1165 * In SELECT DISTINCT, the distinctClause list is as long or longer than the
1166 * sortClause list, while in SELECT DISTINCT ON it's typically shorter.
1167 * The two lists must match up to the end of the shorter one --- the parser
1168 * rearranges the distinctClause if necessary to make this true. (This
1169 * restriction ensures that only one sort step is needed to both satisfy the
1170 * ORDER BY and set up for the Unique step. This is semantically necessary
1171 * for DISTINCT ON, and presents no real drawback for DISTINCT.)
1173 typedef struct SortGroupClause
1176 Index tleSortGroupRef; /* reference into targetlist */
1177 Oid eqop; /* the equality operator ('=' op) */
1178 Oid sortop; /* the ordering operator ('<' op), or 0 */
1179 bool nulls_first; /* do NULLs come before normal values? */
1180 bool hashable; /* can eqop be implemented by hashing? */
1185 * representation of CUBE, ROLLUP and GROUPING SETS clauses
1187 * In a Query with grouping sets, the groupClause contains a flat list of
1188 * SortGroupClause nodes for each distinct expression used. The actual
1189 * structure of the GROUP BY clause is given by the groupingSets tree.
1191 * In the raw parser output, GroupingSet nodes (of all types except SIMPLE
1192 * which is not used) are potentially mixed in with the expressions in the
1193 * groupClause of the SelectStmt. (An expression can't contain a GroupingSet,
1194 * but a list may mix GroupingSet and expression nodes.) At this stage, the
1195 * content of each node is a list of expressions, some of which may be RowExprs
1196 * which represent sublists rather than actual row constructors, and nested
1197 * GroupingSet nodes where legal in the grammar. The structure directly
1198 * reflects the query syntax.
1200 * In parse analysis, the transformed expressions are used to build the tlist
1201 * and groupClause list (of SortGroupClause nodes), and the groupingSets tree
1202 * is eventually reduced to a fixed format:
1204 * EMPTY nodes represent (), and obviously have no content
1206 * SIMPLE nodes represent a list of one or more expressions to be treated as an
1207 * atom by the enclosing structure; the content is an integer list of
1208 * ressortgroupref values (see SortGroupClause)
1210 * CUBE and ROLLUP nodes contain a list of one or more SIMPLE nodes.
1212 * SETS nodes contain a list of EMPTY, SIMPLE, CUBE or ROLLUP nodes, but after
1213 * parse analysis they cannot contain more SETS nodes; enough of the syntactic
1214 * transforms of the spec have been applied that we no longer have arbitrarily
1215 * deep nesting (though we still preserve the use of cube/rollup).
1217 * Note that if the groupingSets tree contains no SIMPLE nodes (only EMPTY
1218 * nodes at the leaves), then the groupClause will be empty, but this is still
1219 * an aggregation query (similar to using aggs or HAVING without GROUP BY).
1221 * As an example, the following clause:
1223 * GROUP BY GROUPING SETS ((a,b), CUBE(c,(d,e)))
1225 * looks like this after raw parsing:
1227 * SETS( RowExpr(a,b) , CUBE( c, RowExpr(d,e) ) )
1229 * and parse analysis converts it to:
1231 * SETS( SIMPLE(1,2), CUBE( SIMPLE(3), SIMPLE(4,5) ) )
1236 GROUPING_SET_SIMPLE,
1237 GROUPING_SET_ROLLUP,
1242 typedef struct GroupingSet
1245 GroupingSetKind kind;
1252 * transformed representation of WINDOW and OVER clauses
1254 * A parsed Query's windowClause list contains these structs. "name" is set
1255 * if the clause originally came from WINDOW, and is NULL if it originally
1256 * was an OVER clause (but note that we collapse out duplicate OVERs).
1257 * partitionClause and orderClause are lists of SortGroupClause structs.
1258 * winref is an ID number referenced by WindowFunc nodes; it must be unique
1259 * among the members of a Query's windowClause list.
1260 * When refname isn't null, the partitionClause is always copied from there;
1261 * the orderClause might or might not be copied (see copiedOrder); the framing
1262 * options are never copied, per spec.
1264 typedef struct WindowClause
1267 char *name; /* window name (NULL in an OVER clause) */
1268 char *refname; /* referenced window name, if any */
1269 List *partitionClause; /* PARTITION BY list */
1270 List *orderClause; /* ORDER BY list */
1271 int frameOptions; /* frame_clause options, see WindowDef */
1272 Node *startOffset; /* expression for starting bound, if any */
1273 Node *endOffset; /* expression for ending bound, if any */
1274 Index winref; /* ID referenced by window functions */
1275 bool copiedOrder; /* did we copy orderClause from refname? */
1280 * parser output representation of FOR [KEY] UPDATE/SHARE clauses
1282 * Query.rowMarks contains a separate RowMarkClause node for each relation
1283 * identified as a FOR [KEY] UPDATE/SHARE target. If one of these clauses
1284 * is applied to a subquery, we generate RowMarkClauses for all normal and
1285 * subquery rels in the subquery, but they are marked pushedDown = true to
1286 * distinguish them from clauses that were explicitly written at this query
1287 * level. Also, Query.hasForUpdate tells whether there were explicit FOR
1288 * UPDATE/SHARE/KEY SHARE clauses in the current query level.
1290 typedef struct RowMarkClause
1293 Index rti; /* range table index of target relation */
1294 LockClauseStrength strength;
1295 LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */
1296 bool pushedDown; /* pushed down from higher query level? */
1301 * representation of WITH clause
1303 * Note: WithClause does not propagate into the Query representation;
1304 * but CommonTableExpr does.
1306 typedef struct WithClause
1309 List *ctes; /* list of CommonTableExprs */
1310 bool recursive; /* true = WITH RECURSIVE */
1311 int location; /* token location, or -1 if unknown */
1316 * ON CONFLICT unique index inference clause
1318 * Note: InferClause does not propagate into the Query representation.
1320 typedef struct InferClause
1323 List *indexElems; /* IndexElems to infer unique index */
1324 Node *whereClause; /* qualification (partial-index predicate) */
1325 char *conname; /* Constraint name, or NULL if unnamed */
1326 int location; /* token location, or -1 if unknown */
1330 * OnConflictClause -
1331 * representation of ON CONFLICT clause
1333 * Note: OnConflictClause does not propagate into the Query representation.
1335 typedef struct OnConflictClause
1338 OnConflictAction action; /* DO NOTHING or UPDATE? */
1339 InferClause *infer; /* Optional index inference clause */
1340 List *targetList; /* the target list (of ResTarget) */
1341 Node *whereClause; /* qualifications */
1342 int location; /* token location, or -1 if unknown */
1347 * representation of WITH list element
1349 * We don't currently support the SEARCH or CYCLE clause.
1351 typedef struct CommonTableExpr
1354 char *ctename; /* query name (never qualified) */
1355 List *aliascolnames; /* optional list of column names */
1356 /* SelectStmt/InsertStmt/etc before parse analysis, Query afterwards: */
1357 Node *ctequery; /* the CTE's subquery */
1358 int location; /* token location, or -1 if unknown */
1359 /* These fields are set during parse analysis: */
1360 bool cterecursive; /* is this CTE actually recursive? */
1361 int cterefcount; /* number of RTEs referencing this CTE
1362 * (excluding internal self-references) */
1363 List *ctecolnames; /* list of output column names */
1364 List *ctecoltypes; /* OID list of output column type OIDs */
1365 List *ctecoltypmods; /* integer list of output column typmods */
1366 List *ctecolcollations; /* OID list of column collation OIDs */
1369 /* Convenience macro to get the output tlist of a CTE's query */
1370 #define GetCTETargetList(cte) \
1371 (AssertMacro(IsA((cte)->ctequery, Query)), \
1372 ((Query *) (cte)->ctequery)->commandType == CMD_SELECT ? \
1373 ((Query *) (cte)->ctequery)->targetList : \
1374 ((Query *) (cte)->ctequery)->returningList)
1377 * TriggerTransition -
1378 * representation of transition row or table naming clause
1380 * Only transition tables are initially supported in the syntax, and only for
1381 * AFTER triggers, but other permutations are accepted by the parser so we can
1382 * give a meaningful message from C code.
1384 typedef struct TriggerTransition
1390 } TriggerTransition;
1392 /*****************************************************************************
1393 * Raw Grammar Output Statements
1394 *****************************************************************************/
1397 * RawStmt --- container for any one statement's raw parse tree
1399 * Parse analysis converts a raw parse tree headed by a RawStmt node into
1400 * an analyzed statement headed by a Query node. For optimizable statements,
1401 * the conversion is complex. For utility statements, the parser usually just
1402 * transfers the raw parse tree (sans RawStmt) into the utilityStmt field of
1403 * the Query node, and all the useful work happens at execution time.
1405 * stmt_location/stmt_len identify the portion of the source text string
1406 * containing this raw statement (useful for multi-statement strings).
1408 typedef struct RawStmt
1411 Node *stmt; /* raw parse tree */
1412 int stmt_location; /* start location, or -1 if unknown */
1413 int stmt_len; /* length in bytes; 0 means "rest of string" */
1416 /*****************************************************************************
1417 * Optimizable Statements
1418 *****************************************************************************/
1420 /* ----------------------
1423 * The source expression is represented by SelectStmt for both the
1424 * SELECT and VALUES cases. If selectStmt is NULL, then the query
1425 * is INSERT ... DEFAULT VALUES.
1426 * ----------------------
1428 typedef struct InsertStmt
1431 RangeVar *relation; /* relation to insert into */
1432 List *cols; /* optional: names of the target columns */
1433 Node *selectStmt; /* the source SELECT/VALUES, or NULL */
1434 OnConflictClause *onConflictClause; /* ON CONFLICT clause */
1435 List *returningList; /* list of expressions to return */
1436 WithClause *withClause; /* WITH clause */
1437 OverridingKind override; /* OVERRIDING clause */
1440 /* ----------------------
1442 * ----------------------
1444 typedef struct DeleteStmt
1447 RangeVar *relation; /* relation to delete from */
1448 List *usingClause; /* optional using clause for more tables */
1449 Node *whereClause; /* qualifications */
1450 List *returningList; /* list of expressions to return */
1451 WithClause *withClause; /* WITH clause */
1454 /* ----------------------
1456 * ----------------------
1458 typedef struct UpdateStmt
1461 RangeVar *relation; /* relation to update */
1462 List *targetList; /* the target list (of ResTarget) */
1463 Node *whereClause; /* qualifications */
1464 List *fromClause; /* optional from clause for more tables */
1465 List *returningList; /* list of expressions to return */
1466 WithClause *withClause; /* WITH clause */
1469 /* ----------------------
1472 * A "simple" SELECT is represented in the output of gram.y by a single
1473 * SelectStmt node; so is a VALUES construct. A query containing set
1474 * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
1475 * nodes, in which the leaf nodes are component SELECTs and the internal nodes
1476 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node
1477 * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
1478 * LIMIT, etc, clause values into a SELECT statement without worrying
1479 * whether it is a simple or compound SELECT.
1480 * ----------------------
1482 typedef enum SetOperation
1490 typedef struct SelectStmt
1495 * These fields are used only in "leaf" SelectStmts.
1497 List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
1498 * lcons(NIL,NIL) for all (SELECT DISTINCT) */
1499 IntoClause *intoClause; /* target for SELECT INTO */
1500 List *targetList; /* the target list (of ResTarget) */
1501 List *fromClause; /* the FROM clause */
1502 Node *whereClause; /* WHERE qualification */
1503 List *groupClause; /* GROUP BY clauses */
1504 Node *havingClause; /* HAVING conditional-expression */
1505 List *windowClause; /* WINDOW window_name AS (...), ... */
1508 * In a "leaf" node representing a VALUES list, the above fields are all
1509 * null, and instead this field is set. Note that the elements of the
1510 * sublists are just expressions, without ResTarget decoration. Also note
1511 * that a list element can be DEFAULT (represented as a SetToDefault
1512 * node), regardless of the context of the VALUES list. It's up to parse
1513 * analysis to reject that where not valid.
1515 List *valuesLists; /* untransformed list of expression lists */
1518 * These fields are used in both "leaf" SelectStmts and upper-level
1521 List *sortClause; /* sort clause (a list of SortBy's) */
1522 Node *limitOffset; /* # of result tuples to skip */
1523 Node *limitCount; /* # of result tuples to return */
1524 List *lockingClause; /* FOR UPDATE (list of LockingClause's) */
1525 WithClause *withClause; /* WITH clause */
1528 * These fields are used only in upper-level SelectStmts.
1530 SetOperation op; /* type of set op */
1531 bool all; /* ALL specified? */
1532 struct SelectStmt *larg; /* left child */
1533 struct SelectStmt *rarg; /* right child */
1534 /* Eventually add fields for CORRESPONDING spec here */
1538 /* ----------------------
1539 * Set Operation node for post-analysis query trees
1541 * After parse analysis, a SELECT with set operations is represented by a
1542 * top-level Query node containing the leaf SELECTs as subqueries in its
1543 * range table. Its setOperations field shows the tree of set operations,
1544 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
1545 * nodes replaced by SetOperationStmt nodes. Information about the output
1546 * column types is added, too. (Note that the child nodes do not necessarily
1547 * produce these types directly, but we've checked that their output types
1548 * can be coerced to the output column type.) Also, if it's not UNION ALL,
1549 * information about the types' sort/group semantics is provided in the form
1550 * of a SortGroupClause list (same representation as, eg, DISTINCT).
1551 * The resolved common column collations are provided too; but note that if
1552 * it's not UNION ALL, it's okay for a column to not have a common collation,
1553 * so a member of the colCollations list could be InvalidOid even though the
1554 * column has a collatable type.
1555 * ----------------------
1557 typedef struct SetOperationStmt
1560 SetOperation op; /* type of set op */
1561 bool all; /* ALL specified? */
1562 Node *larg; /* left child */
1563 Node *rarg; /* right child */
1564 /* Eventually add fields for CORRESPONDING spec here */
1566 /* Fields derived during parse analysis: */
1567 List *colTypes; /* OID list of output column type OIDs */
1568 List *colTypmods; /* integer list of output column typmods */
1569 List *colCollations; /* OID list of output column collation OIDs */
1570 List *groupClauses; /* a list of SortGroupClause's */
1571 /* groupClauses is NIL if UNION ALL, but must be set otherwise */
1575 /*****************************************************************************
1576 * Other Statements (no optimizations required)
1578 * These are not touched by parser/analyze.c except to put them into
1579 * the utilityStmt field of a Query. This is eventually passed to
1580 * ProcessUtility (by-passing rewriting and planning). Some of the
1581 * statements do need attention from parse analysis, and this is
1582 * done by routines in parser/parse_utilcmd.c after ProcessUtility
1583 * receives the command for execution.
1584 * DECLARE CURSOR, EXPLAIN, and CREATE TABLE AS are special cases:
1585 * they contain optimizable statements, which get processed normally
1586 * by parser/analyze.c.
1587 *****************************************************************************/
1590 * When a command can act on several kinds of objects with only one
1591 * parse structure required, use these constants to designate the
1592 * object type. Note that commands typically don't support all the types.
1595 typedef enum ObjectType
1597 OBJECT_ACCESS_METHOD,
1601 OBJECT_ATTRIBUTE, /* type's attribute, when distinct from column */
1610 OBJECT_DOMCONSTRAINT,
1611 OBJECT_EVENT_TRIGGER,
1614 OBJECT_FOREIGN_SERVER,
1615 OBJECT_FOREIGN_TABLE,
1626 OBJECT_PUBLICATION_REL,
1631 OBJECT_SUBSCRIPTION,
1632 OBJECT_STATISTIC_EXT,
1633 OBJECT_TABCONSTRAINT,
1638 OBJECT_TSCONFIGURATION,
1639 OBJECT_TSDICTIONARY,
1643 OBJECT_USER_MAPPING,
1647 /* ----------------------
1648 * Create Schema Statement
1650 * NOTE: the schemaElts list contains raw parsetrees for component statements
1651 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
1652 * executed after the schema itself is created.
1653 * ----------------------
1655 typedef struct CreateSchemaStmt
1658 char *schemaname; /* the name of the schema to create */
1659 RoleSpec *authrole; /* the owner of the created schema */
1660 List *schemaElts; /* schema components (list of parsenodes) */
1661 bool if_not_exists; /* just do nothing if schema already exists? */
1664 typedef enum DropBehavior
1666 DROP_RESTRICT, /* drop fails if any dependent objects */
1667 DROP_CASCADE /* remove dependent objects too */
1670 /* ----------------------
1672 * ----------------------
1674 typedef struct AlterTableStmt
1677 RangeVar *relation; /* table to work on */
1678 List *cmds; /* list of subcommands */
1679 ObjectType relkind; /* type of object */
1680 bool missing_ok; /* skip error if table missing */
1683 typedef enum AlterTableType
1685 AT_AddColumn, /* add column */
1686 AT_AddColumnRecurse, /* internal to commands/tablecmds.c */
1687 AT_AddColumnToView, /* implicitly via CREATE OR REPLACE VIEW */
1688 AT_ColumnDefault, /* alter column default */
1689 AT_DropNotNull, /* alter column drop not null */
1690 AT_SetNotNull, /* alter column set not null */
1691 AT_SetStatistics, /* alter column set statistics */
1692 AT_SetOptions, /* alter column set ( options ) */
1693 AT_ResetOptions, /* alter column reset ( options ) */
1694 AT_SetStorage, /* alter column set storage */
1695 AT_DropColumn, /* drop column */
1696 AT_DropColumnRecurse, /* internal to commands/tablecmds.c */
1697 AT_AddIndex, /* add index */
1698 AT_ReAddIndex, /* internal to commands/tablecmds.c */
1699 AT_AddConstraint, /* add constraint */
1700 AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */
1701 AT_ReAddConstraint, /* internal to commands/tablecmds.c */
1702 AT_AlterConstraint, /* alter constraint */
1703 AT_ValidateConstraint, /* validate constraint */
1704 AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */
1705 AT_ProcessedConstraint, /* pre-processed add constraint (local in
1706 * parser/parse_utilcmd.c) */
1707 AT_AddIndexConstraint, /* add constraint using existing index */
1708 AT_DropConstraint, /* drop constraint */
1709 AT_DropConstraintRecurse, /* internal to commands/tablecmds.c */
1710 AT_ReAddComment, /* internal to commands/tablecmds.c */
1711 AT_AlterColumnType, /* alter column type */
1712 AT_AlterColumnGenericOptions, /* alter column OPTIONS (...) */
1713 AT_ChangeOwner, /* change owner */
1714 AT_ClusterOn, /* CLUSTER ON */
1715 AT_DropCluster, /* SET WITHOUT CLUSTER */
1716 AT_SetLogged, /* SET LOGGED */
1717 AT_SetUnLogged, /* SET UNLOGGED */
1718 AT_AddOids, /* SET WITH OIDS */
1719 AT_AddOidsRecurse, /* internal to commands/tablecmds.c */
1720 AT_DropOids, /* SET WITHOUT OIDS */
1721 AT_SetTableSpace, /* SET TABLESPACE */
1722 AT_SetRelOptions, /* SET (...) -- AM specific parameters */
1723 AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */
1724 AT_ReplaceRelOptions, /* replace reloption list in its entirety */
1725 AT_EnableTrig, /* ENABLE TRIGGER name */
1726 AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */
1727 AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */
1728 AT_DisableTrig, /* DISABLE TRIGGER name */
1729 AT_EnableTrigAll, /* ENABLE TRIGGER ALL */
1730 AT_DisableTrigAll, /* DISABLE TRIGGER ALL */
1731 AT_EnableTrigUser, /* ENABLE TRIGGER USER */
1732 AT_DisableTrigUser, /* DISABLE TRIGGER USER */
1733 AT_EnableRule, /* ENABLE RULE name */
1734 AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */
1735 AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */
1736 AT_DisableRule, /* DISABLE RULE name */
1737 AT_AddInherit, /* INHERIT parent */
1738 AT_DropInherit, /* NO INHERIT parent */
1739 AT_AddOf, /* OF <type_name> */
1740 AT_DropOf, /* NOT OF */
1741 AT_ReplicaIdentity, /* REPLICA IDENTITY */
1742 AT_EnableRowSecurity, /* ENABLE ROW SECURITY */
1743 AT_DisableRowSecurity, /* DISABLE ROW SECURITY */
1744 AT_ForceRowSecurity, /* FORCE ROW SECURITY */
1745 AT_NoForceRowSecurity, /* NO FORCE ROW SECURITY */
1746 AT_GenericOptions, /* OPTIONS (...) */
1747 AT_AttachPartition, /* ATTACH PARTITION */
1748 AT_DetachPartition, /* DETACH PARTITION */
1749 AT_AddIdentity, /* ADD IDENTITY */
1750 AT_SetIdentity, /* SET identity column options */
1751 AT_DropIdentity /* DROP IDENTITY */
1754 typedef struct ReplicaIdentityStmt
1759 } ReplicaIdentityStmt;
1761 typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */
1764 AlterTableType subtype; /* Type of table alteration to apply */
1765 char *name; /* column, constraint, or trigger to act on,
1768 Node *def; /* definition of new column, index,
1769 * constraint, or parent table */
1770 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
1771 bool missing_ok; /* skip error if missing? */
1775 /* ----------------------
1777 * ----------------------
1779 typedef struct AlterCollationStmt
1783 } AlterCollationStmt;
1786 /* ----------------------
1789 * The fields are used in different ways by the different variants of
1791 * ----------------------
1793 typedef struct AlterDomainStmt
1796 char subtype; /*------------
1797 * T = alter column default
1798 * N = alter column drop not null
1799 * O = alter column set not null
1800 * C = add constraint
1801 * X = drop constraint
1804 List *typeName; /* domain to work on */
1805 char *name; /* column or constraint name to act on */
1806 Node *def; /* definition of default or constraint */
1807 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
1808 bool missing_ok; /* skip error if missing? */
1812 /* ----------------------
1813 * Grant|Revoke Statement
1814 * ----------------------
1816 typedef enum GrantTargetType
1818 ACL_TARGET_OBJECT, /* grant on specific named object(s) */
1819 ACL_TARGET_ALL_IN_SCHEMA, /* grant on all objects in given schema(s) */
1820 ACL_TARGET_DEFAULTS /* ALTER DEFAULT PRIVILEGES */
1823 typedef enum GrantObjectType
1825 ACL_OBJECT_COLUMN, /* column */
1826 ACL_OBJECT_RELATION, /* table, view */
1827 ACL_OBJECT_SEQUENCE, /* sequence */
1828 ACL_OBJECT_DATABASE, /* database */
1829 ACL_OBJECT_DOMAIN, /* domain */
1830 ACL_OBJECT_FDW, /* foreign-data wrapper */
1831 ACL_OBJECT_FOREIGN_SERVER, /* foreign server */
1832 ACL_OBJECT_FUNCTION, /* function */
1833 ACL_OBJECT_LANGUAGE, /* procedural language */
1834 ACL_OBJECT_LARGEOBJECT, /* largeobject */
1835 ACL_OBJECT_NAMESPACE, /* namespace */
1836 ACL_OBJECT_TABLESPACE, /* tablespace */
1837 ACL_OBJECT_TYPE /* type */
1840 typedef struct GrantStmt
1843 bool is_grant; /* true = GRANT, false = REVOKE */
1844 GrantTargetType targtype; /* type of the grant target */
1845 GrantObjectType objtype; /* kind of object being operated on */
1846 List *objects; /* list of RangeVar nodes, ObjectWithArgs
1847 * nodes, or plain names (as Value strings) */
1848 List *privileges; /* list of AccessPriv nodes */
1849 /* privileges == NIL denotes ALL PRIVILEGES */
1850 List *grantees; /* list of RoleSpec nodes */
1851 bool grant_option; /* grant or revoke grant option */
1852 DropBehavior behavior; /* drop behavior (for REVOKE) */
1856 * Note: ObjectWithArgs carries only the types of the input parameters of the
1857 * function. So it is sufficient to identify an existing function, but it
1858 * is not enough info to define a function nor to call it.
1860 typedef struct ObjectWithArgs
1863 List *objname; /* qualified name of function/operator */
1864 List *objargs; /* list of Typename nodes */
1865 bool args_unspecified; /* argument list was omitted, so name must
1866 * be unique (note that objargs == NIL
1867 * means zero args) */
1871 * An access privilege, with optional list of column names
1872 * priv_name == NULL denotes ALL PRIVILEGES (only used with a column list)
1873 * cols == NIL denotes "all columns"
1874 * Note that simple "ALL PRIVILEGES" is represented as a NIL list, not
1875 * an AccessPriv with both fields null.
1877 typedef struct AccessPriv
1880 char *priv_name; /* string name of privilege */
1881 List *cols; /* list of Value strings */
1884 /* ----------------------
1885 * Grant/Revoke Role Statement
1887 * Note: because of the parsing ambiguity with the GRANT <privileges>
1888 * statement, granted_roles is a list of AccessPriv; the execution code
1889 * should complain if any column lists appear. grantee_roles is a list
1890 * of role names, as Value strings.
1891 * ----------------------
1893 typedef struct GrantRoleStmt
1896 List *granted_roles; /* list of roles to be granted/revoked */
1897 List *grantee_roles; /* list of member roles to add/delete */
1898 bool is_grant; /* true = GRANT, false = REVOKE */
1899 bool admin_opt; /* with admin option */
1900 RoleSpec *grantor; /* set grantor to other than current role */
1901 DropBehavior behavior; /* drop behavior (for REVOKE) */
1904 /* ----------------------
1905 * Alter Default Privileges Statement
1906 * ----------------------
1908 typedef struct AlterDefaultPrivilegesStmt
1911 List *options; /* list of DefElem */
1912 GrantStmt *action; /* GRANT/REVOKE action (with objects=NIL) */
1913 } AlterDefaultPrivilegesStmt;
1915 /* ----------------------
1918 * We support "COPY relation FROM file", "COPY relation TO file", and
1919 * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation"
1920 * and "query" must be non-NULL.
1921 * ----------------------
1923 typedef struct CopyStmt
1926 RangeVar *relation; /* the relation to copy */
1927 Node *query; /* the query (SELECT or DML statement with
1928 * RETURNING) to copy, as a raw parse tree */
1929 List *attlist; /* List of column names (as Strings), or NIL
1930 * for all columns */
1931 bool is_from; /* TO or FROM */
1932 bool is_program; /* is 'filename' a program to popen? */
1933 char *filename; /* filename, or NULL for STDIN/STDOUT */
1934 List *options; /* List of DefElem nodes */
1937 /* ----------------------
1938 * SET Statement (includes RESET)
1940 * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
1941 * preserve the distinction in VariableSetKind for CreateCommandTag().
1942 * ----------------------
1946 VAR_SET_VALUE, /* SET var = value */
1947 VAR_SET_DEFAULT, /* SET var TO DEFAULT */
1948 VAR_SET_CURRENT, /* SET var FROM CURRENT */
1949 VAR_SET_MULTI, /* special case for SET TRANSACTION ... */
1950 VAR_RESET, /* RESET var */
1951 VAR_RESET_ALL /* RESET ALL */
1954 typedef struct VariableSetStmt
1957 VariableSetKind kind;
1958 char *name; /* variable to be set */
1959 List *args; /* List of A_Const nodes */
1960 bool is_local; /* SET LOCAL? */
1963 /* ----------------------
1965 * ----------------------
1967 typedef struct VariableShowStmt
1973 /* ----------------------
1974 * Create Table Statement
1976 * NOTE: in the raw gram.y output, ColumnDef and Constraint nodes are
1977 * intermixed in tableElts, and constraints is NIL. After parse analysis,
1978 * tableElts contains just ColumnDefs, and constraints contains just
1979 * Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
1981 * ----------------------
1984 typedef struct CreateStmt
1987 RangeVar *relation; /* relation to create */
1988 List *tableElts; /* column definitions (list of ColumnDef) */
1989 List *inhRelations; /* relations to inherit from (list of
1991 PartitionBoundSpec *partbound; /* FOR VALUES clause */
1992 PartitionSpec *partspec; /* PARTITION BY clause */
1993 TypeName *ofTypename; /* OF typename */
1994 List *constraints; /* constraints (list of Constraint nodes) */
1995 List *options; /* options from WITH clause */
1996 OnCommitAction oncommit; /* what do we do at COMMIT? */
1997 char *tablespacename; /* table space to use, or NULL */
1998 bool if_not_exists; /* just do nothing if it already exists? */
2002 * Definitions for constraints in CreateStmt
2004 * Note that column defaults are treated as a type of constraint,
2005 * even though that's a bit odd semantically.
2007 * For constraints that use expressions (CONSTR_CHECK, CONSTR_DEFAULT)
2008 * we may have the expression in either "raw" form (an untransformed
2009 * parse tree) or "cooked" form (the nodeToString representation of
2010 * an executable expression tree), depending on how this Constraint
2011 * node was created (by parsing, or by inheritance from an existing
2012 * relation). We should never have both in the same node!
2014 * FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
2015 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
2016 * stored into pg_constraint.confmatchtype. Changing the code values may
2017 * require an initdb!
2019 * If skip_validation is true then we skip checking that the existing rows
2020 * in the table satisfy the constraint, and just install the catalog entries
2021 * for the constraint. A new FK constraint is marked as valid iff
2022 * initially_valid is true. (Usually skip_validation and initially_valid
2023 * are inverses, but we can set both true if the table is known empty.)
2025 * Constraint attributes (DEFERRABLE etc) are initially represented as
2026 * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes
2027 * a pass through the constraints list to insert the info into the appropriate
2032 typedef enum ConstrType /* types of constraints */
2034 CONSTR_NULL, /* not standard SQL, but a lot of people
2044 CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
2045 CONSTR_ATTR_NOT_DEFERRABLE,
2046 CONSTR_ATTR_DEFERRED,
2047 CONSTR_ATTR_IMMEDIATE
2050 /* Foreign key action codes */
2051 #define FKCONSTR_ACTION_NOACTION 'a'
2052 #define FKCONSTR_ACTION_RESTRICT 'r'
2053 #define FKCONSTR_ACTION_CASCADE 'c'
2054 #define FKCONSTR_ACTION_SETNULL 'n'
2055 #define FKCONSTR_ACTION_SETDEFAULT 'd'
2057 /* Foreign key matchtype codes */
2058 #define FKCONSTR_MATCH_FULL 'f'
2059 #define FKCONSTR_MATCH_PARTIAL 'p'
2060 #define FKCONSTR_MATCH_SIMPLE 's'
2062 typedef struct Constraint
2065 ConstrType contype; /* see above */
2067 /* Fields used for most/all constraint types: */
2068 char *conname; /* Constraint name, or NULL if unnamed */
2069 bool deferrable; /* DEFERRABLE? */
2070 bool initdeferred; /* INITIALLY DEFERRED? */
2071 int location; /* token location, or -1 if unknown */
2073 /* Fields used for constraints with expressions (CHECK and DEFAULT): */
2074 bool is_no_inherit; /* is constraint non-inheritable? */
2075 Node *raw_expr; /* expr, as untransformed parse tree */
2076 char *cooked_expr; /* expr, as nodeToString representation */
2077 char generated_when;
2079 /* Fields used for unique constraints (UNIQUE and PRIMARY KEY): */
2080 List *keys; /* String nodes naming referenced column(s) */
2082 /* Fields used for EXCLUSION constraints: */
2083 List *exclusions; /* list of (IndexElem, operator name) pairs */
2085 /* Fields used for index constraints (UNIQUE, PRIMARY KEY, EXCLUSION): */
2086 List *options; /* options from WITH clause */
2087 char *indexname; /* existing index to use; otherwise NULL */
2088 char *indexspace; /* index tablespace; NULL for default */
2089 /* These could be, but currently are not, used for UNIQUE/PKEY: */
2090 char *access_method; /* index access method; NULL for default */
2091 Node *where_clause; /* partial index predicate */
2093 /* Fields used for FOREIGN KEY constraints: */
2094 RangeVar *pktable; /* Primary key table */
2095 List *fk_attrs; /* Attributes of foreign key */
2096 List *pk_attrs; /* Corresponding attrs in PK table */
2097 char fk_matchtype; /* FULL, PARTIAL, SIMPLE */
2098 char fk_upd_action; /* ON UPDATE action */
2099 char fk_del_action; /* ON DELETE action */
2100 List *old_conpfeqop; /* pg_constraint.conpfeqop of my former self */
2101 Oid old_pktable_oid; /* pg_constraint.confrelid of my former
2104 /* Fields used for constraints that allow a NOT VALID specification */
2105 bool skip_validation; /* skip validation of existing rows? */
2106 bool initially_valid; /* mark the new constraint as valid? */
2109 /* ----------------------
2110 * Create/Drop Table Space Statements
2111 * ----------------------
2114 typedef struct CreateTableSpaceStmt
2117 char *tablespacename;
2121 } CreateTableSpaceStmt;
2123 typedef struct DropTableSpaceStmt
2126 char *tablespacename;
2127 bool missing_ok; /* skip error if missing? */
2128 } DropTableSpaceStmt;
2130 typedef struct AlterTableSpaceOptionsStmt
2133 char *tablespacename;
2136 } AlterTableSpaceOptionsStmt;
2138 typedef struct AlterTableMoveAllStmt
2141 char *orig_tablespacename;
2142 ObjectType objtype; /* Object type to move */
2143 List *roles; /* List of roles to move objects of */
2144 char *new_tablespacename;
2146 } AlterTableMoveAllStmt;
2148 /* ----------------------
2149 * Create/Alter Extension Statements
2150 * ----------------------
2153 typedef struct CreateExtensionStmt
2157 bool if_not_exists; /* just do nothing if it already exists? */
2158 List *options; /* List of DefElem nodes */
2159 } CreateExtensionStmt;
2161 /* Only used for ALTER EXTENSION UPDATE; later might need an action field */
2162 typedef struct AlterExtensionStmt
2166 List *options; /* List of DefElem nodes */
2167 } AlterExtensionStmt;
2169 typedef struct AlterExtensionContentsStmt
2172 char *extname; /* Extension's name */
2173 int action; /* +1 = add object, -1 = drop object */
2174 ObjectType objtype; /* Object's type */
2175 Node *object; /* Qualified name of the object */
2176 } AlterExtensionContentsStmt;
2178 /* ----------------------
2179 * Create/Alter FOREIGN DATA WRAPPER Statements
2180 * ----------------------
2183 typedef struct CreateFdwStmt
2186 char *fdwname; /* foreign-data wrapper name */
2187 List *func_options; /* HANDLER/VALIDATOR options */
2188 List *options; /* generic options to FDW */
2191 typedef struct AlterFdwStmt
2194 char *fdwname; /* foreign-data wrapper name */
2195 List *func_options; /* HANDLER/VALIDATOR options */
2196 List *options; /* generic options to FDW */
2199 /* ----------------------
2200 * Create/Alter FOREIGN SERVER Statements
2201 * ----------------------
2204 typedef struct CreateForeignServerStmt
2207 char *servername; /* server name */
2208 char *servertype; /* optional server type */
2209 char *version; /* optional server version */
2210 char *fdwname; /* FDW name */
2211 bool if_not_exists; /* just do nothing if it already exists? */
2212 List *options; /* generic options to server */
2213 } CreateForeignServerStmt;
2215 typedef struct AlterForeignServerStmt
2218 char *servername; /* server name */
2219 char *version; /* optional server version */
2220 List *options; /* generic options to server */
2221 bool has_version; /* version specified */
2222 } AlterForeignServerStmt;
2224 /* ----------------------
2225 * Create FOREIGN TABLE Statement
2226 * ----------------------
2229 typedef struct CreateForeignTableStmt
2234 } CreateForeignTableStmt;
2236 /* ----------------------
2237 * Create/Drop USER MAPPING Statements
2238 * ----------------------
2241 typedef struct CreateUserMappingStmt
2244 RoleSpec *user; /* user role */
2245 char *servername; /* server name */
2246 bool if_not_exists; /* just do nothing if it already exists? */
2247 List *options; /* generic options to server */
2248 } CreateUserMappingStmt;
2250 typedef struct AlterUserMappingStmt
2253 RoleSpec *user; /* user role */
2254 char *servername; /* server name */
2255 List *options; /* generic options to server */
2256 } AlterUserMappingStmt;
2258 typedef struct DropUserMappingStmt
2261 RoleSpec *user; /* user role */
2262 char *servername; /* server name */
2263 bool missing_ok; /* ignore missing mappings */
2264 } DropUserMappingStmt;
2266 /* ----------------------
2267 * Import Foreign Schema Statement
2268 * ----------------------
2271 typedef enum ImportForeignSchemaType
2273 FDW_IMPORT_SCHEMA_ALL, /* all relations wanted */
2274 FDW_IMPORT_SCHEMA_LIMIT_TO, /* include only listed tables in import */
2275 FDW_IMPORT_SCHEMA_EXCEPT /* exclude listed tables from import */
2276 } ImportForeignSchemaType;
2278 typedef struct ImportForeignSchemaStmt
2281 char *server_name; /* FDW server name */
2282 char *remote_schema; /* remote schema name to query */
2283 char *local_schema; /* local schema to create objects in */
2284 ImportForeignSchemaType list_type; /* type of table list */
2285 List *table_list; /* List of RangeVar */
2286 List *options; /* list of options to pass to FDW */
2287 } ImportForeignSchemaStmt;
2289 /*----------------------
2290 * Create POLICY Statement
2291 *----------------------
2293 typedef struct CreatePolicyStmt
2296 char *policy_name; /* Policy's name */
2297 RangeVar *table; /* the table name the policy applies to */
2298 char *cmd_name; /* the command name the policy applies to */
2299 bool permissive; /* restrictive or permissive policy */
2300 List *roles; /* the roles associated with the policy */
2301 Node *qual; /* the policy's condition */
2302 Node *with_check; /* the policy's WITH CHECK condition. */
2305 /*----------------------
2306 * Alter POLICY Statement
2307 *----------------------
2309 typedef struct AlterPolicyStmt
2312 char *policy_name; /* Policy's name */
2313 RangeVar *table; /* the table name the policy applies to */
2314 List *roles; /* the roles associated with the policy */
2315 Node *qual; /* the policy's condition */
2316 Node *with_check; /* the policy's WITH CHECK condition. */
2319 /*----------------------
2320 * Create ACCESS METHOD Statement
2321 *----------------------
2323 typedef struct CreateAmStmt
2326 char *amname; /* access method name */
2327 List *handler_name; /* handler function name */
2328 char amtype; /* type of access method */
2331 /* ----------------------
2332 * Create TRIGGER Statement
2333 * ----------------------
2335 typedef struct CreateTrigStmt
2338 char *trigname; /* TRIGGER's name */
2339 RangeVar *relation; /* relation trigger is on */
2340 List *funcname; /* qual. name of function to call */
2341 List *args; /* list of (T_String) Values or NIL */
2342 bool row; /* ROW/STATEMENT */
2343 /* timing uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */
2344 int16 timing; /* BEFORE, AFTER, or INSTEAD */
2345 /* events uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */
2346 int16 events; /* "OR" of INSERT/UPDATE/DELETE/TRUNCATE */
2347 List *columns; /* column names, or NIL for all columns */
2348 Node *whenClause; /* qual expression, or NULL if none */
2349 bool isconstraint; /* This is a constraint trigger */
2350 /* explicitly named transition data */
2351 List *transitionRels; /* TriggerTransition nodes, or NIL if none */
2352 /* The remaining fields are only used for constraint triggers */
2353 bool deferrable; /* [NOT] DEFERRABLE */
2354 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
2355 RangeVar *constrrel; /* opposite relation, if RI trigger */
2358 /* ----------------------
2359 * Create EVENT TRIGGER Statement
2360 * ----------------------
2362 typedef struct CreateEventTrigStmt
2365 char *trigname; /* TRIGGER's name */
2366 char *eventname; /* event's identifier */
2367 List *whenclause; /* list of DefElems indicating filtering */
2368 List *funcname; /* qual. name of function to call */
2369 } CreateEventTrigStmt;
2371 /* ----------------------
2372 * Alter EVENT TRIGGER Statement
2373 * ----------------------
2375 typedef struct AlterEventTrigStmt
2378 char *trigname; /* TRIGGER's name */
2379 char tgenabled; /* trigger's firing configuration WRT
2380 * session_replication_role */
2381 } AlterEventTrigStmt;
2383 /* ----------------------
2384 * Create/Drop PROCEDURAL LANGUAGE Statements
2385 * Create PROCEDURAL LANGUAGE Statements
2386 * ----------------------
2388 typedef struct CreatePLangStmt
2391 bool replace; /* T => replace if already exists */
2392 char *plname; /* PL name */
2393 List *plhandler; /* PL call handler function (qual. name) */
2394 List *plinline; /* optional inline function (qual. name) */
2395 List *plvalidator; /* optional validator function (qual. name) */
2396 bool pltrusted; /* PL is trusted */
2399 /* ----------------------
2400 * Create/Alter/Drop Role Statements
2402 * Note: these node types are also used for the backwards-compatible
2403 * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases
2404 * there's really no need to distinguish what the original spelling was,
2405 * but for CREATE we mark the type because the defaults vary.
2406 * ----------------------
2408 typedef enum RoleStmtType
2415 typedef struct CreateRoleStmt
2418 RoleStmtType stmt_type; /* ROLE/USER/GROUP */
2419 char *role; /* role name */
2420 List *options; /* List of DefElem nodes */
2423 typedef struct AlterRoleStmt
2426 RoleSpec *role; /* role */
2427 List *options; /* List of DefElem nodes */
2428 int action; /* +1 = add members, -1 = drop members */
2431 typedef struct AlterRoleSetStmt
2434 RoleSpec *role; /* role */
2435 char *database; /* database name, or NULL */
2436 VariableSetStmt *setstmt; /* SET or RESET subcommand */
2439 typedef struct DropRoleStmt
2442 List *roles; /* List of roles to remove */
2443 bool missing_ok; /* skip error if a role is missing? */
2446 /* ----------------------
2447 * {Create|Alter} SEQUENCE Statement
2448 * ----------------------
2451 typedef struct CreateSeqStmt
2454 RangeVar *sequence; /* the sequence to create */
2456 Oid ownerId; /* ID of owner, or InvalidOid for default */
2458 bool if_not_exists; /* just do nothing if it already exists? */
2461 typedef struct AlterSeqStmt
2464 RangeVar *sequence; /* the sequence to alter */
2467 bool missing_ok; /* skip error if a role is missing? */
2470 /* ----------------------
2471 * Create {Aggregate|Operator|Type} Statement
2472 * ----------------------
2474 typedef struct DefineStmt
2477 ObjectType kind; /* aggregate, operator, type */
2478 bool oldstyle; /* hack to signal old CREATE AGG syntax */
2479 List *defnames; /* qualified name (list of Value strings) */
2480 List *args; /* a list of TypeName (if needed) */
2481 List *definition; /* a list of DefElem */
2482 bool if_not_exists; /* just do nothing if it already exists? */
2485 /* ----------------------
2486 * Create Domain Statement
2487 * ----------------------
2489 typedef struct CreateDomainStmt
2492 List *domainname; /* qualified name (list of Value strings) */
2493 TypeName *typeName; /* the base type */
2494 CollateClause *collClause; /* untransformed COLLATE spec, if any */
2495 List *constraints; /* constraints (list of Constraint nodes) */
2498 /* ----------------------
2499 * Create Operator Class Statement
2500 * ----------------------
2502 typedef struct CreateOpClassStmt
2505 List *opclassname; /* qualified name (list of Value strings) */
2506 List *opfamilyname; /* qualified name (ditto); NIL if omitted */
2507 char *amname; /* name of index AM opclass is for */
2508 TypeName *datatype; /* datatype of indexed column */
2509 List *items; /* List of CreateOpClassItem nodes */
2510 bool isDefault; /* Should be marked as default for type? */
2511 } CreateOpClassStmt;
2513 #define OPCLASS_ITEM_OPERATOR 1
2514 #define OPCLASS_ITEM_FUNCTION 2
2515 #define OPCLASS_ITEM_STORAGETYPE 3
2517 typedef struct CreateOpClassItem
2520 int itemtype; /* see codes above */
2521 ObjectWithArgs *name; /* operator or function name and args */
2522 int number; /* strategy num or support proc num */
2523 List *order_family; /* only used for ordering operators */
2524 List *class_args; /* amproclefttype/amprocrighttype or
2525 * amoplefttype/amoprighttype */
2526 /* fields used for a storagetype item: */
2527 TypeName *storedtype; /* datatype stored in index */
2528 } CreateOpClassItem;
2530 /* ----------------------
2531 * Create Operator Family Statement
2532 * ----------------------
2534 typedef struct CreateOpFamilyStmt
2537 List *opfamilyname; /* qualified name (list of Value strings) */
2538 char *amname; /* name of index AM opfamily is for */
2539 } CreateOpFamilyStmt;
2541 /* ----------------------
2542 * Alter Operator Family Statement
2543 * ----------------------
2545 typedef struct AlterOpFamilyStmt
2548 List *opfamilyname; /* qualified name (list of Value strings) */
2549 char *amname; /* name of index AM opfamily is for */
2550 bool isDrop; /* ADD or DROP the items? */
2551 List *items; /* List of CreateOpClassItem nodes */
2552 } AlterOpFamilyStmt;
2554 /* ----------------------
2555 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
2556 * ----------------------
2559 typedef struct DropStmt
2562 List *objects; /* list of names */
2563 ObjectType removeType; /* object type */
2564 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
2565 bool missing_ok; /* skip error if object is missing? */
2566 bool concurrent; /* drop index concurrently? */
2569 /* ----------------------
2570 * Truncate Table Statement
2571 * ----------------------
2573 typedef struct TruncateStmt
2576 List *relations; /* relations (RangeVars) to be truncated */
2577 bool restart_seqs; /* restart owned sequences? */
2578 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
2581 /* ----------------------
2582 * Comment On Statement
2583 * ----------------------
2585 typedef struct CommentStmt
2588 ObjectType objtype; /* Object's type */
2589 Node *object; /* Qualified name of the object */
2590 char *comment; /* Comment to insert, or NULL to remove */
2593 /* ----------------------
2594 * SECURITY LABEL Statement
2595 * ----------------------
2597 typedef struct SecLabelStmt
2600 ObjectType objtype; /* Object's type */
2601 Node *object; /* Qualified name of the object */
2602 char *provider; /* Label provider (or NULL) */
2603 char *label; /* New security label to be assigned */
2606 /* ----------------------
2607 * Declare Cursor Statement
2609 * The "query" field is initially a raw parse tree, and is converted to a
2610 * Query node during parse analysis. Note that rewriting and planning
2611 * of the query are always postponed until execution.
2612 * ----------------------
2614 #define CURSOR_OPT_BINARY 0x0001 /* BINARY */
2615 #define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */
2616 #define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */
2617 #define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */
2618 #define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */
2619 /* these planner-control flags do not correspond to any SQL grammar: */
2620 #define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */
2621 #define CURSOR_OPT_GENERIC_PLAN 0x0040 /* force use of generic plan */
2622 #define CURSOR_OPT_CUSTOM_PLAN 0x0080 /* force use of custom plan */
2623 #define CURSOR_OPT_PARALLEL_OK 0x0100 /* parallel mode OK */
2625 typedef struct DeclareCursorStmt
2628 char *portalname; /* name of the portal (cursor) */
2629 int options; /* bitmask of options (see above) */
2630 Node *query; /* the query (see comments above) */
2631 } DeclareCursorStmt;
2633 /* ----------------------
2634 * Close Portal Statement
2635 * ----------------------
2637 typedef struct ClosePortalStmt
2640 char *portalname; /* name of the portal (cursor) */
2641 /* NULL means CLOSE ALL */
2644 /* ----------------------
2645 * Fetch Statement (also Move)
2646 * ----------------------
2648 typedef enum FetchDirection
2650 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
2653 /* for these, howMany indicates a position; only one row is fetched */
2658 #define FETCH_ALL LONG_MAX
2660 typedef struct FetchStmt
2663 FetchDirection direction; /* see above */
2664 long howMany; /* number of rows, or position argument */
2665 char *portalname; /* name of portal (cursor) */
2666 bool ismove; /* TRUE if MOVE */
2669 /* ----------------------
2670 * Create Index Statement
2672 * This represents creation of an index and/or an associated constraint.
2673 * If isconstraint is true, we should create a pg_constraint entry along
2674 * with the index. But if indexOid isn't InvalidOid, we are not creating an
2675 * index, just a UNIQUE/PKEY constraint using an existing index. isconstraint
2676 * must always be true in this case, and the fields describing the index
2677 * properties are empty.
2678 * ----------------------
2680 typedef struct IndexStmt
2683 char *idxname; /* name of new index, or NULL for default */
2684 RangeVar *relation; /* relation to build index on */
2685 char *accessMethod; /* name of access method (eg. btree) */
2686 char *tableSpace; /* tablespace, or NULL for default */
2687 List *indexParams; /* columns to index: a list of IndexElem */
2688 List *options; /* WITH clause options: a list of DefElem */
2689 Node *whereClause; /* qualification (partial-index predicate) */
2690 List *excludeOpNames; /* exclusion operator names, or NIL if none */
2691 char *idxcomment; /* comment to apply to index, or NULL */
2692 Oid indexOid; /* OID of an existing index, if any */
2693 Oid oldNode; /* relfilenode of existing storage, if any */
2694 bool unique; /* is index unique? */
2695 bool primary; /* is index a primary key? */
2696 bool isconstraint; /* is it for a pkey/unique constraint? */
2697 bool deferrable; /* is the constraint DEFERRABLE? */
2698 bool initdeferred; /* is the constraint INITIALLY DEFERRED? */
2699 bool transformed; /* true when transformIndexStmt is finished */
2700 bool concurrent; /* should this be a concurrent index build? */
2701 bool if_not_exists; /* just do nothing if index already exists? */
2704 /* ----------------------
2705 * Create Statistics Statement
2706 * ----------------------
2708 typedef struct CreateStatsStmt
2711 List *defnames; /* qualified name (list of Value strings) */
2712 List *stat_types; /* stat types (list of Value strings) */
2713 List *exprs; /* expressions to build statistics on */
2714 List *relations; /* rels to build stats on (list of RangeVar) */
2715 bool if_not_exists; /* do nothing if stats name already exists */
2718 /* ----------------------
2719 * Create Function Statement
2720 * ----------------------
2722 typedef struct CreateFunctionStmt
2725 bool replace; /* T => replace if already exists */
2726 List *funcname; /* qualified name of function to create */
2727 List *parameters; /* a list of FunctionParameter */
2728 TypeName *returnType; /* the return type */
2729 List *options; /* a list of DefElem */
2730 List *withClause; /* a list of DefElem */
2731 } CreateFunctionStmt;
2733 typedef enum FunctionParameterMode
2735 /* the assigned enum values appear in pg_proc, don't change 'em! */
2736 FUNC_PARAM_IN = 'i', /* input only */
2737 FUNC_PARAM_OUT = 'o', /* output only */
2738 FUNC_PARAM_INOUT = 'b', /* both */
2739 FUNC_PARAM_VARIADIC = 'v', /* variadic (always input) */
2740 FUNC_PARAM_TABLE = 't' /* table function output column */
2741 } FunctionParameterMode;
2743 typedef struct FunctionParameter
2746 char *name; /* parameter name, or NULL if not given */
2747 TypeName *argType; /* TypeName for parameter type */
2748 FunctionParameterMode mode; /* IN/OUT/etc */
2749 Node *defexpr; /* raw default expr, or NULL if not given */
2750 } FunctionParameter;
2752 typedef struct AlterFunctionStmt
2755 ObjectWithArgs *func; /* name and args of function */
2756 List *actions; /* list of DefElem */
2757 } AlterFunctionStmt;
2759 /* ----------------------
2762 * DoStmt is the raw parser output, InlineCodeBlock is the execution-time API
2763 * ----------------------
2765 typedef struct DoStmt
2768 List *args; /* List of DefElem nodes */
2771 typedef struct InlineCodeBlock
2774 char *source_text; /* source text of anonymous code block */
2775 Oid langOid; /* OID of selected language */
2776 bool langIsTrusted; /* trusted property of the language */
2779 /* ----------------------
2780 * Alter Object Rename Statement
2781 * ----------------------
2783 typedef struct RenameStmt
2786 ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
2787 ObjectType relationType; /* if column name, associated relation type */
2788 RangeVar *relation; /* in case it's a table */
2789 Node *object; /* in case it's some other object */
2790 char *subname; /* name of contained object (column, rule,
2792 char *newname; /* the new name */
2793 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
2794 bool missing_ok; /* skip error if missing? */
2797 /* ----------------------
2798 * ALTER object DEPENDS ON EXTENSION extname
2799 * ----------------------
2801 typedef struct AlterObjectDependsStmt
2804 ObjectType objectType; /* OBJECT_FUNCTION, OBJECT_TRIGGER, etc */
2805 RangeVar *relation; /* in case a table is involved */
2806 Node *object; /* name of the object */
2807 Value *extname; /* extension name */
2808 } AlterObjectDependsStmt;
2810 /* ----------------------
2811 * ALTER object SET SCHEMA Statement
2812 * ----------------------
2814 typedef struct AlterObjectSchemaStmt
2817 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
2818 RangeVar *relation; /* in case it's a table */
2819 Node *object; /* in case it's some other object */
2820 char *newschema; /* the new schema */
2821 bool missing_ok; /* skip error if missing? */
2822 } AlterObjectSchemaStmt;
2824 /* ----------------------
2825 * Alter Object Owner Statement
2826 * ----------------------
2828 typedef struct AlterOwnerStmt
2831 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
2832 RangeVar *relation; /* in case it's a table */
2833 Node *object; /* in case it's some other object */
2834 RoleSpec *newowner; /* the new owner */
2838 /* ----------------------
2839 * Alter Operator Set Restrict, Join
2840 * ----------------------
2842 typedef struct AlterOperatorStmt
2845 ObjectWithArgs *opername; /* operator name and argument types */
2846 List *options; /* List of DefElem nodes */
2847 } AlterOperatorStmt;
2850 /* ----------------------
2851 * Create Rule Statement
2852 * ----------------------
2854 typedef struct RuleStmt
2857 RangeVar *relation; /* relation the rule is for */
2858 char *rulename; /* name of the rule */
2859 Node *whereClause; /* qualifications */
2860 CmdType event; /* SELECT, INSERT, etc */
2861 bool instead; /* is a 'do instead'? */
2862 List *actions; /* the action statements */
2863 bool replace; /* OR REPLACE */
2866 /* ----------------------
2868 * ----------------------
2870 typedef struct NotifyStmt
2873 char *conditionname; /* condition name to notify */
2874 char *payload; /* the payload string, or NULL if none */
2877 /* ----------------------
2879 * ----------------------
2881 typedef struct ListenStmt
2884 char *conditionname; /* condition name to listen on */
2887 /* ----------------------
2888 * Unlisten Statement
2889 * ----------------------
2891 typedef struct UnlistenStmt
2894 char *conditionname; /* name to unlisten on, or NULL for all */
2897 /* ----------------------
2898 * {Begin|Commit|Rollback} Transaction Statement
2899 * ----------------------
2901 typedef enum TransactionStmtKind
2904 TRANS_STMT_START, /* semantically identical to BEGIN */
2906 TRANS_STMT_ROLLBACK,
2907 TRANS_STMT_SAVEPOINT,
2909 TRANS_STMT_ROLLBACK_TO,
2911 TRANS_STMT_COMMIT_PREPARED,
2912 TRANS_STMT_ROLLBACK_PREPARED
2913 } TransactionStmtKind;
2915 typedef struct TransactionStmt
2918 TransactionStmtKind kind; /* see above */
2919 List *options; /* for BEGIN/START and savepoint commands */
2920 char *gid; /* for two-phase-commit related commands */
2923 /* ----------------------
2924 * Create Type Statement, composite types
2925 * ----------------------
2927 typedef struct CompositeTypeStmt
2930 RangeVar *typevar; /* the composite type to be created */
2931 List *coldeflist; /* list of ColumnDef nodes */
2932 } CompositeTypeStmt;
2934 /* ----------------------
2935 * Create Type Statement, enum types
2936 * ----------------------
2938 typedef struct CreateEnumStmt
2941 List *typeName; /* qualified name (list of Value strings) */
2942 List *vals; /* enum values (list of Value strings) */
2945 /* ----------------------
2946 * Create Type Statement, range types
2947 * ----------------------
2949 typedef struct CreateRangeStmt
2952 List *typeName; /* qualified name (list of Value strings) */
2953 List *params; /* range parameters (list of DefElem) */
2956 /* ----------------------
2957 * Alter Type Statement, enum types
2958 * ----------------------
2960 typedef struct AlterEnumStmt
2963 List *typeName; /* qualified name (list of Value strings) */
2964 char *oldVal; /* old enum value's name, if renaming */
2965 char *newVal; /* new enum value's name */
2966 char *newValNeighbor; /* neighboring enum value, if specified */
2967 bool newValIsAfter; /* place new enum value after neighbor? */
2968 bool skipIfNewValExists; /* no error if new already exists? */
2971 /* ----------------------
2972 * Create View Statement
2973 * ----------------------
2975 typedef enum ViewCheckOption
2979 CASCADED_CHECK_OPTION
2982 typedef struct ViewStmt
2985 RangeVar *view; /* the view to be created */
2986 List *aliases; /* target column names */
2987 Node *query; /* the SELECT query (as a raw parse tree) */
2988 bool replace; /* replace an existing view? */
2989 List *options; /* options from WITH clause */
2990 ViewCheckOption withCheckOption; /* WITH CHECK OPTION */
2993 /* ----------------------
2995 * ----------------------
2997 typedef struct LoadStmt
3000 char *filename; /* file to load */
3003 /* ----------------------
3004 * Createdb Statement
3005 * ----------------------
3007 typedef struct CreatedbStmt
3010 char *dbname; /* name of database to create */
3011 List *options; /* List of DefElem nodes */
3014 /* ----------------------
3016 * ----------------------
3018 typedef struct AlterDatabaseStmt
3021 char *dbname; /* name of database to alter */
3022 List *options; /* List of DefElem nodes */
3023 } AlterDatabaseStmt;
3025 typedef struct AlterDatabaseSetStmt
3028 char *dbname; /* database name */
3029 VariableSetStmt *setstmt; /* SET or RESET subcommand */
3030 } AlterDatabaseSetStmt;
3032 /* ----------------------
3034 * ----------------------
3036 typedef struct DropdbStmt
3039 char *dbname; /* database to drop */
3040 bool missing_ok; /* skip error if db is missing? */
3043 /* ----------------------
3044 * Alter System Statement
3045 * ----------------------
3047 typedef struct AlterSystemStmt
3050 VariableSetStmt *setstmt; /* SET subcommand */
3053 /* ----------------------
3054 * Cluster Statement (support pbrown's cluster index implementation)
3055 * ----------------------
3057 typedef struct ClusterStmt
3060 RangeVar *relation; /* relation being indexed, or NULL if all */
3061 char *indexname; /* original index defined */
3062 bool verbose; /* print progress info */
3065 /* ----------------------
3066 * Vacuum and Analyze Statements
3068 * Even though these are nominally two statements, it's convenient to use
3069 * just one node type for both. Note that at least one of VACOPT_VACUUM
3070 * and VACOPT_ANALYZE must be set in options.
3071 * ----------------------
3073 typedef enum VacuumOption
3075 VACOPT_VACUUM = 1 << 0, /* do VACUUM */
3076 VACOPT_ANALYZE = 1 << 1, /* do ANALYZE */
3077 VACOPT_VERBOSE = 1 << 2, /* print progress info */
3078 VACOPT_FREEZE = 1 << 3, /* FREEZE option */
3079 VACOPT_FULL = 1 << 4, /* FULL (non-concurrent) vacuum */
3080 VACOPT_NOWAIT = 1 << 5, /* don't wait to get lock (autovacuum only) */
3081 VACOPT_SKIPTOAST = 1 << 6, /* don't process the TOAST table, if any */
3082 VACOPT_DISABLE_PAGE_SKIPPING = 1 << 7 /* don't skip any pages */
3085 typedef struct VacuumStmt
3088 int options; /* OR of VacuumOption flags */
3089 RangeVar *relation; /* single table to process, or NULL */
3090 List *va_cols; /* list of column names, or NIL for all */
3093 /* ----------------------
3096 * The "query" field is initially a raw parse tree, and is converted to a
3097 * Query node during parse analysis. Note that rewriting and planning
3098 * of the query are always postponed until execution.
3099 * ----------------------
3101 typedef struct ExplainStmt
3104 Node *query; /* the query (see comments above) */
3105 List *options; /* list of DefElem nodes */
3108 /* ----------------------
3109 * CREATE TABLE AS Statement (a/k/a SELECT INTO)
3111 * A query written as CREATE TABLE AS will produce this node type natively.
3112 * A query written as SELECT ... INTO will be transformed to this form during
3114 * A query written as CREATE MATERIALIZED view will produce this node type,
3115 * during parse analysis, since it needs all the same data.
3117 * The "query" field is handled similarly to EXPLAIN, though note that it
3118 * can be a SELECT or an EXECUTE, but not other DML statements.
3119 * ----------------------
3121 typedef struct CreateTableAsStmt
3124 Node *query; /* the query (see comments above) */
3125 IntoClause *into; /* destination table */
3126 ObjectType relkind; /* OBJECT_TABLE or OBJECT_MATVIEW */
3127 bool is_select_into; /* it was written as SELECT INTO */
3128 bool if_not_exists; /* just do nothing if it already exists? */
3129 } CreateTableAsStmt;
3131 /* ----------------------
3132 * REFRESH MATERIALIZED VIEW Statement
3133 * ----------------------
3135 typedef struct RefreshMatViewStmt
3138 bool concurrent; /* allow concurrent access? */
3139 bool skipData; /* true for WITH NO DATA */
3140 RangeVar *relation; /* relation to insert into */
3141 } RefreshMatViewStmt;
3143 /* ----------------------
3144 * Checkpoint Statement
3145 * ----------------------
3147 typedef struct CheckPointStmt
3152 /* ----------------------
3154 * ----------------------
3157 typedef enum DiscardMode
3165 typedef struct DiscardStmt
3171 /* ----------------------
3173 * ----------------------
3175 typedef struct LockStmt
3178 List *relations; /* relations to lock */
3179 int mode; /* lock mode */
3180 bool nowait; /* no wait mode */
3183 /* ----------------------
3184 * SET CONSTRAINTS Statement
3185 * ----------------------
3187 typedef struct ConstraintsSetStmt
3190 List *constraints; /* List of names as RangeVars */
3192 } ConstraintsSetStmt;
3194 /* ----------------------
3196 * ----------------------
3199 /* Reindex options */
3200 #define REINDEXOPT_VERBOSE 1 << 0 /* print progress info */
3202 typedef enum ReindexObjectType
3204 REINDEX_OBJECT_INDEX, /* index */
3205 REINDEX_OBJECT_TABLE, /* table or materialized view */
3206 REINDEX_OBJECT_SCHEMA, /* schema */
3207 REINDEX_OBJECT_SYSTEM, /* system catalogs */
3208 REINDEX_OBJECT_DATABASE /* database */
3209 } ReindexObjectType;
3211 typedef struct ReindexStmt
3214 ReindexObjectType kind; /* REINDEX_OBJECT_INDEX, REINDEX_OBJECT_TABLE,
3216 RangeVar *relation; /* Table or index to reindex */
3217 const char *name; /* name of database to reindex */
3218 int options; /* Reindex options flags */
3221 /* ----------------------
3222 * CREATE CONVERSION Statement
3223 * ----------------------
3225 typedef struct CreateConversionStmt
3228 List *conversion_name; /* Name of the conversion */
3229 char *for_encoding_name; /* source encoding name */
3230 char *to_encoding_name; /* destination encoding name */
3231 List *func_name; /* qualified conversion function name */
3232 bool def; /* is this a default conversion? */
3233 } CreateConversionStmt;
3235 /* ----------------------
3236 * CREATE CAST Statement
3237 * ----------------------
3239 typedef struct CreateCastStmt
3242 TypeName *sourcetype;
3243 TypeName *targettype;
3244 ObjectWithArgs *func;
3245 CoercionContext context;
3249 /* ----------------------
3250 * CREATE TRANSFORM Statement
3251 * ----------------------
3253 typedef struct CreateTransformStmt
3257 TypeName *type_name;
3259 ObjectWithArgs *fromsql;
3260 ObjectWithArgs *tosql;
3261 } CreateTransformStmt;
3263 /* ----------------------
3265 * ----------------------
3267 typedef struct PrepareStmt
3270 char *name; /* Name of plan, arbitrary */
3271 List *argtypes; /* Types of parameters (List of TypeName) */
3272 Node *query; /* The query itself (as a raw parsetree) */
3276 /* ----------------------
3278 * ----------------------
3281 typedef struct ExecuteStmt
3284 char *name; /* The name of the plan to execute */
3285 List *params; /* Values to assign to parameters */
3289 /* ----------------------
3290 * DEALLOCATE Statement
3291 * ----------------------
3293 typedef struct DeallocateStmt
3296 char *name; /* The name of the plan to remove */
3297 /* NULL means DEALLOCATE ALL */
3301 * DROP OWNED statement
3303 typedef struct DropOwnedStmt
3307 DropBehavior behavior;
3311 * REASSIGN OWNED statement
3313 typedef struct ReassignOwnedStmt
3318 } ReassignOwnedStmt;
3321 * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
3323 typedef struct AlterTSDictionaryStmt
3326 List *dictname; /* qualified name (list of Value strings) */
3327 List *options; /* List of DefElem nodes */
3328 } AlterTSDictionaryStmt;
3331 * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
3333 typedef enum AlterTSConfigType
3335 ALTER_TSCONFIG_ADD_MAPPING,
3336 ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN,
3337 ALTER_TSCONFIG_REPLACE_DICT,
3338 ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN,
3339 ALTER_TSCONFIG_DROP_MAPPING
3340 } AlterTSConfigType;
3342 typedef struct AlterTSConfigurationStmt
3345 AlterTSConfigType kind; /* ALTER_TSCONFIG_ADD_MAPPING, etc */
3346 List *cfgname; /* qualified name (list of Value strings) */
3349 * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is
3350 * NIL, but tokentype isn't, DROP MAPPING was specified.
3352 List *tokentype; /* list of Value strings */
3353 List *dicts; /* list of list of Value strings */
3354 bool override; /* if true - remove old variant */
3355 bool replace; /* if true - replace dictionary by another */
3356 bool missing_ok; /* for DROP - skip error if missing? */
3357 } AlterTSConfigurationStmt;
3360 typedef struct CreatePublicationStmt
3363 char *pubname; /* Name of of the publication */
3364 List *options; /* List of DefElem nodes */
3365 List *tables; /* Optional list of tables to add */
3366 bool for_all_tables; /* Special publication for all tables in db */
3367 } CreatePublicationStmt;
3369 typedef struct AlterPublicationStmt
3372 char *pubname; /* Name of of the publication */
3374 /* parameters used for ALTER PUBLICATION ... WITH */
3375 List *options; /* List of DefElem nodes */
3377 /* parameters used for ALTER PUBLICATION ... ADD/DROP TABLE */
3378 List *tables; /* List of tables to add/drop */
3379 bool for_all_tables; /* Special publication for all tables in db */
3380 DefElemAction tableAction; /* What action to perform with the tables */
3381 } AlterPublicationStmt;
3383 typedef struct CreateSubscriptionStmt
3386 char *subname; /* Name of of the subscription */
3387 char *conninfo; /* Connection string to publisher */
3388 List *publication; /* One or more publication to subscribe to */
3389 List *options; /* List of DefElem nodes */
3390 } CreateSubscriptionStmt;
3392 typedef enum AlterSubscriptionType
3394 ALTER_SUBSCRIPTION_OPTIONS,
3395 ALTER_SUBSCRIPTION_CONNECTION,
3396 ALTER_SUBSCRIPTION_PUBLICATION,
3397 ALTER_SUBSCRIPTION_REFRESH,
3398 ALTER_SUBSCRIPTION_ENABLED
3399 } AlterSubscriptionType;
3401 typedef struct AlterSubscriptionStmt
3404 AlterSubscriptionType kind; /* ALTER_SUBSCRIPTION_OPTIONS, etc */
3405 char *subname; /* Name of of the subscription */
3406 char *conninfo; /* Connection string to publisher */
3407 List *publication; /* One or more publication to subscribe to */
3408 List *options; /* List of DefElem nodes */
3409 } AlterSubscriptionStmt;
3411 typedef struct DropSubscriptionStmt
3414 char *subname; /* Name of of the subscription */
3415 bool missing_ok; /* Skip error if missing? */
3416 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
3417 } DropSubscriptionStmt;
3419 #endif /* PARSENODES_H */