parsenodes.h 104 KB

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