gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

3525 lines
119KB

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