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