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