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 /* Possible sources of a Query */
31 typedef enum QuerySource
33 QSRC_ORIGINAL, /* original parsetree (explicit query) */
34 QSRC_PARSER, /* added by parse analysis (now unused) */
35 QSRC_INSTEAD_RULE, /* added by unconditional INSTEAD rule */
36 QSRC_QUAL_INSTEAD_RULE, /* added by conditional INSTEAD rule */
37 QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */
40 /* Sort ordering options for ORDER BY and CREATE INDEX */
41 typedef enum SortByDir
46 SORTBY_USING /* not allowed in CREATE INDEX ... */
49 typedef enum SortByNulls
57 * Grantable rights are encoded so that we can OR them together in a bitmask.
58 * The present representation of AclItem limits us to 16 distinct rights,
59 * even though AclMode is defined as uint32. See utils/acl.h.
61 * Caution: changing these codes breaks stored ACLs, hence forces initdb.
63 typedef uint32 AclMode; /* a bitmask of privilege bits */
65 #define ACL_INSERT (1<<0) /* for relations */
66 #define ACL_SELECT (1<<1)
67 #define ACL_UPDATE (1<<2)
68 #define ACL_DELETE (1<<3)
69 #define ACL_TRUNCATE (1<<4)
70 #define ACL_REFERENCES (1<<5)
71 #define ACL_TRIGGER (1<<6)
72 #define ACL_EXECUTE (1<<7) /* for functions */
73 #define ACL_USAGE (1<<8) /* for languages, namespaces, FDWs, and
75 #define ACL_CREATE (1<<9) /* for namespaces and databases */
76 #define ACL_CREATE_TEMP (1<<10) /* for databases */
77 #define ACL_CONNECT (1<<11) /* for databases */
78 #define N_ACL_RIGHTS 12 /* 1 plus the last 1<<x */
79 #define ACL_NO_RIGHTS 0
80 /* Currently, SELECT ... FOR [KEY] UPDATE/SHARE requires UPDATE privileges */
81 #define ACL_SELECT_FOR_UPDATE ACL_UPDATE
84 /*****************************************************************************
86 *****************************************************************************/
90 * Parse analysis turns all statements into a Query tree
91 * for further processing by the rewriter and planner.
93 * Utility statements (i.e. non-optimizable statements) have the
94 * utilityStmt field set, and the rest of the Query is mostly dummy.
96 * Planning converts a Query tree into a Plan tree headed by a PlannedStmt
97 * node --- the Query structure is not used by the executor.
103 CmdType commandType; /* select|insert|update|delete|utility */
105 QuerySource querySource; /* where did I come from? */
107 uint32 queryId; /* query identifier (can be set by plugins) */
109 bool canSetTag; /* do I set the command result tag? */
111 Node *utilityStmt; /* non-null if commandType == CMD_UTILITY */
113 int resultRelation; /* rtable index of target relation for
114 * INSERT/UPDATE/DELETE; 0 for SELECT */
116 bool hasAggs; /* has aggregates in tlist or havingQual */
117 bool hasWindowFuncs; /* has window functions in tlist */
118 bool hasTargetSRFs; /* has set-returning functions in tlist */
119 bool hasSubLinks; /* has subquery SubLink */
120 bool hasDistinctOn; /* distinctClause is from DISTINCT ON */
121 bool hasRecursive; /* WITH RECURSIVE was specified */
122 bool hasModifyingCTE; /* has INSERT/UPDATE/DELETE in WITH */
123 bool hasForUpdate; /* FOR [KEY] UPDATE/SHARE was specified */
124 bool hasRowSecurity; /* rewriter has applied some RLS policy */
126 List *cteList; /* WITH list (of CommonTableExpr's) */
128 List *rtable; /* list of range table entries */
129 FromExpr *jointree; /* table join tree (FROM and WHERE clauses) */
131 List *targetList; /* target list (of TargetEntry) */
133 OnConflictExpr *onConflict; /* ON CONFLICT DO [NOTHING | UPDATE] */
135 List *returningList; /* return-values list (of TargetEntry) */
137 List *groupClause; /* a list of SortGroupClause's */
139 List *groupingSets; /* a list of GroupingSet's if present */
141 Node *havingQual; /* qualifications applied to groups */
143 List *windowClause; /* a list of WindowClause's */
145 List *distinctClause; /* a list of SortGroupClause's */
147 List *sortClause; /* a list of SortGroupClause's */
149 Node *limitOffset; /* # of result tuples to skip (int8 expr) */
150 Node *limitCount; /* # of result tuples to return (int8 expr) */
152 List *rowMarks; /* a list of RowMarkClause's */
154 Node *setOperations; /* set-operation tree if this is top level of
155 * a UNION/INTERSECT/EXCEPT query */
157 List *constraintDeps; /* a list of pg_constraint OIDs that the query
158 * depends on to be semantically valid */
160 List *withCheckOptions; /* a list of WithCheckOption's, which
161 * are only added during rewrite and
162 * therefore are not written out as
166 * The following two fields identify the portion of the source text string
167 * containing this query. They are typically only populated in top-level
168 * Queries, not in sub-queries. When not set, they might both be zero, or
169 * both be -1 meaning "unknown".
171 int stmt_location; /* start location, or -1 if unknown */
172 int stmt_len; /* length in bytes; 0 means "rest of string" */
176 /****************************************************************************
177 * Supporting data structures for Parse Trees
179 * Most of these node types appear in raw parsetrees output by the grammar,
180 * and get transformed to something else by the analyzer. A few of them
181 * are used as-is in transformed querytrees.
182 ****************************************************************************/
185 * TypeName - specifies a type in definitions
187 * For TypeName structures generated internally, it is often easier to
188 * specify the type by OID than by name. If "names" is NIL then the
189 * actual type OID is given by typeOid, otherwise typeOid is unused.
190 * Similarly, if "typmods" is NIL then the actual typmod is expected to
191 * be prespecified in typemod, otherwise typemod is unused.
193 * If pct_type is TRUE, then names is actually a field name and we look up
194 * the type of that field. Otherwise (the normal case), names is a type
195 * name possibly qualified with schema and database name.
197 typedef struct TypeName
200 List *names; /* qualified name (list of Value strings) */
201 Oid typeOid; /* type identified by OID */
202 bool setof; /* is a set? */
203 bool pct_type; /* %TYPE specified? */
204 List *typmods; /* type modifier expression(s) */
205 int32 typemod; /* prespecified type modifier */
206 List *arrayBounds; /* array bounds */
207 int location; /* token location, or -1 if unknown */
211 * ColumnRef - specifies a reference to a column, or possibly a whole tuple
213 * The "fields" list must be nonempty. It can contain string Value nodes
214 * (representing names) and A_Star nodes (representing occurrence of a '*').
215 * Currently, A_Star must appear only as the last list element --- the grammar
216 * is responsible for enforcing this!
218 * Note: any array subscripting or selection of fields from composite columns
219 * is represented by an A_Indirection node above the ColumnRef. However,
220 * for simplicity in the normal case, initial field selection from a table
221 * name is represented within ColumnRef and not by adding A_Indirection.
223 typedef struct ColumnRef
226 List *fields; /* field names (Value strings) or A_Star */
227 int location; /* token location, or -1 if unknown */
231 * ParamRef - specifies a $n parameter reference
233 typedef struct ParamRef
236 int number; /* the number of the parameter */
237 int location; /* token location, or -1 if unknown */
241 * A_Expr - infix, prefix, and postfix expressions
243 typedef enum A_Expr_Kind
245 AEXPR_OP, /* normal operator */
246 AEXPR_OP_ANY, /* scalar op ANY (array) */
247 AEXPR_OP_ALL, /* scalar op ALL (array) */
248 AEXPR_DISTINCT, /* IS DISTINCT FROM - name must be "=" */
249 AEXPR_NOT_DISTINCT, /* IS NOT DISTINCT FROM - name must be "=" */
250 AEXPR_NULLIF, /* NULLIF - name must be "=" */
251 AEXPR_OF, /* IS [NOT] OF - name must be "=" or "<>" */
252 AEXPR_IN, /* [NOT] IN - name must be "=" or "<>" */
253 AEXPR_LIKE, /* [NOT] LIKE - name must be "~~" or "!~~" */
254 AEXPR_ILIKE, /* [NOT] ILIKE - name must be "~~*" or "!~~*" */
255 AEXPR_SIMILAR, /* [NOT] SIMILAR - name must be "~" or "!~" */
256 AEXPR_BETWEEN, /* name must be "BETWEEN" */
257 AEXPR_NOT_BETWEEN, /* name must be "NOT BETWEEN" */
258 AEXPR_BETWEEN_SYM, /* name must be "BETWEEN SYMMETRIC" */
259 AEXPR_NOT_BETWEEN_SYM, /* name must be "NOT BETWEEN SYMMETRIC" */
260 AEXPR_PAREN /* nameless dummy node for parentheses */
263 typedef struct A_Expr
266 A_Expr_Kind kind; /* see above */
267 List *name; /* possibly-qualified name of operator */
268 Node *lexpr; /* left argument, or NULL if none */
269 Node *rexpr; /* right argument, or NULL if none */
270 int location; /* token location, or -1 if unknown */
274 * A_Const - a literal constant
276 typedef struct A_Const
279 Value val; /* value (includes type info, see value.h) */
280 int location; /* token location, or -1 if unknown */
284 * TypeCast - a CAST expression
286 typedef struct TypeCast
289 Node *arg; /* the expression being casted */
290 TypeName *typeName; /* the target type */
291 int location; /* token location, or -1 if unknown */
295 * CollateClause - a COLLATE expression
297 typedef struct CollateClause
300 Node *arg; /* input expression */
301 List *collname; /* possibly-qualified collation name */
302 int location; /* token location, or -1 if unknown */
306 * RoleSpec - a role name or one of a few special values.
308 typedef enum RoleSpecType
310 ROLESPEC_CSTRING, /* role name is stored as a C string */
311 ROLESPEC_CURRENT_USER, /* role spec is CURRENT_USER */
312 ROLESPEC_SESSION_USER, /* role spec is SESSION_USER */
313 ROLESPEC_PUBLIC /* role name is "public" */
316 typedef struct RoleSpec
319 RoleSpecType roletype; /* Type of this rolespec */
320 char *rolename; /* filled only for ROLESPEC_CSTRING */
321 int location; /* token location, or -1 if unknown */
325 * FuncCall - a function or aggregate invocation
327 * agg_order (if not NIL) indicates we saw 'foo(... ORDER BY ...)', or if
328 * agg_within_group is true, it was 'foo(...) WITHIN GROUP (ORDER BY ...)'.
329 * agg_star indicates we saw a 'foo(*)' construct, while agg_distinct
330 * indicates we saw 'foo(DISTINCT ...)'. In any of these cases, the
331 * construct *must* be an aggregate call. Otherwise, it might be either an
332 * aggregate or some other kind of function. However, if FILTER or OVER is
333 * present it had better be an aggregate or window function.
335 * Normally, you'd initialize this via makeFuncCall() and then only change the
336 * parts of the struct its defaults don't match afterwards, as needed.
338 typedef struct FuncCall
341 List *funcname; /* qualified name of function */
342 List *args; /* the arguments (list of exprs) */
343 List *agg_order; /* ORDER BY (list of SortBy) */
344 Node *agg_filter; /* FILTER clause, if any */
345 bool agg_within_group; /* ORDER BY appeared in WITHIN GROUP */
346 bool agg_star; /* argument was really '*' */
347 bool agg_distinct; /* arguments were labeled DISTINCT */
348 bool func_variadic; /* last argument was labeled VARIADIC */
349 struct WindowDef *over; /* OVER clause, if any */
350 int location; /* token location, or -1 if unknown */
354 * A_Star - '*' representing all columns of a table or compound field
356 * This can appear within ColumnRef.fields, A_Indirection.indirection, and
357 * ResTarget.indirection lists.
359 typedef struct A_Star
365 * A_Indices - array subscript or slice bounds ([idx] or [lidx:uidx])
367 * In slice case, either or both of lidx and uidx can be NULL (omitted).
368 * In non-slice case, uidx holds the single subscript and lidx is always NULL.
370 typedef struct A_Indices
373 bool is_slice; /* true if slice (i.e., colon present) */
374 Node *lidx; /* slice lower bound, if any */
375 Node *uidx; /* subscript, or slice upper bound if any */
379 * A_Indirection - select a field and/or array element from an expression
381 * The indirection list can contain A_Indices nodes (representing
382 * subscripting), string Value nodes (representing field selection --- the
383 * string value is the name of the field to select), and A_Star nodes
384 * (representing selection of all fields of a composite type).
385 * For example, a complex selection operation like
386 * (foo).field1[42][7].field2
387 * would be represented with a single A_Indirection node having a 4-element
390 * Currently, A_Star must appear only as the last list element --- the grammar
391 * is responsible for enforcing this!
393 typedef struct A_Indirection
396 Node *arg; /* the thing being selected from */
397 List *indirection; /* subscripts and/or field names and/or * */
401 * A_ArrayExpr - an ARRAY[] construct
403 typedef struct A_ArrayExpr
406 List *elements; /* array element expressions */
407 int location; /* token location, or -1 if unknown */
412 * result target (used in target list of pre-transformed parse trees)
414 * In a SELECT target list, 'name' is the column label from an
415 * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the
416 * value expression itself. The 'indirection' field is not used.
418 * INSERT uses ResTarget in its target-column-names list. Here, 'name' is
419 * the name of the destination column, 'indirection' stores any subscripts
420 * attached to the destination, and 'val' is not used.
422 * In an UPDATE target list, 'name' is the name of the destination column,
423 * 'indirection' stores any subscripts attached to the destination, and
424 * 'val' is the expression to assign.
426 * See A_Indirection for more info about what can appear in 'indirection'.
428 typedef struct ResTarget
431 char *name; /* column name or NULL */
432 List *indirection; /* subscripts, field names, and '*', or NIL */
433 Node *val; /* the value expression to compute or assign */
434 int location; /* token location, or -1 if unknown */
438 * MultiAssignRef - element of a row source expression for UPDATE
440 * In an UPDATE target list, when we have SET (a,b,c) = row-valued-expression,
441 * we generate separate ResTarget items for each of a,b,c. Their "val" trees
442 * are MultiAssignRef nodes numbered 1..n, linking to a common copy of the
443 * row-valued-expression (which parse analysis will process only once, when
444 * handling the MultiAssignRef with colno=1).
446 typedef struct MultiAssignRef
449 Node *source; /* the row-valued expression */
450 int colno; /* column number for this target (1..n) */
451 int ncolumns; /* number of targets in the construct */
455 * SortBy - for ORDER BY clause
457 typedef struct SortBy
460 Node *node; /* expression to sort on */
461 SortByDir sortby_dir; /* ASC/DESC/USING/default */
462 SortByNulls sortby_nulls; /* NULLS FIRST/LAST */
463 List *useOp; /* name of op to use, if SORTBY_USING */
464 int location; /* operator location, or -1 if none/unknown */
468 * WindowDef - raw representation of WINDOW and OVER clauses
470 * For entries in a WINDOW list, "name" is the window name being defined.
471 * For OVER clauses, we use "name" for the "OVER window" syntax, or "refname"
472 * for the "OVER (window)" syntax, which is subtly different --- the latter
473 * implies overriding the window frame clause.
475 typedef struct WindowDef
478 char *name; /* window's own name */
479 char *refname; /* referenced window name, if any */
480 List *partitionClause; /* PARTITION BY expression list */
481 List *orderClause; /* ORDER BY (list of SortBy) */
482 int frameOptions; /* frame_clause options, see below */
483 Node *startOffset; /* expression for starting bound, if any */
484 Node *endOffset; /* expression for ending bound, if any */
485 int location; /* parse location, or -1 if none/unknown */
489 * frameOptions is an OR of these bits. The NONDEFAULT and BETWEEN bits are
490 * used so that ruleutils.c can tell which properties were specified and
491 * which were defaulted; the correct behavioral bits must be set either way.
492 * The START_foo and END_foo options must come in pairs of adjacent bits for
493 * the convenience of gram.y, even though some of them are useless/invalid.
494 * We will need more bits (and fields) to cover the full SQL:2008 option set.
496 #define FRAMEOPTION_NONDEFAULT 0x00001 /* any specified? */
497 #define FRAMEOPTION_RANGE 0x00002 /* RANGE behavior */
498 #define FRAMEOPTION_ROWS 0x00004 /* ROWS behavior */
499 #define FRAMEOPTION_BETWEEN 0x00008 /* BETWEEN given? */
500 #define FRAMEOPTION_START_UNBOUNDED_PRECEDING 0x00010 /* start is U. P. */
501 #define FRAMEOPTION_END_UNBOUNDED_PRECEDING 0x00020 /* (disallowed) */
502 #define FRAMEOPTION_START_UNBOUNDED_FOLLOWING 0x00040 /* (disallowed) */
503 #define FRAMEOPTION_END_UNBOUNDED_FOLLOWING 0x00080 /* end is U. F. */
504 #define FRAMEOPTION_START_CURRENT_ROW 0x00100 /* start is C. R. */
505 #define FRAMEOPTION_END_CURRENT_ROW 0x00200 /* end is C. R. */
506 #define FRAMEOPTION_START_VALUE_PRECEDING 0x00400 /* start is V. P. */
507 #define FRAMEOPTION_END_VALUE_PRECEDING 0x00800 /* end is V. P. */
508 #define FRAMEOPTION_START_VALUE_FOLLOWING 0x01000 /* start is V. F. */
509 #define FRAMEOPTION_END_VALUE_FOLLOWING 0x02000 /* end is V. F. */
511 #define FRAMEOPTION_START_VALUE \
512 (FRAMEOPTION_START_VALUE_PRECEDING | FRAMEOPTION_START_VALUE_FOLLOWING)
513 #define FRAMEOPTION_END_VALUE \
514 (FRAMEOPTION_END_VALUE_PRECEDING | FRAMEOPTION_END_VALUE_FOLLOWING)
516 #define FRAMEOPTION_DEFAULTS \
517 (FRAMEOPTION_RANGE | FRAMEOPTION_START_UNBOUNDED_PRECEDING | \
518 FRAMEOPTION_END_CURRENT_ROW)
521 * RangeSubselect - subquery appearing in a FROM clause
523 typedef struct RangeSubselect
526 bool lateral; /* does it have LATERAL prefix? */
527 Node *subquery; /* the untransformed sub-select clause */
528 Alias *alias; /* table alias & optional column aliases */
532 * RangeFunction - function call appearing in a FROM clause
534 * functions is a List because we use this to represent the construct
535 * ROWS FROM(func1(...), func2(...), ...). Each element of this list is a
536 * two-element sublist, the first element being the untransformed function
537 * call tree, and the second element being a possibly-empty list of ColumnDef
538 * nodes representing any columndef list attached to that function within the
539 * ROWS FROM() syntax.
541 * alias and coldeflist represent any alias and/or columndef list attached
542 * at the top level. (We disallow coldeflist appearing both here and
543 * per-function, but that's checked in parse analysis, not by the grammar.)
545 typedef struct RangeFunction
548 bool lateral; /* does it have LATERAL prefix? */
549 bool ordinality; /* does it have WITH ORDINALITY suffix? */
550 bool is_rowsfrom; /* is result of ROWS FROM() syntax? */
551 List *functions; /* per-function information, see above */
552 Alias *alias; /* table alias & optional column aliases */
553 List *coldeflist; /* list of ColumnDef nodes to describe result
554 * of function returning RECORD */
558 * RangeTableSample - TABLESAMPLE appearing in a raw FROM clause
560 * This node, appearing only in raw parse trees, represents
561 * <relation> TABLESAMPLE <method> (<params>) REPEATABLE (<num>)
562 * Currently, the <relation> can only be a RangeVar, but we might in future
563 * allow RangeSubselect and other options. Note that the RangeTableSample
564 * is wrapped around the node representing the <relation>, rather than being
567 typedef struct RangeTableSample
570 Node *relation; /* relation to be sampled */
571 List *method; /* sampling method name (possibly qualified) */
572 List *args; /* argument(s) for sampling method */
573 Node *repeatable; /* REPEATABLE expression, or NULL if none */
574 int location; /* method name location, or -1 if unknown */
578 * ColumnDef - column definition (used in various creates)
580 * If the column has a default value, we may have the value expression
581 * in either "raw" form (an untransformed parse tree) or "cooked" form
582 * (a post-parse-analysis, executable expression tree), depending on
583 * how this ColumnDef node was created (by parsing, or by inheritance
584 * from an existing relation). We should never have both in the same node!
586 * Similarly, we may have a COLLATE specification in either raw form
587 * (represented as a CollateClause with arg==NULL) or cooked form
588 * (the collation's OID).
590 * The constraints list may contain a CONSTR_DEFAULT item in a raw
591 * parsetree produced by gram.y, but transformCreateStmt will remove
592 * the item and set raw_default instead. CONSTR_DEFAULT items
593 * should not appear in any subsequent processing.
595 typedef struct ColumnDef
598 char *colname; /* name of column */
599 TypeName *typeName; /* type of column */
600 int inhcount; /* number of times column is inherited */
601 bool is_local; /* column has local (non-inherited) def'n */
602 bool is_not_null; /* NOT NULL constraint specified? */
603 bool is_from_type; /* column definition came from table type */
604 char storage; /* attstorage setting, or 0 for default */
605 Node *raw_default; /* default value (untransformed parse tree) */
606 Node *cooked_default; /* default value (transformed expr tree) */
607 CollateClause *collClause; /* untransformed COLLATE spec, if any */
608 Oid collOid; /* collation OID (InvalidOid if not set) */
609 List *constraints; /* other constraints on column */
610 List *fdwoptions; /* per-column FDW options */
611 int location; /* parse location, or -1 if none/unknown */
615 * TableLikeClause - CREATE TABLE ( ... LIKE ... ) clause
617 typedef struct TableLikeClause
621 bits32 options; /* OR of TableLikeOption flags */
624 typedef enum TableLikeOption
626 CREATE_TABLE_LIKE_DEFAULTS = 1 << 0,
627 CREATE_TABLE_LIKE_CONSTRAINTS = 1 << 1,
628 CREATE_TABLE_LIKE_INDEXES = 1 << 2,
629 CREATE_TABLE_LIKE_STORAGE = 1 << 3,
630 CREATE_TABLE_LIKE_COMMENTS = 1 << 4,
631 CREATE_TABLE_LIKE_ALL = PG_INT32_MAX
635 * IndexElem - index parameters (used in CREATE INDEX, and in ON CONFLICT)
637 * For a plain index attribute, 'name' is the name of the table column to
638 * index, and 'expr' is NULL. For an index expression, 'name' is NULL and
639 * 'expr' is the expression tree.
641 typedef struct IndexElem
644 char *name; /* name of attribute to index, or NULL */
645 Node *expr; /* expression to index, or NULL */
646 char *indexcolname; /* name for index column; NULL = default */
647 List *collation; /* name of collation; NIL = default */
648 List *opclass; /* name of desired opclass; NIL = default */
649 SortByDir ordering; /* ASC/DESC/default */
650 SortByNulls nulls_ordering; /* FIRST/LAST/default */
654 * DefElem - a generic "name = value" option definition
656 * In some contexts the name can be qualified. Also, certain SQL commands
657 * allow a SET/ADD/DROP action to be attached to option settings, so it's
658 * convenient to carry a field for that too. (Note: currently, it is our
659 * practice that the grammar allows namespace and action only in statements
660 * where they are relevant; C code can just ignore those fields in other
663 typedef enum DefElemAction
665 DEFELEM_UNSPEC, /* no action given */
671 typedef struct DefElem
674 char *defnamespace; /* NULL if unqualified name */
676 Node *arg; /* a (Value *) or a (TypeName *) */
677 DefElemAction defaction; /* unspecified action, or SET/ADD/DROP */
678 int location; /* token location, or -1 if unknown */
682 * LockingClause - raw representation of FOR [NO KEY] UPDATE/[KEY] SHARE
685 * Note: lockedRels == NIL means "all relations in query". Otherwise it
686 * is a list of RangeVar nodes. (We use RangeVar mainly because it carries
687 * a location field --- currently, parse analysis insists on unqualified
688 * names in LockingClause.)
690 typedef struct LockingClause
693 List *lockedRels; /* FOR [KEY] UPDATE/SHARE relations */
694 LockClauseStrength strength;
695 LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */
699 * XMLSERIALIZE (in raw parse tree only)
701 typedef struct XmlSerialize
704 XmlOptionType xmloption; /* DOCUMENT or CONTENT */
707 int location; /* token location, or -1 if unknown */
710 /* Partitioning related definitions */
713 * PartitionElem - a column in the partition key
715 typedef struct PartitionElem
718 char *name; /* name of column to partition on, or NULL */
719 Node *expr; /* expression to partition on, or NULL */
720 List *collation; /* name of collation; NIL = default */
721 List *opclass; /* name of desired opclass; NIL = default */
722 int location; /* token location, or -1 if unknown */
726 * PartitionSpec - partition key specification
728 typedef struct PartitionSpec
731 char *strategy; /* partitioning strategy ('list' or 'range') */
732 List *partParams; /* List of PartitionElems */
733 int location; /* token location, or -1 if unknown */
736 #define PARTITION_STRATEGY_LIST 'l'
737 #define PARTITION_STRATEGY_RANGE 'r'
740 * PartitionBoundSpec - a partition bound specification
742 typedef struct PartitionBoundSpec
748 /* List partition values */
752 * Range partition lower and upper bounds; each member of the lists
753 * is a PartitionRangeDatum (see below).
759 } PartitionBoundSpec;
762 * PartitionRangeDatum
764 typedef struct PartitionRangeDatum
772 } PartitionRangeDatum;
775 * PartitionCmd - ALTER TABLE partition commands
777 typedef struct PartitionCmd
784 /****************************************************************************
785 * Nodes for a Query tree
786 ****************************************************************************/
788 /*--------------------
790 * A range table is a List of RangeTblEntry nodes.
792 * A range table entry may represent a plain relation, a sub-select in
793 * FROM, or the result of a JOIN clause. (Only explicit JOIN syntax
794 * produces an RTE, not the implicit join resulting from multiple FROM
795 * items. This is because we only need the RTE to deal with SQL features
796 * like outer joins and join-output-column aliasing.) Other special
797 * RTE types also exist, as indicated by RTEKind.
799 * Note that we consider RTE_RELATION to cover anything that has a pg_class
800 * entry. relkind distinguishes the sub-cases.
802 * alias is an Alias node representing the AS alias-clause attached to the
803 * FROM expression, or NULL if no clause.
805 * eref is the table reference name and column reference names (either
806 * real or aliases). Note that system columns (OID etc) are not included
807 * in the column list.
808 * eref->aliasname is required to be present, and should generally be used
809 * to identify the RTE for error messages etc.
811 * In RELATION RTEs, the colnames in both alias and eref are indexed by
812 * physical attribute number; this means there must be colname entries for
813 * dropped columns. When building an RTE we insert empty strings ("") for
814 * dropped columns. Note however that a stored rule may have nonempty
815 * colnames for columns dropped since the rule was created (and for that
816 * matter the colnames might be out of date due to column renamings).
817 * The same comments apply to FUNCTION RTEs when a function's return type
818 * is a named composite type.
820 * In JOIN RTEs, the colnames in both alias and eref are one-to-one with
821 * joinaliasvars entries. A JOIN RTE will omit columns of its inputs when
822 * those columns are known to be dropped at parse time. Again, however,
823 * a stored rule might contain entries for columns dropped since the rule
824 * was created. (This is only possible for columns not actually referenced
825 * in the rule.) When loading a stored rule, we replace the joinaliasvars
826 * items for any such columns with null pointers. (We can't simply delete
827 * them from the joinaliasvars list, because that would affect the attnums
828 * of Vars referencing the rest of the list.)
830 * inh is TRUE for relation references that should be expanded to include
831 * inheritance children, if the rel has any. This *must* be FALSE for
832 * RTEs other than RTE_RELATION entries.
834 * inFromCl marks those range variables that are listed in the FROM clause.
835 * It's false for RTEs that are added to a query behind the scenes, such
836 * as the NEW and OLD variables for a rule, or the subqueries of a UNION.
837 * This flag is not used anymore during parsing, since the parser now uses
838 * a separate "namespace" data structure to control visibility, but it is
839 * needed by ruleutils.c to determine whether RTEs should be shown in
840 * decompiled queries.
842 * requiredPerms and checkAsUser specify run-time access permissions
843 * checks to be performed at query startup. The user must have *all*
844 * of the permissions that are OR'd together in requiredPerms (zero
845 * indicates no permissions checking). If checkAsUser is not zero,
846 * then do the permissions checks using the access rights of that user,
847 * not the current effective user ID. (This allows rules to act as
848 * setuid gateways.) Permissions checks only apply to RELATION RTEs.
850 * For SELECT/INSERT/UPDATE permissions, if the user doesn't have
851 * table-wide permissions then it is sufficient to have the permissions
852 * on all columns identified in selectedCols (for SELECT) and/or
853 * insertedCols and/or updatedCols (INSERT with ON CONFLICT DO UPDATE may
854 * have all 3). selectedCols, insertedCols and updatedCols are bitmapsets,
855 * which cannot have negative integer members, so we subtract
856 * FirstLowInvalidHeapAttributeNumber from column numbers before storing
857 * them in these fields. A whole-row Var reference is represented by
858 * setting the bit for InvalidAttrNumber.
860 * securityQuals is a list of security barrier quals (boolean expressions),
861 * to be tested in the listed order before returning a row from the
862 * relation. It is always NIL in parser output. Entries are added by the
863 * rewriter to implement security-barrier views and/or row-level security.
864 * Note that the planner turns each boolean expression into an implicitly
865 * AND'ed sublist, as is its usual habit with qualification expressions.
866 *--------------------
870 RTE_RELATION, /* ordinary relation reference */
871 RTE_SUBQUERY, /* subquery in FROM */
873 RTE_FUNCTION, /* function in FROM */
874 RTE_VALUES, /* VALUES (<exprlist>), (<exprlist>), ... */
875 RTE_CTE /* common table expr (WITH list element) */
878 typedef struct RangeTblEntry
882 RTEKind rtekind; /* see above */
885 * XXX the fields applicable to only some rte kinds should be merged into
886 * a union. I didn't do this yet because the diffs would impact a lot of
887 * code that is being actively worked on. FIXME someday.
891 * Fields valid for a plain relation RTE (else zero):
893 Oid relid; /* OID of the relation */
894 char relkind; /* relation kind (see pg_class.relkind) */
895 struct TableSampleClause *tablesample; /* sampling info, or NULL */
898 * Fields valid for a subquery RTE (else NULL):
900 Query *subquery; /* the sub-query */
901 bool security_barrier; /* is from security_barrier view? */
904 * Fields valid for a join RTE (else NULL/zero):
906 * joinaliasvars is a list of (usually) Vars corresponding to the columns
907 * of the join result. An alias Var referencing column K of the join
908 * result can be replaced by the K'th element of joinaliasvars --- but to
909 * simplify the task of reverse-listing aliases correctly, we do not do
910 * that until planning time. In detail: an element of joinaliasvars can
911 * be a Var of one of the join's input relations, or such a Var with an
912 * implicit coercion to the join's output column type, or a COALESCE
913 * expression containing the two input column Vars (possibly coerced).
914 * Within a Query loaded from a stored rule, it is also possible for
915 * joinaliasvars items to be null pointers, which are placeholders for
916 * (necessarily unreferenced) columns dropped since the rule was made.
917 * Also, once planning begins, joinaliasvars items can be almost anything,
918 * as a result of subquery-flattening substitutions.
920 JoinType jointype; /* type of join */
921 List *joinaliasvars; /* list of alias-var expansions */
924 * Fields valid for a function RTE (else NIL/zero):
926 * When funcordinality is true, the eref->colnames list includes an alias
927 * for the ordinality column. The ordinality column is otherwise
928 * implicit, and must be accounted for "by hand" in places such as
931 List *functions; /* list of RangeTblFunction nodes */
932 bool funcordinality; /* is this called WITH ORDINALITY? */
935 * Fields valid for a values RTE (else NIL):
937 List *values_lists; /* list of expression lists */
940 * Fields valid for a CTE RTE (else NULL/zero):
942 char *ctename; /* name of the WITH list item */
943 Index ctelevelsup; /* number of query levels up */
944 bool self_reference; /* is this a recursive self-reference? */
947 * Fields valid for values and CTE RTEs (else NIL):
949 * We need these for CTE RTEs so that the types of self-referential
950 * columns are well-defined. For VALUES RTEs, storing these explicitly
951 * saves having to re-determine the info by scanning the values_lists.
953 List *coltypes; /* OID list of column type OIDs */
954 List *coltypmods; /* integer list of column typmods */
955 List *colcollations; /* OID list of column collation OIDs */
958 * Fields valid in all RTEs:
960 Alias *alias; /* user-written alias clause, if any */
961 Alias *eref; /* expanded reference names */
962 bool lateral; /* subquery, function, or values is LATERAL? */
963 bool inh; /* inheritance requested? */
964 bool inFromCl; /* present in FROM clause? */
965 AclMode requiredPerms; /* bitmask of required access permissions */
966 Oid checkAsUser; /* if valid, check access as this role */
967 Bitmapset *selectedCols; /* columns needing SELECT permission */
968 Bitmapset *insertedCols; /* columns needing INSERT permission */
969 Bitmapset *updatedCols; /* columns needing UPDATE permission */
970 List *securityQuals; /* security barrier quals to apply, if any */
975 * RangeTblEntry subsidiary data for one function in a FUNCTION RTE.
977 * If the function had a column definition list (required for an
978 * otherwise-unspecified RECORD result), funccolnames lists the names given
979 * in the definition list, funccoltypes lists their declared column types,
980 * funccoltypmods lists their typmods, funccolcollations their collations.
981 * Otherwise, those fields are NIL.
983 * Notice we don't attempt to store info about the results of functions
984 * returning named composite types, because those can change from time to
985 * time. We do however remember how many columns we thought the type had
986 * (including dropped columns!), so that we can successfully ignore any
987 * columns added after the query was parsed.
989 typedef struct RangeTblFunction
993 Node *funcexpr; /* expression tree for func call */
994 int funccolcount; /* number of columns it contributes to RTE */
995 /* These fields record the contents of a column definition list, if any: */
996 List *funccolnames; /* column names (list of String) */
997 List *funccoltypes; /* OID list of column type OIDs */
998 List *funccoltypmods; /* integer list of column typmods */
999 List *funccolcollations; /* OID list of column collation OIDs */
1000 /* This is set during planning for use by the executor: */
1001 Bitmapset *funcparams; /* PARAM_EXEC Param IDs affecting this func */
1005 * TableSampleClause - TABLESAMPLE appearing in a transformed FROM clause
1007 * Unlike RangeTableSample, this is a subnode of the relevant RangeTblEntry.
1009 typedef struct TableSampleClause
1012 Oid tsmhandler; /* OID of the tablesample handler function */
1013 List *args; /* tablesample argument expression(s) */
1014 Expr *repeatable; /* REPEATABLE expression, or NULL if none */
1015 } TableSampleClause;
1019 * representation of WITH CHECK OPTION checks to be applied to new tuples
1020 * when inserting/updating an auto-updatable view, or RLS WITH CHECK
1021 * policies to be applied when inserting/updating a relation with RLS.
1023 typedef enum WCOKind
1025 WCO_VIEW_CHECK, /* WCO on an auto-updatable view */
1026 WCO_RLS_INSERT_CHECK, /* RLS INSERT WITH CHECK policy */
1027 WCO_RLS_UPDATE_CHECK, /* RLS UPDATE WITH CHECK policy */
1028 WCO_RLS_CONFLICT_CHECK /* RLS ON CONFLICT DO UPDATE USING policy */
1031 typedef struct WithCheckOption
1034 WCOKind kind; /* kind of WCO */
1035 char *relname; /* name of relation that specified the WCO */
1036 char *polname; /* name of RLS policy being checked */
1037 Node *qual; /* constraint qual to check */
1038 bool cascaded; /* true for a cascaded WCO on a view */
1043 * representation of ORDER BY, GROUP BY, PARTITION BY,
1044 * DISTINCT, DISTINCT ON items
1046 * You might think that ORDER BY is only interested in defining ordering,
1047 * and GROUP/DISTINCT are only interested in defining equality. However,
1048 * one way to implement grouping is to sort and then apply a "uniq"-like
1049 * filter. So it's also interesting to keep track of possible sort operators
1050 * for GROUP/DISTINCT, and in particular to try to sort for the grouping
1051 * in a way that will also yield a requested ORDER BY ordering. So we need
1052 * to be able to compare ORDER BY and GROUP/DISTINCT lists, which motivates
1053 * the decision to give them the same representation.
1055 * tleSortGroupRef must match ressortgroupref of exactly one entry of the
1056 * query's targetlist; that is the expression to be sorted or grouped by.
1057 * eqop is the OID of the equality operator.
1058 * sortop is the OID of the ordering operator (a "<" or ">" operator),
1059 * or InvalidOid if not available.
1060 * nulls_first means about what you'd expect. If sortop is InvalidOid
1061 * then nulls_first is meaningless and should be set to false.
1062 * hashable is TRUE if eqop is hashable (note this condition also depends
1063 * on the datatype of the input expression).
1065 * In an ORDER BY item, all fields must be valid. (The eqop isn't essential
1066 * here, but it's cheap to get it along with the sortop, and requiring it
1067 * to be valid eases comparisons to grouping items.) Note that this isn't
1068 * actually enough information to determine an ordering: if the sortop is
1069 * collation-sensitive, a collation OID is needed too. We don't store the
1070 * collation in SortGroupClause because it's not available at the time the
1071 * parser builds the SortGroupClause; instead, consult the exposed collation
1072 * of the referenced targetlist expression to find out what it is.
1074 * In a grouping item, eqop must be valid. If the eqop is a btree equality
1075 * operator, then sortop should be set to a compatible ordering operator.
1076 * We prefer to set eqop/sortop/nulls_first to match any ORDER BY item that
1077 * the query presents for the same tlist item. If there is none, we just
1078 * use the default ordering op for the datatype.
1080 * If the tlist item's type has a hash opclass but no btree opclass, then
1081 * we will set eqop to the hash equality operator, sortop to InvalidOid,
1082 * and nulls_first to false. A grouping item of this kind can only be
1083 * implemented by hashing, and of course it'll never match an ORDER BY item.
1085 * The hashable flag is provided since we generally have the requisite
1086 * information readily available when the SortGroupClause is constructed,
1087 * and it's relatively expensive to get it again later. Note there is no
1088 * need for a "sortable" flag since OidIsValid(sortop) serves the purpose.
1090 * A query might have both ORDER BY and DISTINCT (or DISTINCT ON) clauses.
1091 * In SELECT DISTINCT, the distinctClause list is as long or longer than the
1092 * sortClause list, while in SELECT DISTINCT ON it's typically shorter.
1093 * The two lists must match up to the end of the shorter one --- the parser
1094 * rearranges the distinctClause if necessary to make this true. (This
1095 * restriction ensures that only one sort step is needed to both satisfy the
1096 * ORDER BY and set up for the Unique step. This is semantically necessary
1097 * for DISTINCT ON, and presents no real drawback for DISTINCT.)
1099 typedef struct SortGroupClause
1102 Index tleSortGroupRef; /* reference into targetlist */
1103 Oid eqop; /* the equality operator ('=' op) */
1104 Oid sortop; /* the ordering operator ('<' op), or 0 */
1105 bool nulls_first; /* do NULLs come before normal values? */
1106 bool hashable; /* can eqop be implemented by hashing? */
1111 * representation of CUBE, ROLLUP and GROUPING SETS clauses
1113 * In a Query with grouping sets, the groupClause contains a flat list of
1114 * SortGroupClause nodes for each distinct expression used. The actual
1115 * structure of the GROUP BY clause is given by the groupingSets tree.
1117 * In the raw parser output, GroupingSet nodes (of all types except SIMPLE
1118 * which is not used) are potentially mixed in with the expressions in the
1119 * groupClause of the SelectStmt. (An expression can't contain a GroupingSet,
1120 * but a list may mix GroupingSet and expression nodes.) At this stage, the
1121 * content of each node is a list of expressions, some of which may be RowExprs
1122 * which represent sublists rather than actual row constructors, and nested
1123 * GroupingSet nodes where legal in the grammar. The structure directly
1124 * reflects the query syntax.
1126 * In parse analysis, the transformed expressions are used to build the tlist
1127 * and groupClause list (of SortGroupClause nodes), and the groupingSets tree
1128 * is eventually reduced to a fixed format:
1130 * EMPTY nodes represent (), and obviously have no content
1132 * SIMPLE nodes represent a list of one or more expressions to be treated as an
1133 * atom by the enclosing structure; the content is an integer list of
1134 * ressortgroupref values (see SortGroupClause)
1136 * CUBE and ROLLUP nodes contain a list of one or more SIMPLE nodes.
1138 * SETS nodes contain a list of EMPTY, SIMPLE, CUBE or ROLLUP nodes, but after
1139 * parse analysis they cannot contain more SETS nodes; enough of the syntactic
1140 * transforms of the spec have been applied that we no longer have arbitrarily
1141 * deep nesting (though we still preserve the use of cube/rollup).
1143 * Note that if the groupingSets tree contains no SIMPLE nodes (only EMPTY
1144 * nodes at the leaves), then the groupClause will be empty, but this is still
1145 * an aggregation query (similar to using aggs or HAVING without GROUP BY).
1147 * As an example, the following clause:
1149 * GROUP BY GROUPING SETS ((a,b), CUBE(c,(d,e)))
1151 * looks like this after raw parsing:
1153 * SETS( RowExpr(a,b) , CUBE( c, RowExpr(d,e) ) )
1155 * and parse analysis converts it to:
1157 * SETS( SIMPLE(1,2), CUBE( SIMPLE(3), SIMPLE(4,5) ) )
1162 GROUPING_SET_SIMPLE,
1163 GROUPING_SET_ROLLUP,
1168 typedef struct GroupingSet
1171 GroupingSetKind kind;
1178 * transformed representation of WINDOW and OVER clauses
1180 * A parsed Query's windowClause list contains these structs. "name" is set
1181 * if the clause originally came from WINDOW, and is NULL if it originally
1182 * was an OVER clause (but note that we collapse out duplicate OVERs).
1183 * partitionClause and orderClause are lists of SortGroupClause structs.
1184 * winref is an ID number referenced by WindowFunc nodes; it must be unique
1185 * among the members of a Query's windowClause list.
1186 * When refname isn't null, the partitionClause is always copied from there;
1187 * the orderClause might or might not be copied (see copiedOrder); the framing
1188 * options are never copied, per spec.
1190 typedef struct WindowClause
1193 char *name; /* window name (NULL in an OVER clause) */
1194 char *refname; /* referenced window name, if any */
1195 List *partitionClause; /* PARTITION BY list */
1196 List *orderClause; /* ORDER BY list */
1197 int frameOptions; /* frame_clause options, see WindowDef */
1198 Node *startOffset; /* expression for starting bound, if any */
1199 Node *endOffset; /* expression for ending bound, if any */
1200 Index winref; /* ID referenced by window functions */
1201 bool copiedOrder; /* did we copy orderClause from refname? */
1206 * parser output representation of FOR [KEY] UPDATE/SHARE clauses
1208 * Query.rowMarks contains a separate RowMarkClause node for each relation
1209 * identified as a FOR [KEY] UPDATE/SHARE target. If one of these clauses
1210 * is applied to a subquery, we generate RowMarkClauses for all normal and
1211 * subquery rels in the subquery, but they are marked pushedDown = true to
1212 * distinguish them from clauses that were explicitly written at this query
1213 * level. Also, Query.hasForUpdate tells whether there were explicit FOR
1214 * UPDATE/SHARE/KEY SHARE clauses in the current query level.
1216 typedef struct RowMarkClause
1219 Index rti; /* range table index of target relation */
1220 LockClauseStrength strength;
1221 LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED */
1222 bool pushedDown; /* pushed down from higher query level? */
1227 * representation of WITH clause
1229 * Note: WithClause does not propagate into the Query representation;
1230 * but CommonTableExpr does.
1232 typedef struct WithClause
1235 List *ctes; /* list of CommonTableExprs */
1236 bool recursive; /* true = WITH RECURSIVE */
1237 int location; /* token location, or -1 if unknown */
1242 * ON CONFLICT unique index inference clause
1244 * Note: InferClause does not propagate into the Query representation.
1246 typedef struct InferClause
1249 List *indexElems; /* IndexElems to infer unique index */
1250 Node *whereClause; /* qualification (partial-index predicate) */
1251 char *conname; /* Constraint name, or NULL if unnamed */
1252 int location; /* token location, or -1 if unknown */
1256 * OnConflictClause -
1257 * representation of ON CONFLICT clause
1259 * Note: OnConflictClause does not propagate into the Query representation.
1261 typedef struct OnConflictClause
1264 OnConflictAction action; /* DO NOTHING or UPDATE? */
1265 InferClause *infer; /* Optional index inference clause */
1266 List *targetList; /* the target list (of ResTarget) */
1267 Node *whereClause; /* qualifications */
1268 int location; /* token location, or -1 if unknown */
1273 * representation of WITH list element
1275 * We don't currently support the SEARCH or CYCLE clause.
1277 typedef struct CommonTableExpr
1280 char *ctename; /* query name (never qualified) */
1281 List *aliascolnames; /* optional list of column names */
1282 /* SelectStmt/InsertStmt/etc before parse analysis, Query afterwards: */
1283 Node *ctequery; /* the CTE's subquery */
1284 int location; /* token location, or -1 if unknown */
1285 /* These fields are set during parse analysis: */
1286 bool cterecursive; /* is this CTE actually recursive? */
1287 int cterefcount; /* number of RTEs referencing this CTE
1288 * (excluding internal self-references) */
1289 List *ctecolnames; /* list of output column names */
1290 List *ctecoltypes; /* OID list of output column type OIDs */
1291 List *ctecoltypmods; /* integer list of output column typmods */
1292 List *ctecolcollations; /* OID list of column collation OIDs */
1295 /* Convenience macro to get the output tlist of a CTE's query */
1296 #define GetCTETargetList(cte) \
1297 (AssertMacro(IsA((cte)->ctequery, Query)), \
1298 ((Query *) (cte)->ctequery)->commandType == CMD_SELECT ? \
1299 ((Query *) (cte)->ctequery)->targetList : \
1300 ((Query *) (cte)->ctequery)->returningList)
1303 * TriggerTransition -
1304 * representation of transition row or table naming clause
1306 * Only transition tables are initially supported in the syntax, and only for
1307 * AFTER triggers, but other permutations are accepted by the parser so we can
1308 * give a meaningful message from C code.
1310 typedef struct TriggerTransition
1316 } TriggerTransition;
1318 /*****************************************************************************
1319 * Raw Grammar Output Statements
1320 *****************************************************************************/
1323 * RawStmt --- container for any one statement's raw parse tree
1325 * Parse analysis converts a raw parse tree headed by a RawStmt node into
1326 * an analyzed statement headed by a Query node. For optimizable statements,
1327 * the conversion is complex. For utility statements, the parser usually just
1328 * transfers the raw parse tree (sans RawStmt) into the utilityStmt field of
1329 * the Query node, and all the useful work happens at execution time.
1331 * stmt_location/stmt_len identify the portion of the source text string
1332 * containing this raw statement (useful for multi-statement strings).
1334 typedef struct RawStmt
1337 Node *stmt; /* raw parse tree */
1338 int stmt_location; /* start location, or -1 if unknown */
1339 int stmt_len; /* length in bytes; 0 means "rest of string" */
1342 /*****************************************************************************
1343 * Optimizable Statements
1344 *****************************************************************************/
1346 /* ----------------------
1349 * The source expression is represented by SelectStmt for both the
1350 * SELECT and VALUES cases. If selectStmt is NULL, then the query
1351 * is INSERT ... DEFAULT VALUES.
1352 * ----------------------
1354 typedef struct InsertStmt
1357 RangeVar *relation; /* relation to insert into */
1358 List *cols; /* optional: names of the target columns */
1359 Node *selectStmt; /* the source SELECT/VALUES, or NULL */
1360 OnConflictClause *onConflictClause; /* ON CONFLICT clause */
1361 List *returningList; /* list of expressions to return */
1362 WithClause *withClause; /* WITH clause */
1365 /* ----------------------
1367 * ----------------------
1369 typedef struct DeleteStmt
1372 RangeVar *relation; /* relation to delete from */
1373 List *usingClause; /* optional using clause for more tables */
1374 Node *whereClause; /* qualifications */
1375 List *returningList; /* list of expressions to return */
1376 WithClause *withClause; /* WITH clause */
1379 /* ----------------------
1381 * ----------------------
1383 typedef struct UpdateStmt
1386 RangeVar *relation; /* relation to update */
1387 List *targetList; /* the target list (of ResTarget) */
1388 Node *whereClause; /* qualifications */
1389 List *fromClause; /* optional from clause for more tables */
1390 List *returningList; /* list of expressions to return */
1391 WithClause *withClause; /* WITH clause */
1394 /* ----------------------
1397 * A "simple" SELECT is represented in the output of gram.y by a single
1398 * SelectStmt node; so is a VALUES construct. A query containing set
1399 * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt
1400 * nodes, in which the leaf nodes are component SELECTs and the internal nodes
1401 * represent UNION, INTERSECT, or EXCEPT operators. Using the same node
1402 * type for both leaf and internal nodes allows gram.y to stick ORDER BY,
1403 * LIMIT, etc, clause values into a SELECT statement without worrying
1404 * whether it is a simple or compound SELECT.
1405 * ----------------------
1407 typedef enum SetOperation
1415 typedef struct SelectStmt
1420 * These fields are used only in "leaf" SelectStmts.
1422 List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
1423 * lcons(NIL,NIL) for all (SELECT DISTINCT) */
1424 IntoClause *intoClause; /* target for SELECT INTO */
1425 List *targetList; /* the target list (of ResTarget) */
1426 List *fromClause; /* the FROM clause */
1427 Node *whereClause; /* WHERE qualification */
1428 List *groupClause; /* GROUP BY clauses */
1429 Node *havingClause; /* HAVING conditional-expression */
1430 List *windowClause; /* WINDOW window_name AS (...), ... */
1433 * In a "leaf" node representing a VALUES list, the above fields are all
1434 * null, and instead this field is set. Note that the elements of the
1435 * sublists are just expressions, without ResTarget decoration. Also note
1436 * that a list element can be DEFAULT (represented as a SetToDefault
1437 * node), regardless of the context of the VALUES list. It's up to parse
1438 * analysis to reject that where not valid.
1440 List *valuesLists; /* untransformed list of expression lists */
1443 * These fields are used in both "leaf" SelectStmts and upper-level
1446 List *sortClause; /* sort clause (a list of SortBy's) */
1447 Node *limitOffset; /* # of result tuples to skip */
1448 Node *limitCount; /* # of result tuples to return */
1449 List *lockingClause; /* FOR UPDATE (list of LockingClause's) */
1450 WithClause *withClause; /* WITH clause */
1453 * These fields are used only in upper-level SelectStmts.
1455 SetOperation op; /* type of set op */
1456 bool all; /* ALL specified? */
1457 struct SelectStmt *larg; /* left child */
1458 struct SelectStmt *rarg; /* right child */
1459 /* Eventually add fields for CORRESPONDING spec here */
1463 /* ----------------------
1464 * Set Operation node for post-analysis query trees
1466 * After parse analysis, a SELECT with set operations is represented by a
1467 * top-level Query node containing the leaf SELECTs as subqueries in its
1468 * range table. Its setOperations field shows the tree of set operations,
1469 * with leaf SelectStmt nodes replaced by RangeTblRef nodes, and internal
1470 * nodes replaced by SetOperationStmt nodes. Information about the output
1471 * column types is added, too. (Note that the child nodes do not necessarily
1472 * produce these types directly, but we've checked that their output types
1473 * can be coerced to the output column type.) Also, if it's not UNION ALL,
1474 * information about the types' sort/group semantics is provided in the form
1475 * of a SortGroupClause list (same representation as, eg, DISTINCT).
1476 * The resolved common column collations are provided too; but note that if
1477 * it's not UNION ALL, it's okay for a column to not have a common collation,
1478 * so a member of the colCollations list could be InvalidOid even though the
1479 * column has a collatable type.
1480 * ----------------------
1482 typedef struct SetOperationStmt
1485 SetOperation op; /* type of set op */
1486 bool all; /* ALL specified? */
1487 Node *larg; /* left child */
1488 Node *rarg; /* right child */
1489 /* Eventually add fields for CORRESPONDING spec here */
1491 /* Fields derived during parse analysis: */
1492 List *colTypes; /* OID list of output column type OIDs */
1493 List *colTypmods; /* integer list of output column typmods */
1494 List *colCollations; /* OID list of output column collation OIDs */
1495 List *groupClauses; /* a list of SortGroupClause's */
1496 /* groupClauses is NIL if UNION ALL, but must be set otherwise */
1500 /*****************************************************************************
1501 * Other Statements (no optimizations required)
1503 * These are not touched by parser/analyze.c except to put them into
1504 * the utilityStmt field of a Query. This is eventually passed to
1505 * ProcessUtility (by-passing rewriting and planning). Some of the
1506 * statements do need attention from parse analysis, and this is
1507 * done by routines in parser/parse_utilcmd.c after ProcessUtility
1508 * receives the command for execution.
1509 * DECLARE CURSOR, EXPLAIN, and CREATE TABLE AS are special cases:
1510 * they contain optimizable statements, which get processed normally
1511 * by parser/analyze.c.
1512 *****************************************************************************/
1515 * When a command can act on several kinds of objects with only one
1516 * parse structure required, use these constants to designate the
1517 * object type. Note that commands typically don't support all the types.
1520 typedef enum ObjectType
1522 OBJECT_ACCESS_METHOD,
1526 OBJECT_ATTRIBUTE, /* type's attribute, when distinct from column */
1535 OBJECT_DOMCONSTRAINT,
1536 OBJECT_EVENT_TRIGGER,
1539 OBJECT_FOREIGN_SERVER,
1540 OBJECT_FOREIGN_TABLE,
1554 OBJECT_TABCONSTRAINT,
1559 OBJECT_TSCONFIGURATION,
1560 OBJECT_TSDICTIONARY,
1564 OBJECT_USER_MAPPING,
1568 /* ----------------------
1569 * Create Schema Statement
1571 * NOTE: the schemaElts list contains raw parsetrees for component statements
1572 * of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
1573 * executed after the schema itself is created.
1574 * ----------------------
1576 typedef struct CreateSchemaStmt
1579 char *schemaname; /* the name of the schema to create */
1580 RoleSpec *authrole; /* the owner of the created schema */
1581 List *schemaElts; /* schema components (list of parsenodes) */
1582 bool if_not_exists; /* just do nothing if schema already exists? */
1585 typedef enum DropBehavior
1587 DROP_RESTRICT, /* drop fails if any dependent objects */
1588 DROP_CASCADE /* remove dependent objects too */
1591 /* ----------------------
1593 * ----------------------
1595 typedef struct AlterTableStmt
1598 RangeVar *relation; /* table to work on */
1599 List *cmds; /* list of subcommands */
1600 ObjectType relkind; /* type of object */
1601 bool missing_ok; /* skip error if table missing */
1604 typedef enum AlterTableType
1606 AT_AddColumn, /* add column */
1607 AT_AddColumnRecurse, /* internal to commands/tablecmds.c */
1608 AT_AddColumnToView, /* implicitly via CREATE OR REPLACE VIEW */
1609 AT_ColumnDefault, /* alter column default */
1610 AT_DropNotNull, /* alter column drop not null */
1611 AT_SetNotNull, /* alter column set not null */
1612 AT_SetStatistics, /* alter column set statistics */
1613 AT_SetOptions, /* alter column set ( options ) */
1614 AT_ResetOptions, /* alter column reset ( options ) */
1615 AT_SetStorage, /* alter column set storage */
1616 AT_DropColumn, /* drop column */
1617 AT_DropColumnRecurse, /* internal to commands/tablecmds.c */
1618 AT_AddIndex, /* add index */
1619 AT_ReAddIndex, /* internal to commands/tablecmds.c */
1620 AT_AddConstraint, /* add constraint */
1621 AT_AddConstraintRecurse, /* internal to commands/tablecmds.c */
1622 AT_ReAddConstraint, /* internal to commands/tablecmds.c */
1623 AT_AlterConstraint, /* alter constraint */
1624 AT_ValidateConstraint, /* validate constraint */
1625 AT_ValidateConstraintRecurse, /* internal to commands/tablecmds.c */
1626 AT_ProcessedConstraint, /* pre-processed add constraint (local in
1627 * parser/parse_utilcmd.c) */
1628 AT_AddIndexConstraint, /* add constraint using existing index */
1629 AT_DropConstraint, /* drop constraint */
1630 AT_DropConstraintRecurse, /* internal to commands/tablecmds.c */
1631 AT_ReAddComment, /* internal to commands/tablecmds.c */
1632 AT_AlterColumnType, /* alter column type */
1633 AT_AlterColumnGenericOptions, /* alter column OPTIONS (...) */
1634 AT_ChangeOwner, /* change owner */
1635 AT_ClusterOn, /* CLUSTER ON */
1636 AT_DropCluster, /* SET WITHOUT CLUSTER */
1637 AT_SetLogged, /* SET LOGGED */
1638 AT_SetUnLogged, /* SET UNLOGGED */
1639 AT_AddOids, /* SET WITH OIDS */
1640 AT_AddOidsRecurse, /* internal to commands/tablecmds.c */
1641 AT_DropOids, /* SET WITHOUT OIDS */
1642 AT_SetTableSpace, /* SET TABLESPACE */
1643 AT_SetRelOptions, /* SET (...) -- AM specific parameters */
1644 AT_ResetRelOptions, /* RESET (...) -- AM specific parameters */
1645 AT_ReplaceRelOptions, /* replace reloption list in its entirety */
1646 AT_EnableTrig, /* ENABLE TRIGGER name */
1647 AT_EnableAlwaysTrig, /* ENABLE ALWAYS TRIGGER name */
1648 AT_EnableReplicaTrig, /* ENABLE REPLICA TRIGGER name */
1649 AT_DisableTrig, /* DISABLE TRIGGER name */
1650 AT_EnableTrigAll, /* ENABLE TRIGGER ALL */
1651 AT_DisableTrigAll, /* DISABLE TRIGGER ALL */
1652 AT_EnableTrigUser, /* ENABLE TRIGGER USER */
1653 AT_DisableTrigUser, /* DISABLE TRIGGER USER */
1654 AT_EnableRule, /* ENABLE RULE name */
1655 AT_EnableAlwaysRule, /* ENABLE ALWAYS RULE name */
1656 AT_EnableReplicaRule, /* ENABLE REPLICA RULE name */
1657 AT_DisableRule, /* DISABLE RULE name */
1658 AT_AddInherit, /* INHERIT parent */
1659 AT_DropInherit, /* NO INHERIT parent */
1660 AT_AddOf, /* OF <type_name> */
1661 AT_DropOf, /* NOT OF */
1662 AT_ReplicaIdentity, /* REPLICA IDENTITY */
1663 AT_EnableRowSecurity, /* ENABLE ROW SECURITY */
1664 AT_DisableRowSecurity, /* DISABLE ROW SECURITY */
1665 AT_ForceRowSecurity, /* FORCE ROW SECURITY */
1666 AT_NoForceRowSecurity, /* NO FORCE ROW SECURITY */
1667 AT_GenericOptions, /* OPTIONS (...) */
1668 AT_AttachPartition, /* ATTACH PARTITION */
1669 AT_DetachPartition /* DETACH PARTITION */
1672 typedef struct ReplicaIdentityStmt
1677 } ReplicaIdentityStmt;
1679 typedef struct AlterTableCmd /* one subcommand of an ALTER TABLE */
1682 AlterTableType subtype; /* Type of table alteration to apply */
1683 char *name; /* column, constraint, or trigger to act on,
1686 Node *def; /* definition of new column, index,
1687 * constraint, or parent table */
1688 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
1689 bool missing_ok; /* skip error if missing? */
1693 /* ----------------------
1696 * The fields are used in different ways by the different variants of
1698 * ----------------------
1700 typedef struct AlterDomainStmt
1703 char subtype; /*------------
1704 * T = alter column default
1705 * N = alter column drop not null
1706 * O = alter column set not null
1707 * C = add constraint
1708 * X = drop constraint
1711 List *typeName; /* domain to work on */
1712 char *name; /* column or constraint name to act on */
1713 Node *def; /* definition of default or constraint */
1714 DropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */
1715 bool missing_ok; /* skip error if missing? */
1719 /* ----------------------
1720 * Grant|Revoke Statement
1721 * ----------------------
1723 typedef enum GrantTargetType
1725 ACL_TARGET_OBJECT, /* grant on specific named object(s) */
1726 ACL_TARGET_ALL_IN_SCHEMA, /* grant on all objects in given schema(s) */
1727 ACL_TARGET_DEFAULTS /* ALTER DEFAULT PRIVILEGES */
1730 typedef enum GrantObjectType
1732 ACL_OBJECT_COLUMN, /* column */
1733 ACL_OBJECT_RELATION, /* table, view */
1734 ACL_OBJECT_SEQUENCE, /* sequence */
1735 ACL_OBJECT_DATABASE, /* database */
1736 ACL_OBJECT_DOMAIN, /* domain */
1737 ACL_OBJECT_FDW, /* foreign-data wrapper */
1738 ACL_OBJECT_FOREIGN_SERVER, /* foreign server */
1739 ACL_OBJECT_FUNCTION, /* function */
1740 ACL_OBJECT_LANGUAGE, /* procedural language */
1741 ACL_OBJECT_LARGEOBJECT, /* largeobject */
1742 ACL_OBJECT_NAMESPACE, /* namespace */
1743 ACL_OBJECT_TABLESPACE, /* tablespace */
1744 ACL_OBJECT_TYPE /* type */
1747 typedef struct GrantStmt
1750 bool is_grant; /* true = GRANT, false = REVOKE */
1751 GrantTargetType targtype; /* type of the grant target */
1752 GrantObjectType objtype; /* kind of object being operated on */
1753 List *objects; /* list of RangeVar nodes, FuncWithArgs nodes,
1754 * or plain names (as Value strings) */
1755 List *privileges; /* list of AccessPriv nodes */
1756 /* privileges == NIL denotes ALL PRIVILEGES */
1757 List *grantees; /* list of RoleSpec nodes */
1758 bool grant_option; /* grant or revoke grant option */
1759 DropBehavior behavior; /* drop behavior (for REVOKE) */
1763 * Note: FuncWithArgs carries only the types of the input parameters of the
1764 * function. So it is sufficient to identify an existing function, but it
1765 * is not enough info to define a function nor to call it.
1767 typedef struct FuncWithArgs
1770 List *funcname; /* qualified name of function */
1771 List *funcargs; /* list of Typename nodes */
1775 * An access privilege, with optional list of column names
1776 * priv_name == NULL denotes ALL PRIVILEGES (only used with a column list)
1777 * cols == NIL denotes "all columns"
1778 * Note that simple "ALL PRIVILEGES" is represented as a NIL list, not
1779 * an AccessPriv with both fields null.
1781 typedef struct AccessPriv
1784 char *priv_name; /* string name of privilege */
1785 List *cols; /* list of Value strings */
1788 /* ----------------------
1789 * Grant/Revoke Role Statement
1791 * Note: because of the parsing ambiguity with the GRANT <privileges>
1792 * statement, granted_roles is a list of AccessPriv; the execution code
1793 * should complain if any column lists appear. grantee_roles is a list
1794 * of role names, as Value strings.
1795 * ----------------------
1797 typedef struct GrantRoleStmt
1800 List *granted_roles; /* list of roles to be granted/revoked */
1801 List *grantee_roles; /* list of member roles to add/delete */
1802 bool is_grant; /* true = GRANT, false = REVOKE */
1803 bool admin_opt; /* with admin option */
1804 RoleSpec *grantor; /* set grantor to other than current role */
1805 DropBehavior behavior; /* drop behavior (for REVOKE) */
1808 /* ----------------------
1809 * Alter Default Privileges Statement
1810 * ----------------------
1812 typedef struct AlterDefaultPrivilegesStmt
1815 List *options; /* list of DefElem */
1816 GrantStmt *action; /* GRANT/REVOKE action (with objects=NIL) */
1817 } AlterDefaultPrivilegesStmt;
1819 /* ----------------------
1822 * We support "COPY relation FROM file", "COPY relation TO file", and
1823 * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation"
1824 * and "query" must be non-NULL.
1825 * ----------------------
1827 typedef struct CopyStmt
1830 RangeVar *relation; /* the relation to copy */
1831 Node *query; /* the query (SELECT or DML statement with
1832 * RETURNING) to copy, as a raw parse tree */
1833 List *attlist; /* List of column names (as Strings), or NIL
1834 * for all columns */
1835 bool is_from; /* TO or FROM */
1836 bool is_program; /* is 'filename' a program to popen? */
1837 char *filename; /* filename, or NULL for STDIN/STDOUT */
1838 List *options; /* List of DefElem nodes */
1841 /* ----------------------
1842 * SET Statement (includes RESET)
1844 * "SET var TO DEFAULT" and "RESET var" are semantically equivalent, but we
1845 * preserve the distinction in VariableSetKind for CreateCommandTag().
1846 * ----------------------
1850 VAR_SET_VALUE, /* SET var = value */
1851 VAR_SET_DEFAULT, /* SET var TO DEFAULT */
1852 VAR_SET_CURRENT, /* SET var FROM CURRENT */
1853 VAR_SET_MULTI, /* special case for SET TRANSACTION ... */
1854 VAR_RESET, /* RESET var */
1855 VAR_RESET_ALL /* RESET ALL */
1858 typedef struct VariableSetStmt
1861 VariableSetKind kind;
1862 char *name; /* variable to be set */
1863 List *args; /* List of A_Const nodes */
1864 bool is_local; /* SET LOCAL? */
1867 /* ----------------------
1869 * ----------------------
1871 typedef struct VariableShowStmt
1877 /* ----------------------
1878 * Create Table Statement
1880 * NOTE: in the raw gram.y output, ColumnDef and Constraint nodes are
1881 * intermixed in tableElts, and constraints is NIL. After parse analysis,
1882 * tableElts contains just ColumnDefs, and constraints contains just
1883 * Constraint nodes (in fact, only CONSTR_CHECK nodes, in the present
1885 * ----------------------
1888 typedef struct CreateStmt
1891 RangeVar *relation; /* relation to create */
1892 List *tableElts; /* column definitions (list of ColumnDef) */
1893 List *inhRelations; /* relations to inherit from (list of
1895 Node *partbound; /* FOR VALUES clause */
1896 PartitionSpec *partspec; /* PARTITION BY clause */
1897 TypeName *ofTypename; /* OF typename */
1898 List *constraints; /* constraints (list of Constraint nodes) */
1899 List *options; /* options from WITH clause */
1900 OnCommitAction oncommit; /* what do we do at COMMIT? */
1901 char *tablespacename; /* table space to use, or NULL */
1902 bool if_not_exists; /* just do nothing if it already exists? */
1906 * Definitions for constraints in CreateStmt
1908 * Note that column defaults are treated as a type of constraint,
1909 * even though that's a bit odd semantically.
1911 * For constraints that use expressions (CONSTR_CHECK, CONSTR_DEFAULT)
1912 * we may have the expression in either "raw" form (an untransformed
1913 * parse tree) or "cooked" form (the nodeToString representation of
1914 * an executable expression tree), depending on how this Constraint
1915 * node was created (by parsing, or by inheritance from an existing
1916 * relation). We should never have both in the same node!
1918 * FKCONSTR_ACTION_xxx values are stored into pg_constraint.confupdtype
1919 * and pg_constraint.confdeltype columns; FKCONSTR_MATCH_xxx values are
1920 * stored into pg_constraint.confmatchtype. Changing the code values may
1921 * require an initdb!
1923 * If skip_validation is true then we skip checking that the existing rows
1924 * in the table satisfy the constraint, and just install the catalog entries
1925 * for the constraint. A new FK constraint is marked as valid iff
1926 * initially_valid is true. (Usually skip_validation and initially_valid
1927 * are inverses, but we can set both true if the table is known empty.)
1929 * Constraint attributes (DEFERRABLE etc) are initially represented as
1930 * separate Constraint nodes for simplicity of parsing. parse_utilcmd.c makes
1931 * a pass through the constraints list to insert the info into the appropriate
1936 typedef enum ConstrType /* types of constraints */
1938 CONSTR_NULL, /* not standard SQL, but a lot of people
1947 CONSTR_ATTR_DEFERRABLE, /* attributes for previous constraint node */
1948 CONSTR_ATTR_NOT_DEFERRABLE,
1949 CONSTR_ATTR_DEFERRED,
1950 CONSTR_ATTR_IMMEDIATE
1953 /* Foreign key action codes */
1954 #define FKCONSTR_ACTION_NOACTION 'a'
1955 #define FKCONSTR_ACTION_RESTRICT 'r'
1956 #define FKCONSTR_ACTION_CASCADE 'c'
1957 #define FKCONSTR_ACTION_SETNULL 'n'
1958 #define FKCONSTR_ACTION_SETDEFAULT 'd'
1960 /* Foreign key matchtype codes */
1961 #define FKCONSTR_MATCH_FULL 'f'
1962 #define FKCONSTR_MATCH_PARTIAL 'p'
1963 #define FKCONSTR_MATCH_SIMPLE 's'
1965 typedef struct Constraint
1968 ConstrType contype; /* see above */
1970 /* Fields used for most/all constraint types: */
1971 char *conname; /* Constraint name, or NULL if unnamed */
1972 bool deferrable; /* DEFERRABLE? */
1973 bool initdeferred; /* INITIALLY DEFERRED? */
1974 int location; /* token location, or -1 if unknown */
1976 /* Fields used for constraints with expressions (CHECK and DEFAULT): */
1977 bool is_no_inherit; /* is constraint non-inheritable? */
1978 Node *raw_expr; /* expr, as untransformed parse tree */
1979 char *cooked_expr; /* expr, as nodeToString representation */
1981 /* Fields used for unique constraints (UNIQUE and PRIMARY KEY): */
1982 List *keys; /* String nodes naming referenced column(s) */
1984 /* Fields used for EXCLUSION constraints: */
1985 List *exclusions; /* list of (IndexElem, operator name) pairs */
1987 /* Fields used for index constraints (UNIQUE, PRIMARY KEY, EXCLUSION): */
1988 List *options; /* options from WITH clause */
1989 char *indexname; /* existing index to use; otherwise NULL */
1990 char *indexspace; /* index tablespace; NULL for default */
1991 /* These could be, but currently are not, used for UNIQUE/PKEY: */
1992 char *access_method; /* index access method; NULL for default */
1993 Node *where_clause; /* partial index predicate */
1995 /* Fields used for FOREIGN KEY constraints: */
1996 RangeVar *pktable; /* Primary key table */
1997 List *fk_attrs; /* Attributes of foreign key */
1998 List *pk_attrs; /* Corresponding attrs in PK table */
1999 char fk_matchtype; /* FULL, PARTIAL, SIMPLE */
2000 char fk_upd_action; /* ON UPDATE action */
2001 char fk_del_action; /* ON DELETE action */
2002 List *old_conpfeqop; /* pg_constraint.conpfeqop of my former self */
2003 Oid old_pktable_oid; /* pg_constraint.confrelid of my former self */
2005 /* Fields used for constraints that allow a NOT VALID specification */
2006 bool skip_validation; /* skip validation of existing rows? */
2007 bool initially_valid; /* mark the new constraint as valid? */
2010 /* ----------------------
2011 * Create/Drop Table Space Statements
2012 * ----------------------
2015 typedef struct CreateTableSpaceStmt
2018 char *tablespacename;
2022 } CreateTableSpaceStmt;
2024 typedef struct DropTableSpaceStmt
2027 char *tablespacename;
2028 bool missing_ok; /* skip error if missing? */
2029 } DropTableSpaceStmt;
2031 typedef struct AlterTableSpaceOptionsStmt
2034 char *tablespacename;
2037 } AlterTableSpaceOptionsStmt;
2039 typedef struct AlterTableMoveAllStmt
2042 char *orig_tablespacename;
2043 ObjectType objtype; /* Object type to move */
2044 List *roles; /* List of roles to move objects of */
2045 char *new_tablespacename;
2047 } AlterTableMoveAllStmt;
2049 /* ----------------------
2050 * Create/Alter Extension Statements
2051 * ----------------------
2054 typedef struct CreateExtensionStmt
2058 bool if_not_exists; /* just do nothing if it already exists? */
2059 List *options; /* List of DefElem nodes */
2060 } CreateExtensionStmt;
2062 /* Only used for ALTER EXTENSION UPDATE; later might need an action field */
2063 typedef struct AlterExtensionStmt
2067 List *options; /* List of DefElem nodes */
2068 } AlterExtensionStmt;
2070 typedef struct AlterExtensionContentsStmt
2073 char *extname; /* Extension's name */
2074 int action; /* +1 = add object, -1 = drop object */
2075 ObjectType objtype; /* Object's type */
2076 List *objname; /* Qualified name of the object */
2077 List *objargs; /* Arguments if needed (eg, for functions) */
2078 } AlterExtensionContentsStmt;
2080 /* ----------------------
2081 * Create/Alter FOREIGN DATA WRAPPER Statements
2082 * ----------------------
2085 typedef struct CreateFdwStmt
2088 char *fdwname; /* foreign-data wrapper name */
2089 List *func_options; /* HANDLER/VALIDATOR options */
2090 List *options; /* generic options to FDW */
2093 typedef struct AlterFdwStmt
2096 char *fdwname; /* foreign-data wrapper name */
2097 List *func_options; /* HANDLER/VALIDATOR options */
2098 List *options; /* generic options to FDW */
2101 /* ----------------------
2102 * Create/Alter FOREIGN SERVER Statements
2103 * ----------------------
2106 typedef struct CreateForeignServerStmt
2109 char *servername; /* server name */
2110 char *servertype; /* optional server type */
2111 char *version; /* optional server version */
2112 char *fdwname; /* FDW name */
2113 List *options; /* generic options to server */
2114 } CreateForeignServerStmt;
2116 typedef struct AlterForeignServerStmt
2119 char *servername; /* server name */
2120 char *version; /* optional server version */
2121 List *options; /* generic options to server */
2122 bool has_version; /* version specified */
2123 } AlterForeignServerStmt;
2125 /* ----------------------
2126 * Create FOREIGN TABLE Statement
2127 * ----------------------
2130 typedef struct CreateForeignTableStmt
2135 } CreateForeignTableStmt;
2137 /* ----------------------
2138 * Create/Drop USER MAPPING Statements
2139 * ----------------------
2142 typedef struct CreateUserMappingStmt
2145 RoleSpec *user; /* user role */
2146 char *servername; /* server name */
2147 List *options; /* generic options to server */
2148 } CreateUserMappingStmt;
2150 typedef struct AlterUserMappingStmt
2153 RoleSpec *user; /* user role */
2154 char *servername; /* server name */
2155 List *options; /* generic options to server */
2156 } AlterUserMappingStmt;
2158 typedef struct DropUserMappingStmt
2161 RoleSpec *user; /* user role */
2162 char *servername; /* server name */
2163 bool missing_ok; /* ignore missing mappings */
2164 } DropUserMappingStmt;
2166 /* ----------------------
2167 * Import Foreign Schema Statement
2168 * ----------------------
2171 typedef enum ImportForeignSchemaType
2173 FDW_IMPORT_SCHEMA_ALL, /* all relations wanted */
2174 FDW_IMPORT_SCHEMA_LIMIT_TO, /* include only listed tables in import */
2175 FDW_IMPORT_SCHEMA_EXCEPT /* exclude listed tables from import */
2176 } ImportForeignSchemaType;
2178 typedef struct ImportForeignSchemaStmt
2181 char *server_name; /* FDW server name */
2182 char *remote_schema; /* remote schema name to query */
2183 char *local_schema; /* local schema to create objects in */
2184 ImportForeignSchemaType list_type; /* type of table list */
2185 List *table_list; /* List of RangeVar */
2186 List *options; /* list of options to pass to FDW */
2187 } ImportForeignSchemaStmt;
2189 /*----------------------
2190 * Create POLICY Statement
2191 *----------------------
2193 typedef struct CreatePolicyStmt
2196 char *policy_name; /* Policy's name */
2197 RangeVar *table; /* the table name the policy applies to */
2198 char *cmd_name; /* the command name the policy applies to */
2199 bool permissive; /* restrictive or permissive policy */
2200 List *roles; /* the roles associated with the policy */
2201 Node *qual; /* the policy's condition */
2202 Node *with_check; /* the policy's WITH CHECK condition. */
2205 /*----------------------
2206 * Alter POLICY Statement
2207 *----------------------
2209 typedef struct AlterPolicyStmt
2212 char *policy_name; /* Policy's name */
2213 RangeVar *table; /* the table name the policy applies to */
2214 List *roles; /* the roles associated with the policy */
2215 Node *qual; /* the policy's condition */
2216 Node *with_check; /* the policy's WITH CHECK condition. */
2219 /*----------------------
2220 * Create ACCESS METHOD Statement
2221 *----------------------
2223 typedef struct CreateAmStmt
2226 char *amname; /* access method name */
2227 List *handler_name; /* handler function name */
2228 char amtype; /* type of access method */
2231 /* ----------------------
2232 * Create TRIGGER Statement
2233 * ----------------------
2235 typedef struct CreateTrigStmt
2238 char *trigname; /* TRIGGER's name */
2239 RangeVar *relation; /* relation trigger is on */
2240 List *funcname; /* qual. name of function to call */
2241 List *args; /* list of (T_String) Values or NIL */
2242 bool row; /* ROW/STATEMENT */
2243 /* timing uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */
2244 int16 timing; /* BEFORE, AFTER, or INSTEAD */
2245 /* events uses the TRIGGER_TYPE bits defined in catalog/pg_trigger.h */
2246 int16 events; /* "OR" of INSERT/UPDATE/DELETE/TRUNCATE */
2247 List *columns; /* column names, or NIL for all columns */
2248 Node *whenClause; /* qual expression, or NULL if none */
2249 bool isconstraint; /* This is a constraint trigger */
2250 /* explicitly named transition data */
2251 List *transitionRels; /* TriggerTransition nodes, or NIL if none */
2252 /* The remaining fields are only used for constraint triggers */
2253 bool deferrable; /* [NOT] DEFERRABLE */
2254 bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
2255 RangeVar *constrrel; /* opposite relation, if RI trigger */
2258 /* ----------------------
2259 * Create EVENT TRIGGER Statement
2260 * ----------------------
2262 typedef struct CreateEventTrigStmt
2265 char *trigname; /* TRIGGER's name */
2266 char *eventname; /* event's identifier */
2267 List *whenclause; /* list of DefElems indicating filtering */
2268 List *funcname; /* qual. name of function to call */
2269 } CreateEventTrigStmt;
2271 /* ----------------------
2272 * Alter EVENT TRIGGER Statement
2273 * ----------------------
2275 typedef struct AlterEventTrigStmt
2278 char *trigname; /* TRIGGER's name */
2279 char tgenabled; /* trigger's firing configuration WRT
2280 * session_replication_role */
2281 } AlterEventTrigStmt;
2283 /* ----------------------
2284 * Create/Drop PROCEDURAL LANGUAGE Statements
2285 * Create PROCEDURAL LANGUAGE Statements
2286 * ----------------------
2288 typedef struct CreatePLangStmt
2291 bool replace; /* T => replace if already exists */
2292 char *plname; /* PL name */
2293 List *plhandler; /* PL call handler function (qual. name) */
2294 List *plinline; /* optional inline function (qual. name) */
2295 List *plvalidator; /* optional validator function (qual. name) */
2296 bool pltrusted; /* PL is trusted */
2299 /* ----------------------
2300 * Create/Alter/Drop Role Statements
2302 * Note: these node types are also used for the backwards-compatible
2303 * Create/Alter/Drop User/Group statements. In the ALTER and DROP cases
2304 * there's really no need to distinguish what the original spelling was,
2305 * but for CREATE we mark the type because the defaults vary.
2306 * ----------------------
2308 typedef enum RoleStmtType
2315 typedef struct CreateRoleStmt
2318 RoleStmtType stmt_type; /* ROLE/USER/GROUP */
2319 char *role; /* role name */
2320 List *options; /* List of DefElem nodes */
2323 typedef struct AlterRoleStmt
2326 RoleSpec *role; /* role */
2327 List *options; /* List of DefElem nodes */
2328 int action; /* +1 = add members, -1 = drop members */
2331 typedef struct AlterRoleSetStmt
2334 RoleSpec *role; /* role */
2335 char *database; /* database name, or NULL */
2336 VariableSetStmt *setstmt; /* SET or RESET subcommand */
2339 typedef struct DropRoleStmt
2342 List *roles; /* List of roles to remove */
2343 bool missing_ok; /* skip error if a role is missing? */
2346 /* ----------------------
2347 * {Create|Alter} SEQUENCE Statement
2348 * ----------------------
2351 typedef struct CreateSeqStmt
2354 RangeVar *sequence; /* the sequence to create */
2356 Oid ownerId; /* ID of owner, or InvalidOid for default */
2357 bool if_not_exists; /* just do nothing if it already exists? */
2360 typedef struct AlterSeqStmt
2363 RangeVar *sequence; /* the sequence to alter */
2365 bool missing_ok; /* skip error if a role is missing? */
2368 /* ----------------------
2369 * Create {Aggregate|Operator|Type} Statement
2370 * ----------------------
2372 typedef struct DefineStmt
2375 ObjectType kind; /* aggregate, operator, type */
2376 bool oldstyle; /* hack to signal old CREATE AGG syntax */
2377 List *defnames; /* qualified name (list of Value strings) */
2378 List *args; /* a list of TypeName (if needed) */
2379 List *definition; /* a list of DefElem */
2382 /* ----------------------
2383 * Create Domain Statement
2384 * ----------------------
2386 typedef struct CreateDomainStmt
2389 List *domainname; /* qualified name (list of Value strings) */
2390 TypeName *typeName; /* the base type */
2391 CollateClause *collClause; /* untransformed COLLATE spec, if any */
2392 List *constraints; /* constraints (list of Constraint nodes) */
2395 /* ----------------------
2396 * Create Operator Class Statement
2397 * ----------------------
2399 typedef struct CreateOpClassStmt
2402 List *opclassname; /* qualified name (list of Value strings) */
2403 List *opfamilyname; /* qualified name (ditto); NIL if omitted */
2404 char *amname; /* name of index AM opclass is for */
2405 TypeName *datatype; /* datatype of indexed column */
2406 List *items; /* List of CreateOpClassItem nodes */
2407 bool isDefault; /* Should be marked as default for type? */
2408 } CreateOpClassStmt;
2410 #define OPCLASS_ITEM_OPERATOR 1
2411 #define OPCLASS_ITEM_FUNCTION 2
2412 #define OPCLASS_ITEM_STORAGETYPE 3
2414 typedef struct CreateOpClassItem
2417 int itemtype; /* see codes above */
2418 /* fields used for an operator or function item: */
2419 List *name; /* operator or function name */
2420 List *args; /* argument types */
2421 int number; /* strategy num or support proc num */
2422 List *order_family; /* only used for ordering operators */
2423 List *class_args; /* only used for functions */
2424 /* fields used for a storagetype item: */
2425 TypeName *storedtype; /* datatype stored in index */
2426 } CreateOpClassItem;
2428 /* ----------------------
2429 * Create Operator Family Statement
2430 * ----------------------
2432 typedef struct CreateOpFamilyStmt
2435 List *opfamilyname; /* qualified name (list of Value strings) */
2436 char *amname; /* name of index AM opfamily is for */
2437 } CreateOpFamilyStmt;
2439 /* ----------------------
2440 * Alter Operator Family Statement
2441 * ----------------------
2443 typedef struct AlterOpFamilyStmt
2446 List *opfamilyname; /* qualified name (list of Value strings) */
2447 char *amname; /* name of index AM opfamily is for */
2448 bool isDrop; /* ADD or DROP the items? */
2449 List *items; /* List of CreateOpClassItem nodes */
2450 } AlterOpFamilyStmt;
2452 /* ----------------------
2453 * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
2454 * ----------------------
2457 typedef struct DropStmt
2460 List *objects; /* list of sublists of names (as Values) */
2461 List *arguments; /* list of sublists of arguments (as Values) */
2462 ObjectType removeType; /* object type */
2463 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
2464 bool missing_ok; /* skip error if object is missing? */
2465 bool concurrent; /* drop index concurrently? */
2468 /* ----------------------
2469 * Truncate Table Statement
2470 * ----------------------
2472 typedef struct TruncateStmt
2475 List *relations; /* relations (RangeVars) to be truncated */
2476 bool restart_seqs; /* restart owned sequences? */
2477 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
2480 /* ----------------------
2481 * Comment On Statement
2482 * ----------------------
2484 typedef struct CommentStmt
2487 ObjectType objtype; /* Object's type */
2488 List *objname; /* Qualified name of the object */
2489 List *objargs; /* Arguments if needed (eg, for functions) */
2490 char *comment; /* Comment to insert, or NULL to remove */
2493 /* ----------------------
2494 * SECURITY LABEL Statement
2495 * ----------------------
2497 typedef struct SecLabelStmt
2500 ObjectType objtype; /* Object's type */
2501 List *objname; /* Qualified name of the object */
2502 List *objargs; /* Arguments if needed (eg, for functions) */
2503 char *provider; /* Label provider (or NULL) */
2504 char *label; /* New security label to be assigned */
2507 /* ----------------------
2508 * Declare Cursor Statement
2510 * The "query" field is initially a raw parse tree, and is converted to a
2511 * Query node during parse analysis. Note that rewriting and planning
2512 * of the query are always postponed until execution.
2513 * ----------------------
2515 #define CURSOR_OPT_BINARY 0x0001 /* BINARY */
2516 #define CURSOR_OPT_SCROLL 0x0002 /* SCROLL explicitly given */
2517 #define CURSOR_OPT_NO_SCROLL 0x0004 /* NO SCROLL explicitly given */
2518 #define CURSOR_OPT_INSENSITIVE 0x0008 /* INSENSITIVE */
2519 #define CURSOR_OPT_HOLD 0x0010 /* WITH HOLD */
2520 /* these planner-control flags do not correspond to any SQL grammar: */
2521 #define CURSOR_OPT_FAST_PLAN 0x0020 /* prefer fast-start plan */
2522 #define CURSOR_OPT_GENERIC_PLAN 0x0040 /* force use of generic plan */
2523 #define CURSOR_OPT_CUSTOM_PLAN 0x0080 /* force use of custom plan */
2524 #define CURSOR_OPT_PARALLEL_OK 0x0100 /* parallel mode OK */
2526 typedef struct DeclareCursorStmt
2529 char *portalname; /* name of the portal (cursor) */
2530 int options; /* bitmask of options (see above) */
2531 Node *query; /* the query (see comments above) */
2532 } DeclareCursorStmt;
2534 /* ----------------------
2535 * Close Portal Statement
2536 * ----------------------
2538 typedef struct ClosePortalStmt
2541 char *portalname; /* name of the portal (cursor) */
2542 /* NULL means CLOSE ALL */
2545 /* ----------------------
2546 * Fetch Statement (also Move)
2547 * ----------------------
2549 typedef enum FetchDirection
2551 /* for these, howMany is how many rows to fetch; FETCH_ALL means ALL */
2554 /* for these, howMany indicates a position; only one row is fetched */
2559 #define FETCH_ALL LONG_MAX
2561 typedef struct FetchStmt
2564 FetchDirection direction; /* see above */
2565 long howMany; /* number of rows, or position argument */
2566 char *portalname; /* name of portal (cursor) */
2567 bool ismove; /* TRUE if MOVE */
2570 /* ----------------------
2571 * Create Index Statement
2573 * This represents creation of an index and/or an associated constraint.
2574 * If isconstraint is true, we should create a pg_constraint entry along
2575 * with the index. But if indexOid isn't InvalidOid, we are not creating an
2576 * index, just a UNIQUE/PKEY constraint using an existing index. isconstraint
2577 * must always be true in this case, and the fields describing the index
2578 * properties are empty.
2579 * ----------------------
2581 typedef struct IndexStmt
2584 char *idxname; /* name of new index, or NULL for default */
2585 RangeVar *relation; /* relation to build index on */
2586 char *accessMethod; /* name of access method (eg. btree) */
2587 char *tableSpace; /* tablespace, or NULL for default */
2588 List *indexParams; /* columns to index: a list of IndexElem */
2589 List *options; /* WITH clause options: a list of DefElem */
2590 Node *whereClause; /* qualification (partial-index predicate) */
2591 List *excludeOpNames; /* exclusion operator names, or NIL if none */
2592 char *idxcomment; /* comment to apply to index, or NULL */
2593 Oid indexOid; /* OID of an existing index, if any */
2594 Oid oldNode; /* relfilenode of existing storage, if any */
2595 bool unique; /* is index unique? */
2596 bool primary; /* is index a primary key? */
2597 bool isconstraint; /* is it for a pkey/unique constraint? */
2598 bool deferrable; /* is the constraint DEFERRABLE? */
2599 bool initdeferred; /* is the constraint INITIALLY DEFERRED? */
2600 bool transformed; /* true when transformIndexStmt is finished */
2601 bool concurrent; /* should this be a concurrent index build? */
2602 bool if_not_exists; /* just do nothing if index already exists? */
2605 /* ----------------------
2606 * Create Function Statement
2607 * ----------------------
2609 typedef struct CreateFunctionStmt
2612 bool replace; /* T => replace if already exists */
2613 List *funcname; /* qualified name of function to create */
2614 List *parameters; /* a list of FunctionParameter */
2615 TypeName *returnType; /* the return type */
2616 List *options; /* a list of DefElem */
2617 List *withClause; /* a list of DefElem */
2618 } CreateFunctionStmt;
2620 typedef enum FunctionParameterMode
2622 /* the assigned enum values appear in pg_proc, don't change 'em! */
2623 FUNC_PARAM_IN = 'i', /* input only */
2624 FUNC_PARAM_OUT = 'o', /* output only */
2625 FUNC_PARAM_INOUT = 'b', /* both */
2626 FUNC_PARAM_VARIADIC = 'v', /* variadic (always input) */
2627 FUNC_PARAM_TABLE = 't' /* table function output column */
2628 } FunctionParameterMode;
2630 typedef struct FunctionParameter
2633 char *name; /* parameter name, or NULL if not given */
2634 TypeName *argType; /* TypeName for parameter type */
2635 FunctionParameterMode mode; /* IN/OUT/etc */
2636 Node *defexpr; /* raw default expr, or NULL if not given */
2637 } FunctionParameter;
2639 typedef struct AlterFunctionStmt
2642 FuncWithArgs *func; /* name and args of function */
2643 List *actions; /* list of DefElem */
2644 } AlterFunctionStmt;
2646 /* ----------------------
2649 * DoStmt is the raw parser output, InlineCodeBlock is the execution-time API
2650 * ----------------------
2652 typedef struct DoStmt
2655 List *args; /* List of DefElem nodes */
2658 typedef struct InlineCodeBlock
2661 char *source_text; /* source text of anonymous code block */
2662 Oid langOid; /* OID of selected language */
2663 bool langIsTrusted; /* trusted property of the language */
2666 /* ----------------------
2667 * Alter Object Rename Statement
2668 * ----------------------
2670 typedef struct RenameStmt
2673 ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
2674 ObjectType relationType; /* if column name, associated relation type */
2675 RangeVar *relation; /* in case it's a table */
2676 List *object; /* in case it's some other object */
2677 List *objarg; /* argument types, if applicable */
2678 char *subname; /* name of contained object (column, rule,
2680 char *newname; /* the new name */
2681 DropBehavior behavior; /* RESTRICT or CASCADE behavior */
2682 bool missing_ok; /* skip error if missing? */
2685 /* ----------------------
2686 * ALTER object DEPENDS ON EXTENSION extname
2687 * ----------------------
2689 typedef struct AlterObjectDependsStmt
2692 ObjectType objectType; /* OBJECT_FUNCTION, OBJECT_TRIGGER, etc */
2693 RangeVar *relation; /* in case a table is involved */
2694 List *objname; /* name of the object */
2695 List *objargs; /* argument types, if applicable */
2696 Value *extname; /* extension name */
2697 } AlterObjectDependsStmt;
2699 /* ----------------------
2700 * ALTER object SET SCHEMA Statement
2701 * ----------------------
2703 typedef struct AlterObjectSchemaStmt
2706 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
2707 RangeVar *relation; /* in case it's a table */
2708 List *object; /* in case it's some other object */
2709 List *objarg; /* argument types, if applicable */
2710 char *newschema; /* the new schema */
2711 bool missing_ok; /* skip error if missing? */
2712 } AlterObjectSchemaStmt;
2714 /* ----------------------
2715 * Alter Object Owner Statement
2716 * ----------------------
2718 typedef struct AlterOwnerStmt
2721 ObjectType objectType; /* OBJECT_TABLE, OBJECT_TYPE, etc */
2722 RangeVar *relation; /* in case it's a table */
2723 List *object; /* in case it's some other object */
2724 List *objarg; /* argument types, if applicable */
2725 RoleSpec *newowner; /* the new owner */
2729 /* ----------------------
2730 * Alter Operator Set Restrict, Join
2731 * ----------------------
2733 typedef struct AlterOperatorStmt
2736 List *opername; /* operator name */
2737 List *operargs; /* operator's argument TypeNames */
2738 List *options; /* List of DefElem nodes */
2739 } AlterOperatorStmt;
2742 /* ----------------------
2743 * Create Rule Statement
2744 * ----------------------
2746 typedef struct RuleStmt
2749 RangeVar *relation; /* relation the rule is for */
2750 char *rulename; /* name of the rule */
2751 Node *whereClause; /* qualifications */
2752 CmdType event; /* SELECT, INSERT, etc */
2753 bool instead; /* is a 'do instead'? */
2754 List *actions; /* the action statements */
2755 bool replace; /* OR REPLACE */
2758 /* ----------------------
2760 * ----------------------
2762 typedef struct NotifyStmt
2765 char *conditionname; /* condition name to notify */
2766 char *payload; /* the payload string, or NULL if none */
2769 /* ----------------------
2771 * ----------------------
2773 typedef struct ListenStmt
2776 char *conditionname; /* condition name to listen on */
2779 /* ----------------------
2780 * Unlisten Statement
2781 * ----------------------
2783 typedef struct UnlistenStmt
2786 char *conditionname; /* name to unlisten on, or NULL for all */
2789 /* ----------------------
2790 * {Begin|Commit|Rollback} Transaction Statement
2791 * ----------------------
2793 typedef enum TransactionStmtKind
2796 TRANS_STMT_START, /* semantically identical to BEGIN */
2798 TRANS_STMT_ROLLBACK,
2799 TRANS_STMT_SAVEPOINT,
2801 TRANS_STMT_ROLLBACK_TO,
2803 TRANS_STMT_COMMIT_PREPARED,
2804 TRANS_STMT_ROLLBACK_PREPARED
2805 } TransactionStmtKind;
2807 typedef struct TransactionStmt
2810 TransactionStmtKind kind; /* see above */
2811 List *options; /* for BEGIN/START and savepoint commands */
2812 char *gid; /* for two-phase-commit related commands */
2815 /* ----------------------
2816 * Create Type Statement, composite types
2817 * ----------------------
2819 typedef struct CompositeTypeStmt
2822 RangeVar *typevar; /* the composite type to be created */
2823 List *coldeflist; /* list of ColumnDef nodes */
2824 } CompositeTypeStmt;
2826 /* ----------------------
2827 * Create Type Statement, enum types
2828 * ----------------------
2830 typedef struct CreateEnumStmt
2833 List *typeName; /* qualified name (list of Value strings) */
2834 List *vals; /* enum values (list of Value strings) */
2837 /* ----------------------
2838 * Create Type Statement, range types
2839 * ----------------------
2841 typedef struct CreateRangeStmt
2844 List *typeName; /* qualified name (list of Value strings) */
2845 List *params; /* range parameters (list of DefElem) */
2848 /* ----------------------
2849 * Alter Type Statement, enum types
2850 * ----------------------
2852 typedef struct AlterEnumStmt
2855 List *typeName; /* qualified name (list of Value strings) */
2856 char *oldVal; /* old enum value's name, if renaming */
2857 char *newVal; /* new enum value's name */
2858 char *newValNeighbor; /* neighboring enum value, if specified */
2859 bool newValIsAfter; /* place new enum value after neighbor? */
2860 bool skipIfNewValExists; /* no error if new already exists? */
2863 /* ----------------------
2864 * Create View Statement
2865 * ----------------------
2867 typedef enum ViewCheckOption
2871 CASCADED_CHECK_OPTION
2874 typedef struct ViewStmt
2877 RangeVar *view; /* the view to be created */
2878 List *aliases; /* target column names */
2879 Node *query; /* the SELECT query (as a raw parse tree) */
2880 bool replace; /* replace an existing view? */
2881 List *options; /* options from WITH clause */
2882 ViewCheckOption withCheckOption; /* WITH CHECK OPTION */
2885 /* ----------------------
2887 * ----------------------
2889 typedef struct LoadStmt
2892 char *filename; /* file to load */
2895 /* ----------------------
2896 * Createdb Statement
2897 * ----------------------
2899 typedef struct CreatedbStmt
2902 char *dbname; /* name of database to create */
2903 List *options; /* List of DefElem nodes */
2906 /* ----------------------
2908 * ----------------------
2910 typedef struct AlterDatabaseStmt
2913 char *dbname; /* name of database to alter */
2914 List *options; /* List of DefElem nodes */
2915 } AlterDatabaseStmt;
2917 typedef struct AlterDatabaseSetStmt
2920 char *dbname; /* database name */
2921 VariableSetStmt *setstmt; /* SET or RESET subcommand */
2922 } AlterDatabaseSetStmt;
2924 /* ----------------------
2926 * ----------------------
2928 typedef struct DropdbStmt
2931 char *dbname; /* database to drop */
2932 bool missing_ok; /* skip error if db is missing? */
2935 /* ----------------------
2936 * Alter System Statement
2937 * ----------------------
2939 typedef struct AlterSystemStmt
2942 VariableSetStmt *setstmt; /* SET subcommand */
2945 /* ----------------------
2946 * Cluster Statement (support pbrown's cluster index implementation)
2947 * ----------------------
2949 typedef struct ClusterStmt
2952 RangeVar *relation; /* relation being indexed, or NULL if all */
2953 char *indexname; /* original index defined */
2954 bool verbose; /* print progress info */
2957 /* ----------------------
2958 * Vacuum and Analyze Statements
2960 * Even though these are nominally two statements, it's convenient to use
2961 * just one node type for both. Note that at least one of VACOPT_VACUUM
2962 * and VACOPT_ANALYZE must be set in options.
2963 * ----------------------
2965 typedef enum VacuumOption
2967 VACOPT_VACUUM = 1 << 0, /* do VACUUM */
2968 VACOPT_ANALYZE = 1 << 1, /* do ANALYZE */
2969 VACOPT_VERBOSE = 1 << 2, /* print progress info */
2970 VACOPT_FREEZE = 1 << 3, /* FREEZE option */
2971 VACOPT_FULL = 1 << 4, /* FULL (non-concurrent) vacuum */
2972 VACOPT_NOWAIT = 1 << 5, /* don't wait to get lock (autovacuum only) */
2973 VACOPT_SKIPTOAST = 1 << 6, /* don't process the TOAST table, if any */
2974 VACOPT_DISABLE_PAGE_SKIPPING = 1 << 7 /* don't skip any pages */
2977 typedef struct VacuumStmt
2980 int options; /* OR of VacuumOption flags */
2981 RangeVar *relation; /* single table to process, or NULL */
2982 List *va_cols; /* list of column names, or NIL for all */
2985 /* ----------------------
2988 * The "query" field is initially a raw parse tree, and is converted to a
2989 * Query node during parse analysis. Note that rewriting and planning
2990 * of the query are always postponed until execution.
2991 * ----------------------
2993 typedef struct ExplainStmt
2996 Node *query; /* the query (see comments above) */
2997 List *options; /* list of DefElem nodes */
3000 /* ----------------------
3001 * CREATE TABLE AS Statement (a/k/a SELECT INTO)
3003 * A query written as CREATE TABLE AS will produce this node type natively.
3004 * A query written as SELECT ... INTO will be transformed to this form during
3006 * A query written as CREATE MATERIALIZED view will produce this node type,
3007 * during parse analysis, since it needs all the same data.
3009 * The "query" field is handled similarly to EXPLAIN, though note that it
3010 * can be a SELECT or an EXECUTE, but not other DML statements.
3011 * ----------------------
3013 typedef struct CreateTableAsStmt
3016 Node *query; /* the query (see comments above) */
3017 IntoClause *into; /* destination table */
3018 ObjectType relkind; /* OBJECT_TABLE or OBJECT_MATVIEW */
3019 bool is_select_into; /* it was written as SELECT INTO */
3020 bool if_not_exists; /* just do nothing if it already exists? */
3021 } CreateTableAsStmt;
3023 /* ----------------------
3024 * REFRESH MATERIALIZED VIEW Statement
3025 * ----------------------
3027 typedef struct RefreshMatViewStmt
3030 bool concurrent; /* allow concurrent access? */
3031 bool skipData; /* true for WITH NO DATA */
3032 RangeVar *relation; /* relation to insert into */
3033 } RefreshMatViewStmt;
3035 /* ----------------------
3036 * Checkpoint Statement
3037 * ----------------------
3039 typedef struct CheckPointStmt
3044 /* ----------------------
3046 * ----------------------
3049 typedef enum DiscardMode
3057 typedef struct DiscardStmt
3063 /* ----------------------
3065 * ----------------------
3067 typedef struct LockStmt
3070 List *relations; /* relations to lock */
3071 int mode; /* lock mode */
3072 bool nowait; /* no wait mode */
3075 /* ----------------------
3076 * SET CONSTRAINTS Statement
3077 * ----------------------
3079 typedef struct ConstraintsSetStmt
3082 List *constraints; /* List of names as RangeVars */
3084 } ConstraintsSetStmt;
3086 /* ----------------------
3088 * ----------------------
3091 /* Reindex options */
3092 #define REINDEXOPT_VERBOSE 1 << 0 /* print progress info */
3094 typedef enum ReindexObjectType
3096 REINDEX_OBJECT_INDEX, /* index */
3097 REINDEX_OBJECT_TABLE, /* table or materialized view */
3098 REINDEX_OBJECT_SCHEMA, /* schema */
3099 REINDEX_OBJECT_SYSTEM, /* system catalogs */
3100 REINDEX_OBJECT_DATABASE /* database */
3101 } ReindexObjectType;
3103 typedef struct ReindexStmt
3106 ReindexObjectType kind; /* REINDEX_OBJECT_INDEX, REINDEX_OBJECT_TABLE,
3108 RangeVar *relation; /* Table or index to reindex */
3109 const char *name; /* name of database to reindex */
3110 int options; /* Reindex options flags */
3113 /* ----------------------
3114 * CREATE CONVERSION Statement
3115 * ----------------------
3117 typedef struct CreateConversionStmt
3120 List *conversion_name; /* Name of the conversion */
3121 char *for_encoding_name; /* source encoding name */
3122 char *to_encoding_name; /* destination encoding name */
3123 List *func_name; /* qualified conversion function name */
3124 bool def; /* is this a default conversion? */
3125 } CreateConversionStmt;
3127 /* ----------------------
3128 * CREATE CAST Statement
3129 * ----------------------
3131 typedef struct CreateCastStmt
3134 TypeName *sourcetype;
3135 TypeName *targettype;
3137 CoercionContext context;
3141 /* ----------------------
3142 * CREATE TRANSFORM Statement
3143 * ----------------------
3145 typedef struct CreateTransformStmt
3149 TypeName *type_name;
3151 FuncWithArgs *fromsql;
3152 FuncWithArgs *tosql;
3153 } CreateTransformStmt;
3155 /* ----------------------
3157 * ----------------------
3159 typedef struct PrepareStmt
3162 char *name; /* Name of plan, arbitrary */
3163 List *argtypes; /* Types of parameters (List of TypeName) */
3164 Node *query; /* The query itself (as a raw parsetree) */
3168 /* ----------------------
3170 * ----------------------
3173 typedef struct ExecuteStmt
3176 char *name; /* The name of the plan to execute */
3177 List *params; /* Values to assign to parameters */
3181 /* ----------------------
3182 * DEALLOCATE Statement
3183 * ----------------------
3185 typedef struct DeallocateStmt
3188 char *name; /* The name of the plan to remove */
3189 /* NULL means DEALLOCATE ALL */
3193 * DROP OWNED statement
3195 typedef struct DropOwnedStmt
3199 DropBehavior behavior;
3203 * REASSIGN OWNED statement
3205 typedef struct ReassignOwnedStmt
3210 } ReassignOwnedStmt;
3213 * TS Dictionary stmts: DefineStmt, RenameStmt and DropStmt are default
3215 typedef struct AlterTSDictionaryStmt
3218 List *dictname; /* qualified name (list of Value strings) */
3219 List *options; /* List of DefElem nodes */
3220 } AlterTSDictionaryStmt;
3223 * TS Configuration stmts: DefineStmt, RenameStmt and DropStmt are default
3225 typedef enum AlterTSConfigType
3227 ALTER_TSCONFIG_ADD_MAPPING,
3228 ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN,
3229 ALTER_TSCONFIG_REPLACE_DICT,
3230 ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN,
3231 ALTER_TSCONFIG_DROP_MAPPING
3232 } AlterTSConfigType;
3234 typedef struct AlterTSConfigurationStmt
3237 AlterTSConfigType kind; /* ALTER_TSCONFIG_ADD_MAPPING, etc */
3238 List *cfgname; /* qualified name (list of Value strings) */
3241 * dicts will be non-NIL if ADD/ALTER MAPPING was specified. If dicts is
3242 * NIL, but tokentype isn't, DROP MAPPING was specified.
3244 List *tokentype; /* list of Value strings */
3245 List *dicts; /* list of list of Value strings */
3246 bool override; /* if true - remove old variant */
3247 bool replace; /* if true - replace dictionary by another */
3248 bool missing_ok; /* for DROP - skip error if missing? */
3249 } AlterTSConfigurationStmt;
3251 #endif /* PARSENODES_H */