PageRenderTime 56ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/include/nodes/parsenodes.h

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