PageRenderTime 35ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/src/include/nodes/parsenodes.h

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