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