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