2
0

parsenodes.h 128 KB

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