convert.go 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647
  1. //go:build !windows && cgo
  2. // +build !windows,cgo
  3. package postgresql
  4. import (
  5. "fmt"
  6. pg "github.com/pganalyze/pg_query_go/v4"
  7. "github.com/sqlc-dev/sqlc/internal/sql/ast"
  8. )
  9. func convertFuncParamMode(m pg.FunctionParameterMode) (ast.FuncParamMode, error) {
  10. switch m {
  11. case pg.FunctionParameterMode_FUNC_PARAM_IN:
  12. return ast.FuncParamIn, nil
  13. case pg.FunctionParameterMode_FUNC_PARAM_OUT:
  14. return ast.FuncParamOut, nil
  15. case pg.FunctionParameterMode_FUNC_PARAM_INOUT:
  16. return ast.FuncParamInOut, nil
  17. case pg.FunctionParameterMode_FUNC_PARAM_VARIADIC:
  18. return ast.FuncParamVariadic, nil
  19. case pg.FunctionParameterMode_FUNC_PARAM_TABLE:
  20. return ast.FuncParamTable, nil
  21. case pg.FunctionParameterMode_FUNC_PARAM_DEFAULT:
  22. return ast.FuncParamDefault, nil
  23. default:
  24. return -1, fmt.Errorf("parse func param: invalid mode %v", m)
  25. }
  26. }
  27. func convertSubLinkType(t pg.SubLinkType) (ast.SubLinkType, error) {
  28. switch t {
  29. case pg.SubLinkType_EXISTS_SUBLINK:
  30. return ast.EXISTS_SUBLINK, nil
  31. case pg.SubLinkType_ALL_SUBLINK:
  32. return ast.ALL_SUBLINK, nil
  33. case pg.SubLinkType_ANY_SUBLINK:
  34. return ast.ANY_SUBLINK, nil
  35. case pg.SubLinkType_ROWCOMPARE_SUBLINK:
  36. return ast.ROWCOMPARE_SUBLINK, nil
  37. case pg.SubLinkType_EXPR_SUBLINK:
  38. return ast.EXPR_SUBLINK, nil
  39. case pg.SubLinkType_MULTIEXPR_SUBLINK:
  40. return ast.MULTIEXPR_SUBLINK, nil
  41. case pg.SubLinkType_ARRAY_SUBLINK:
  42. return ast.ARRAY_SUBLINK, nil
  43. case pg.SubLinkType_CTE_SUBLINK:
  44. return ast.CTE_SUBLINK, nil
  45. default:
  46. return 0, fmt.Errorf("parse sublink type: unknown type %s", t)
  47. }
  48. }
  49. func convertSetOperation(t pg.SetOperation) (ast.SetOperation, error) {
  50. switch t {
  51. case pg.SetOperation_SETOP_NONE:
  52. return ast.None, nil
  53. case pg.SetOperation_SETOP_UNION:
  54. return ast.Union, nil
  55. case pg.SetOperation_SETOP_INTERSECT:
  56. return ast.Intersect, nil
  57. case pg.SetOperation_SETOP_EXCEPT:
  58. return ast.Except, nil
  59. default:
  60. return 0, fmt.Errorf("parse set operation: unknown type %s", t)
  61. }
  62. }
  63. func convertList(l *pg.List) *ast.List {
  64. out := &ast.List{}
  65. for _, item := range l.Items {
  66. out.Items = append(out.Items, convertNode(item))
  67. }
  68. return out
  69. }
  70. func convertSlice(nodes []*pg.Node) *ast.List {
  71. out := &ast.List{}
  72. for _, n := range nodes {
  73. out.Items = append(out.Items, convertNode(n))
  74. }
  75. return out
  76. }
  77. func convert(node *pg.Node) (ast.Node, error) {
  78. return convertNode(node), nil
  79. }
  80. func convertA_ArrayExpr(n *pg.A_ArrayExpr) *ast.A_ArrayExpr {
  81. if n == nil {
  82. return nil
  83. }
  84. return &ast.A_ArrayExpr{
  85. Elements: convertSlice(n.Elements),
  86. Location: int(n.Location),
  87. }
  88. }
  89. func convertA_Const(n *pg.A_Const) *ast.A_Const {
  90. if n == nil {
  91. return nil
  92. }
  93. var val ast.Node
  94. if n.Isnull {
  95. val = &ast.Null{}
  96. } else {
  97. switch v := n.Val.(type) {
  98. case *pg.A_Const_Boolval:
  99. val = convertBoolean(v.Boolval)
  100. case *pg.A_Const_Bsval:
  101. val = convertBitString(v.Bsval)
  102. case *pg.A_Const_Fval:
  103. val = convertFloat(v.Fval)
  104. case *pg.A_Const_Ival:
  105. val = convertInteger(v.Ival)
  106. case *pg.A_Const_Sval:
  107. val = convertString(v.Sval)
  108. }
  109. }
  110. return &ast.A_Const{
  111. Val: val,
  112. Location: int(n.Location),
  113. }
  114. }
  115. func convertA_Expr(n *pg.A_Expr) *ast.A_Expr {
  116. if n == nil {
  117. return nil
  118. }
  119. return &ast.A_Expr{
  120. Kind: ast.A_Expr_Kind(n.Kind),
  121. Name: convertSlice(n.Name),
  122. Lexpr: convertNode(n.Lexpr),
  123. Rexpr: convertNode(n.Rexpr),
  124. Location: int(n.Location),
  125. }
  126. }
  127. func convertA_Indices(n *pg.A_Indices) *ast.A_Indices {
  128. if n == nil {
  129. return nil
  130. }
  131. return &ast.A_Indices{
  132. IsSlice: n.IsSlice,
  133. Lidx: convertNode(n.Lidx),
  134. Uidx: convertNode(n.Uidx),
  135. }
  136. }
  137. func convertA_Indirection(n *pg.A_Indirection) *ast.A_Indirection {
  138. if n == nil {
  139. return nil
  140. }
  141. return &ast.A_Indirection{
  142. Arg: convertNode(n.Arg),
  143. Indirection: convertSlice(n.Indirection),
  144. }
  145. }
  146. func convertA_Star(n *pg.A_Star) *ast.A_Star {
  147. if n == nil {
  148. return nil
  149. }
  150. return &ast.A_Star{}
  151. }
  152. func convertAccessPriv(n *pg.AccessPriv) *ast.AccessPriv {
  153. if n == nil {
  154. return nil
  155. }
  156. return &ast.AccessPriv{
  157. PrivName: makeString(n.PrivName),
  158. Cols: convertSlice(n.Cols),
  159. }
  160. }
  161. func convertAggref(n *pg.Aggref) *ast.Aggref {
  162. if n == nil {
  163. return nil
  164. }
  165. return &ast.Aggref{
  166. Xpr: convertNode(n.Xpr),
  167. Aggfnoid: ast.Oid(n.Aggfnoid),
  168. Aggtype: ast.Oid(n.Aggtype),
  169. Aggcollid: ast.Oid(n.Aggcollid),
  170. Inputcollid: ast.Oid(n.Inputcollid),
  171. Aggtranstype: ast.Oid(n.Aggtranstype),
  172. Aggargtypes: convertSlice(n.Aggargtypes),
  173. Aggdirectargs: convertSlice(n.Aggdirectargs),
  174. Args: convertSlice(n.Args),
  175. Aggorder: convertSlice(n.Aggorder),
  176. Aggdistinct: convertSlice(n.Aggdistinct),
  177. Aggfilter: convertNode(n.Aggfilter),
  178. Aggstar: n.Aggstar,
  179. Aggvariadic: n.Aggvariadic,
  180. Aggkind: makeByte(n.Aggkind),
  181. Agglevelsup: ast.Index(n.Agglevelsup),
  182. Aggsplit: ast.AggSplit(n.Aggsplit),
  183. Location: int(n.Location),
  184. }
  185. }
  186. func convertAlias(n *pg.Alias) *ast.Alias {
  187. if n == nil {
  188. return nil
  189. }
  190. return &ast.Alias{
  191. Aliasname: makeString(n.Aliasname),
  192. Colnames: convertSlice(n.Colnames),
  193. }
  194. }
  195. func convertAlterCollationStmt(n *pg.AlterCollationStmt) *ast.AlterCollationStmt {
  196. if n == nil {
  197. return nil
  198. }
  199. return &ast.AlterCollationStmt{
  200. Collname: convertSlice(n.Collname),
  201. }
  202. }
  203. func convertAlterDatabaseSetStmt(n *pg.AlterDatabaseSetStmt) *ast.AlterDatabaseSetStmt {
  204. if n == nil {
  205. return nil
  206. }
  207. return &ast.AlterDatabaseSetStmt{
  208. Dbname: makeString(n.Dbname),
  209. Setstmt: convertVariableSetStmt(n.Setstmt),
  210. }
  211. }
  212. func convertAlterDatabaseStmt(n *pg.AlterDatabaseStmt) *ast.AlterDatabaseStmt {
  213. if n == nil {
  214. return nil
  215. }
  216. return &ast.AlterDatabaseStmt{
  217. Dbname: makeString(n.Dbname),
  218. Options: convertSlice(n.Options),
  219. }
  220. }
  221. func convertAlterDefaultPrivilegesStmt(n *pg.AlterDefaultPrivilegesStmt) *ast.AlterDefaultPrivilegesStmt {
  222. if n == nil {
  223. return nil
  224. }
  225. return &ast.AlterDefaultPrivilegesStmt{
  226. Options: convertSlice(n.Options),
  227. Action: convertGrantStmt(n.Action),
  228. }
  229. }
  230. func convertAlterDomainStmt(n *pg.AlterDomainStmt) *ast.AlterDomainStmt {
  231. if n == nil {
  232. return nil
  233. }
  234. return &ast.AlterDomainStmt{
  235. Subtype: makeByte(n.Subtype),
  236. TypeName: convertSlice(n.TypeName),
  237. Name: makeString(n.Name),
  238. Def: convertNode(n.Def),
  239. Behavior: ast.DropBehavior(n.Behavior),
  240. MissingOk: n.MissingOk,
  241. }
  242. }
  243. func convertAlterEnumStmt(n *pg.AlterEnumStmt) *ast.AlterEnumStmt {
  244. if n == nil {
  245. return nil
  246. }
  247. return &ast.AlterEnumStmt{
  248. TypeName: convertSlice(n.TypeName),
  249. OldVal: makeString(n.OldVal),
  250. NewVal: makeString(n.NewVal),
  251. NewValNeighbor: makeString(n.NewValNeighbor),
  252. NewValIsAfter: n.NewValIsAfter,
  253. SkipIfNewValExists: n.SkipIfNewValExists,
  254. }
  255. }
  256. func convertAlterEventTrigStmt(n *pg.AlterEventTrigStmt) *ast.AlterEventTrigStmt {
  257. if n == nil {
  258. return nil
  259. }
  260. return &ast.AlterEventTrigStmt{
  261. Trigname: makeString(n.Trigname),
  262. Tgenabled: makeByte(n.Tgenabled),
  263. }
  264. }
  265. func convertAlterExtensionContentsStmt(n *pg.AlterExtensionContentsStmt) *ast.AlterExtensionContentsStmt {
  266. if n == nil {
  267. return nil
  268. }
  269. return &ast.AlterExtensionContentsStmt{
  270. Extname: makeString(n.Extname),
  271. Action: int(n.Action),
  272. Objtype: ast.ObjectType(n.Objtype),
  273. Object: convertNode(n.Object),
  274. }
  275. }
  276. func convertAlterExtensionStmt(n *pg.AlterExtensionStmt) *ast.AlterExtensionStmt {
  277. if n == nil {
  278. return nil
  279. }
  280. return &ast.AlterExtensionStmt{
  281. Extname: makeString(n.Extname),
  282. Options: convertSlice(n.Options),
  283. }
  284. }
  285. func convertAlterFdwStmt(n *pg.AlterFdwStmt) *ast.AlterFdwStmt {
  286. if n == nil {
  287. return nil
  288. }
  289. return &ast.AlterFdwStmt{
  290. Fdwname: makeString(n.Fdwname),
  291. FuncOptions: convertSlice(n.FuncOptions),
  292. Options: convertSlice(n.Options),
  293. }
  294. }
  295. func convertAlterForeignServerStmt(n *pg.AlterForeignServerStmt) *ast.AlterForeignServerStmt {
  296. if n == nil {
  297. return nil
  298. }
  299. return &ast.AlterForeignServerStmt{
  300. Servername: makeString(n.Servername),
  301. Version: makeString(n.Version),
  302. Options: convertSlice(n.Options),
  303. HasVersion: n.HasVersion,
  304. }
  305. }
  306. func convertAlterFunctionStmt(n *pg.AlterFunctionStmt) *ast.AlterFunctionStmt {
  307. if n == nil {
  308. return nil
  309. }
  310. return &ast.AlterFunctionStmt{
  311. Func: convertObjectWithArgs(n.Func),
  312. Actions: convertSlice(n.Actions),
  313. }
  314. }
  315. func convertAlterObjectDependsStmt(n *pg.AlterObjectDependsStmt) *ast.AlterObjectDependsStmt {
  316. if n == nil {
  317. return nil
  318. }
  319. return &ast.AlterObjectDependsStmt{
  320. ObjectType: ast.ObjectType(n.ObjectType),
  321. Relation: convertRangeVar(n.Relation),
  322. Object: convertNode(n.Object),
  323. Extname: convertString(n.Extname),
  324. }
  325. }
  326. func convertAlterObjectSchemaStmt(n *pg.AlterObjectSchemaStmt) *ast.AlterObjectSchemaStmt {
  327. if n == nil {
  328. return nil
  329. }
  330. return &ast.AlterObjectSchemaStmt{
  331. ObjectType: ast.ObjectType(n.ObjectType),
  332. Relation: convertRangeVar(n.Relation),
  333. Object: convertNode(n.Object),
  334. Newschema: makeString(n.Newschema),
  335. MissingOk: n.MissingOk,
  336. }
  337. }
  338. func convertAlterOpFamilyStmt(n *pg.AlterOpFamilyStmt) *ast.AlterOpFamilyStmt {
  339. if n == nil {
  340. return nil
  341. }
  342. return &ast.AlterOpFamilyStmt{
  343. Opfamilyname: convertSlice(n.Opfamilyname),
  344. Amname: makeString(n.Amname),
  345. IsDrop: n.IsDrop,
  346. Items: convertSlice(n.Items),
  347. }
  348. }
  349. func convertAlterOperatorStmt(n *pg.AlterOperatorStmt) *ast.AlterOperatorStmt {
  350. if n == nil {
  351. return nil
  352. }
  353. return &ast.AlterOperatorStmt{
  354. Opername: convertObjectWithArgs(n.Opername),
  355. Options: convertSlice(n.Options),
  356. }
  357. }
  358. func convertAlterOwnerStmt(n *pg.AlterOwnerStmt) *ast.AlterOwnerStmt {
  359. if n == nil {
  360. return nil
  361. }
  362. return &ast.AlterOwnerStmt{
  363. ObjectType: ast.ObjectType(n.ObjectType),
  364. Relation: convertRangeVar(n.Relation),
  365. Object: convertNode(n.Object),
  366. Newowner: convertRoleSpec(n.Newowner),
  367. }
  368. }
  369. func convertAlterPolicyStmt(n *pg.AlterPolicyStmt) *ast.AlterPolicyStmt {
  370. if n == nil {
  371. return nil
  372. }
  373. return &ast.AlterPolicyStmt{
  374. PolicyName: makeString(n.PolicyName),
  375. Table: convertRangeVar(n.Table),
  376. Roles: convertSlice(n.Roles),
  377. Qual: convertNode(n.Qual),
  378. WithCheck: convertNode(n.WithCheck),
  379. }
  380. }
  381. func convertAlterPublicationStmt(n *pg.AlterPublicationStmt) *ast.AlterPublicationStmt {
  382. if n == nil {
  383. return nil
  384. }
  385. return &ast.AlterPublicationStmt{
  386. Pubname: makeString(n.Pubname),
  387. Options: convertSlice(n.Options),
  388. Tables: convertSlice(n.Pubobjects),
  389. ForAllTables: n.ForAllTables,
  390. TableAction: ast.DefElemAction(n.Action),
  391. }
  392. }
  393. func convertAlterRoleSetStmt(n *pg.AlterRoleSetStmt) *ast.AlterRoleSetStmt {
  394. if n == nil {
  395. return nil
  396. }
  397. return &ast.AlterRoleSetStmt{
  398. Role: convertRoleSpec(n.Role),
  399. Database: makeString(n.Database),
  400. Setstmt: convertVariableSetStmt(n.Setstmt),
  401. }
  402. }
  403. func convertAlterRoleStmt(n *pg.AlterRoleStmt) *ast.AlterRoleStmt {
  404. if n == nil {
  405. return nil
  406. }
  407. return &ast.AlterRoleStmt{
  408. Role: convertRoleSpec(n.Role),
  409. Options: convertSlice(n.Options),
  410. Action: int(n.Action),
  411. }
  412. }
  413. func convertAlterSeqStmt(n *pg.AlterSeqStmt) *ast.AlterSeqStmt {
  414. if n == nil {
  415. return nil
  416. }
  417. return &ast.AlterSeqStmt{
  418. Sequence: convertRangeVar(n.Sequence),
  419. Options: convertSlice(n.Options),
  420. ForIdentity: n.ForIdentity,
  421. MissingOk: n.MissingOk,
  422. }
  423. }
  424. func convertAlterSubscriptionStmt(n *pg.AlterSubscriptionStmt) *ast.AlterSubscriptionStmt {
  425. if n == nil {
  426. return nil
  427. }
  428. return &ast.AlterSubscriptionStmt{
  429. Kind: ast.AlterSubscriptionType(n.Kind),
  430. Subname: makeString(n.Subname),
  431. Conninfo: makeString(n.Conninfo),
  432. Publication: convertSlice(n.Publication),
  433. Options: convertSlice(n.Options),
  434. }
  435. }
  436. func convertAlterSystemStmt(n *pg.AlterSystemStmt) *ast.AlterSystemStmt {
  437. if n == nil {
  438. return nil
  439. }
  440. return &ast.AlterSystemStmt{
  441. Setstmt: convertVariableSetStmt(n.Setstmt),
  442. }
  443. }
  444. func convertAlterTSConfigurationStmt(n *pg.AlterTSConfigurationStmt) *ast.AlterTSConfigurationStmt {
  445. if n == nil {
  446. return nil
  447. }
  448. return &ast.AlterTSConfigurationStmt{
  449. Kind: ast.AlterTSConfigType(n.Kind),
  450. Cfgname: convertSlice(n.Cfgname),
  451. Tokentype: convertSlice(n.Tokentype),
  452. Dicts: convertSlice(n.Dicts),
  453. Override: n.Override,
  454. Replace: n.Replace,
  455. MissingOk: n.MissingOk,
  456. }
  457. }
  458. func convertAlterTSDictionaryStmt(n *pg.AlterTSDictionaryStmt) *ast.AlterTSDictionaryStmt {
  459. if n == nil {
  460. return nil
  461. }
  462. return &ast.AlterTSDictionaryStmt{
  463. Dictname: convertSlice(n.Dictname),
  464. Options: convertSlice(n.Options),
  465. }
  466. }
  467. func convertAlterTableCmd(n *pg.AlterTableCmd) *ast.AlterTableCmd {
  468. if n == nil {
  469. return nil
  470. }
  471. def := convertNode(n.Def)
  472. columnDef := def.(*ast.ColumnDef)
  473. return &ast.AlterTableCmd{
  474. Subtype: ast.AlterTableType(n.Subtype),
  475. Name: makeString(n.Name),
  476. Newowner: convertRoleSpec(n.Newowner),
  477. Def: columnDef,
  478. Behavior: ast.DropBehavior(n.Behavior),
  479. MissingOk: n.MissingOk,
  480. }
  481. }
  482. func convertAlterTableMoveAllStmt(n *pg.AlterTableMoveAllStmt) *ast.AlterTableMoveAllStmt {
  483. if n == nil {
  484. return nil
  485. }
  486. return &ast.AlterTableMoveAllStmt{
  487. OrigTablespacename: makeString(n.OrigTablespacename),
  488. Objtype: ast.ObjectType(n.Objtype),
  489. Roles: convertSlice(n.Roles),
  490. NewTablespacename: makeString(n.NewTablespacename),
  491. Nowait: n.Nowait,
  492. }
  493. }
  494. func convertAlterTableSpaceOptionsStmt(n *pg.AlterTableSpaceOptionsStmt) *ast.AlterTableSpaceOptionsStmt {
  495. if n == nil {
  496. return nil
  497. }
  498. return &ast.AlterTableSpaceOptionsStmt{
  499. Tablespacename: makeString(n.Tablespacename),
  500. Options: convertSlice(n.Options),
  501. IsReset: n.IsReset,
  502. }
  503. }
  504. func convertAlterTableStmt(n *pg.AlterTableStmt) *ast.AlterTableStmt {
  505. if n == nil {
  506. return nil
  507. }
  508. return &ast.AlterTableStmt{
  509. Relation: convertRangeVar(n.Relation),
  510. Cmds: convertSlice(n.Cmds),
  511. Relkind: ast.ObjectType(n.Objtype),
  512. MissingOk: n.MissingOk,
  513. }
  514. }
  515. func convertAlterUserMappingStmt(n *pg.AlterUserMappingStmt) *ast.AlterUserMappingStmt {
  516. if n == nil {
  517. return nil
  518. }
  519. return &ast.AlterUserMappingStmt{
  520. User: convertRoleSpec(n.User),
  521. Servername: makeString(n.Servername),
  522. Options: convertSlice(n.Options),
  523. }
  524. }
  525. func convertAlternativeSubPlan(n *pg.AlternativeSubPlan) *ast.AlternativeSubPlan {
  526. if n == nil {
  527. return nil
  528. }
  529. return &ast.AlternativeSubPlan{
  530. Xpr: convertNode(n.Xpr),
  531. Subplans: convertSlice(n.Subplans),
  532. }
  533. }
  534. func convertArrayCoerceExpr(n *pg.ArrayCoerceExpr) *ast.ArrayCoerceExpr {
  535. if n == nil {
  536. return nil
  537. }
  538. return &ast.ArrayCoerceExpr{
  539. Xpr: convertNode(n.Xpr),
  540. Arg: convertNode(n.Arg),
  541. Resulttype: ast.Oid(n.Resulttype),
  542. Resulttypmod: n.Resulttypmod,
  543. Resultcollid: ast.Oid(n.Resultcollid),
  544. Coerceformat: ast.CoercionForm(n.Coerceformat),
  545. Location: int(n.Location),
  546. }
  547. }
  548. func convertArrayExpr(n *pg.ArrayExpr) *ast.ArrayExpr {
  549. if n == nil {
  550. return nil
  551. }
  552. return &ast.ArrayExpr{
  553. Xpr: convertNode(n.Xpr),
  554. ArrayTypeid: ast.Oid(n.ArrayTypeid),
  555. ArrayCollid: ast.Oid(n.ArrayCollid),
  556. ElementTypeid: ast.Oid(n.ElementTypeid),
  557. Elements: convertSlice(n.Elements),
  558. Multidims: n.Multidims,
  559. Location: int(n.Location),
  560. }
  561. }
  562. func convertBitString(n *pg.BitString) *ast.BitString {
  563. if n == nil {
  564. return nil
  565. }
  566. return &ast.BitString{
  567. Str: n.Bsval,
  568. }
  569. }
  570. func convertBoolExpr(n *pg.BoolExpr) *ast.BoolExpr {
  571. if n == nil {
  572. return nil
  573. }
  574. return &ast.BoolExpr{
  575. Xpr: convertNode(n.Xpr),
  576. Boolop: ast.BoolExprType(n.Boolop),
  577. Args: convertSlice(n.Args),
  578. Location: int(n.Location),
  579. }
  580. }
  581. func convertBoolean(n *pg.Boolean) *ast.Boolean {
  582. if n == nil {
  583. return nil
  584. }
  585. return &ast.Boolean{
  586. Boolval: n.Boolval,
  587. }
  588. }
  589. func convertBooleanTest(n *pg.BooleanTest) *ast.BooleanTest {
  590. if n == nil {
  591. return nil
  592. }
  593. return &ast.BooleanTest{
  594. Xpr: convertNode(n.Xpr),
  595. Arg: convertNode(n.Arg),
  596. Booltesttype: ast.BoolTestType(n.Booltesttype),
  597. Location: int(n.Location),
  598. }
  599. }
  600. func convertCallStmt(n *pg.CallStmt) *ast.CallStmt {
  601. if n == nil {
  602. return nil
  603. }
  604. rel, err := parseRelationFromNodes(n.Funccall.Funcname)
  605. if err != nil {
  606. // TODO: How should we handle errors?
  607. panic(err)
  608. }
  609. return &ast.CallStmt{
  610. FuncCall: &ast.FuncCall{
  611. Func: rel.FuncName(),
  612. Funcname: convertSlice(n.Funccall.Funcname),
  613. Args: convertSlice(n.Funccall.Args),
  614. AggOrder: convertSlice(n.Funccall.AggOrder),
  615. AggFilter: convertNode(n.Funccall.AggFilter),
  616. AggWithinGroup: n.Funccall.AggWithinGroup,
  617. AggStar: n.Funccall.AggStar,
  618. AggDistinct: n.Funccall.AggDistinct,
  619. FuncVariadic: n.Funccall.FuncVariadic,
  620. Over: convertWindowDef(n.Funccall.Over),
  621. Location: int(n.Funccall.Location),
  622. },
  623. }
  624. }
  625. func convertCaseExpr(n *pg.CaseExpr) *ast.CaseExpr {
  626. if n == nil {
  627. return nil
  628. }
  629. return &ast.CaseExpr{
  630. Xpr: convertNode(n.Xpr),
  631. Casetype: ast.Oid(n.Casetype),
  632. Casecollid: ast.Oid(n.Casecollid),
  633. Arg: convertNode(n.Arg),
  634. Args: convertSlice(n.Args),
  635. Defresult: convertNode(n.Defresult),
  636. Location: int(n.Location),
  637. }
  638. }
  639. func convertCaseTestExpr(n *pg.CaseTestExpr) *ast.CaseTestExpr {
  640. if n == nil {
  641. return nil
  642. }
  643. return &ast.CaseTestExpr{
  644. Xpr: convertNode(n.Xpr),
  645. TypeId: ast.Oid(n.TypeId),
  646. TypeMod: n.TypeMod,
  647. Collation: ast.Oid(n.Collation),
  648. }
  649. }
  650. func convertCaseWhen(n *pg.CaseWhen) *ast.CaseWhen {
  651. if n == nil {
  652. return nil
  653. }
  654. return &ast.CaseWhen{
  655. Xpr: convertNode(n.Xpr),
  656. Expr: convertNode(n.Expr),
  657. Result: convertNode(n.Result),
  658. Location: int(n.Location),
  659. }
  660. }
  661. func convertCheckPointStmt(n *pg.CheckPointStmt) *ast.CheckPointStmt {
  662. if n == nil {
  663. return nil
  664. }
  665. return &ast.CheckPointStmt{}
  666. }
  667. func convertClosePortalStmt(n *pg.ClosePortalStmt) *ast.ClosePortalStmt {
  668. if n == nil {
  669. return nil
  670. }
  671. return &ast.ClosePortalStmt{
  672. Portalname: makeString(n.Portalname),
  673. }
  674. }
  675. func convertClusterStmt(n *pg.ClusterStmt) *ast.ClusterStmt {
  676. if n == nil {
  677. return nil
  678. }
  679. return &ast.ClusterStmt{
  680. Relation: convertRangeVar(n.Relation),
  681. Indexname: makeString(n.Indexname),
  682. }
  683. }
  684. func convertCoalesceExpr(n *pg.CoalesceExpr) *ast.CoalesceExpr {
  685. if n == nil {
  686. return nil
  687. }
  688. return &ast.CoalesceExpr{
  689. Xpr: convertNode(n.Xpr),
  690. Coalescetype: ast.Oid(n.Coalescetype),
  691. Coalescecollid: ast.Oid(n.Coalescecollid),
  692. Args: convertSlice(n.Args),
  693. Location: int(n.Location),
  694. }
  695. }
  696. func convertCoerceToDomain(n *pg.CoerceToDomain) *ast.CoerceToDomain {
  697. if n == nil {
  698. return nil
  699. }
  700. return &ast.CoerceToDomain{
  701. Xpr: convertNode(n.Xpr),
  702. Arg: convertNode(n.Arg),
  703. Resulttype: ast.Oid(n.Resulttype),
  704. Resulttypmod: n.Resulttypmod,
  705. Resultcollid: ast.Oid(n.Resultcollid),
  706. Coercionformat: ast.CoercionForm(n.Coercionformat),
  707. Location: int(n.Location),
  708. }
  709. }
  710. func convertCoerceToDomainValue(n *pg.CoerceToDomainValue) *ast.CoerceToDomainValue {
  711. if n == nil {
  712. return nil
  713. }
  714. return &ast.CoerceToDomainValue{
  715. Xpr: convertNode(n.Xpr),
  716. TypeId: ast.Oid(n.TypeId),
  717. TypeMod: n.TypeMod,
  718. Collation: ast.Oid(n.Collation),
  719. Location: int(n.Location),
  720. }
  721. }
  722. func convertCoerceViaIO(n *pg.CoerceViaIO) *ast.CoerceViaIO {
  723. if n == nil {
  724. return nil
  725. }
  726. return &ast.CoerceViaIO{
  727. Xpr: convertNode(n.Xpr),
  728. Arg: convertNode(n.Arg),
  729. Resulttype: ast.Oid(n.Resulttype),
  730. Resultcollid: ast.Oid(n.Resultcollid),
  731. Coerceformat: ast.CoercionForm(n.Coerceformat),
  732. Location: int(n.Location),
  733. }
  734. }
  735. func convertCollateClause(n *pg.CollateClause) *ast.CollateClause {
  736. if n == nil {
  737. return nil
  738. }
  739. return &ast.CollateClause{
  740. Arg: convertNode(n.Arg),
  741. Collname: convertSlice(n.Collname),
  742. Location: int(n.Location),
  743. }
  744. }
  745. func convertCollateExpr(n *pg.CollateExpr) *ast.CollateExpr {
  746. if n == nil {
  747. return nil
  748. }
  749. return &ast.CollateExpr{
  750. Xpr: convertNode(n.Xpr),
  751. Arg: convertNode(n.Arg),
  752. CollOid: ast.Oid(n.CollOid),
  753. Location: int(n.Location),
  754. }
  755. }
  756. func convertColumnDef(n *pg.ColumnDef) *ast.ColumnDef {
  757. if n == nil {
  758. return nil
  759. }
  760. return &ast.ColumnDef{
  761. Colname: n.Colname,
  762. TypeName: convertTypeName(n.TypeName),
  763. Inhcount: int(n.Inhcount),
  764. IsLocal: n.IsLocal,
  765. IsNotNull: n.IsNotNull,
  766. IsFromType: n.IsFromType,
  767. Storage: makeByte(n.Storage),
  768. RawDefault: convertNode(n.RawDefault),
  769. CookedDefault: convertNode(n.CookedDefault),
  770. Identity: makeByte(n.Identity),
  771. CollClause: convertCollateClause(n.CollClause),
  772. CollOid: ast.Oid(n.CollOid),
  773. Constraints: convertSlice(n.Constraints),
  774. Fdwoptions: convertSlice(n.Fdwoptions),
  775. Location: int(n.Location),
  776. }
  777. }
  778. func convertColumnRef(n *pg.ColumnRef) *ast.ColumnRef {
  779. if n == nil {
  780. return nil
  781. }
  782. return &ast.ColumnRef{
  783. Fields: convertSlice(n.Fields),
  784. Location: int(n.Location),
  785. }
  786. }
  787. func convertCommentStmt(n *pg.CommentStmt) *ast.CommentStmt {
  788. if n == nil {
  789. return nil
  790. }
  791. return &ast.CommentStmt{
  792. Objtype: ast.ObjectType(n.Objtype),
  793. Object: convertNode(n.Object),
  794. Comment: makeString(n.Comment),
  795. }
  796. }
  797. func convertCommonTableExpr(n *pg.CommonTableExpr) *ast.CommonTableExpr {
  798. if n == nil {
  799. return nil
  800. }
  801. return &ast.CommonTableExpr{
  802. Ctename: makeString(n.Ctename),
  803. Aliascolnames: convertSlice(n.Aliascolnames),
  804. Ctequery: convertNode(n.Ctequery),
  805. Location: int(n.Location),
  806. Cterecursive: n.Cterecursive,
  807. Cterefcount: int(n.Cterefcount),
  808. Ctecolnames: convertSlice(n.Ctecolnames),
  809. Ctecoltypes: convertSlice(n.Ctecoltypes),
  810. Ctecoltypmods: convertSlice(n.Ctecoltypmods),
  811. Ctecolcollations: convertSlice(n.Ctecolcollations),
  812. }
  813. }
  814. func convertCompositeTypeStmt(n *pg.CompositeTypeStmt) *ast.CompositeTypeStmt {
  815. if n == nil {
  816. return nil
  817. }
  818. rel := parseRelationFromRangeVar(n.Typevar)
  819. return &ast.CompositeTypeStmt{
  820. TypeName: rel.TypeName(),
  821. }
  822. }
  823. func convertConstraint(n *pg.Constraint) *ast.Constraint {
  824. if n == nil {
  825. return nil
  826. }
  827. return &ast.Constraint{
  828. Contype: ast.ConstrType(n.Contype),
  829. Conname: makeString(n.Conname),
  830. Deferrable: n.Deferrable,
  831. Initdeferred: n.Initdeferred,
  832. Location: int(n.Location),
  833. IsNoInherit: n.IsNoInherit,
  834. RawExpr: convertNode(n.RawExpr),
  835. CookedExpr: makeString(n.CookedExpr),
  836. GeneratedWhen: makeByte(n.GeneratedWhen),
  837. Keys: convertSlice(n.Keys),
  838. Exclusions: convertSlice(n.Exclusions),
  839. Options: convertSlice(n.Options),
  840. Indexname: makeString(n.Indexname),
  841. Indexspace: makeString(n.Indexspace),
  842. AccessMethod: makeString(n.AccessMethod),
  843. WhereClause: convertNode(n.WhereClause),
  844. Pktable: convertRangeVar(n.Pktable),
  845. FkAttrs: convertSlice(n.FkAttrs),
  846. PkAttrs: convertSlice(n.PkAttrs),
  847. FkMatchtype: makeByte(n.FkMatchtype),
  848. FkUpdAction: makeByte(n.FkUpdAction),
  849. FkDelAction: makeByte(n.FkDelAction),
  850. OldConpfeqop: convertSlice(n.OldConpfeqop),
  851. OldPktableOid: ast.Oid(n.OldPktableOid),
  852. SkipValidation: n.SkipValidation,
  853. InitiallyValid: n.InitiallyValid,
  854. }
  855. }
  856. func convertConstraintsSetStmt(n *pg.ConstraintsSetStmt) *ast.ConstraintsSetStmt {
  857. if n == nil {
  858. return nil
  859. }
  860. return &ast.ConstraintsSetStmt{
  861. Constraints: convertSlice(n.Constraints),
  862. Deferred: n.Deferred,
  863. }
  864. }
  865. func convertConvertRowtypeExpr(n *pg.ConvertRowtypeExpr) *ast.ConvertRowtypeExpr {
  866. if n == nil {
  867. return nil
  868. }
  869. return &ast.ConvertRowtypeExpr{
  870. Xpr: convertNode(n.Xpr),
  871. Arg: convertNode(n.Arg),
  872. Resulttype: ast.Oid(n.Resulttype),
  873. Convertformat: ast.CoercionForm(n.Convertformat),
  874. Location: int(n.Location),
  875. }
  876. }
  877. func convertCopyStmt(n *pg.CopyStmt) *ast.CopyStmt {
  878. if n == nil {
  879. return nil
  880. }
  881. return &ast.CopyStmt{
  882. Relation: convertRangeVar(n.Relation),
  883. Query: convertNode(n.Query),
  884. Attlist: convertSlice(n.Attlist),
  885. IsFrom: n.IsFrom,
  886. IsProgram: n.IsProgram,
  887. Filename: makeString(n.Filename),
  888. Options: convertSlice(n.Options),
  889. }
  890. }
  891. func convertCreateAmStmt(n *pg.CreateAmStmt) *ast.CreateAmStmt {
  892. if n == nil {
  893. return nil
  894. }
  895. return &ast.CreateAmStmt{
  896. Amname: makeString(n.Amname),
  897. HandlerName: convertSlice(n.HandlerName),
  898. Amtype: makeByte(n.Amtype),
  899. }
  900. }
  901. func convertCreateCastStmt(n *pg.CreateCastStmt) *ast.CreateCastStmt {
  902. if n == nil {
  903. return nil
  904. }
  905. return &ast.CreateCastStmt{
  906. Sourcetype: convertTypeName(n.Sourcetype),
  907. Targettype: convertTypeName(n.Targettype),
  908. Func: convertObjectWithArgs(n.Func),
  909. Context: ast.CoercionContext(n.Context),
  910. Inout: n.Inout,
  911. }
  912. }
  913. func convertCreateConversionStmt(n *pg.CreateConversionStmt) *ast.CreateConversionStmt {
  914. if n == nil {
  915. return nil
  916. }
  917. return &ast.CreateConversionStmt{
  918. ConversionName: convertSlice(n.ConversionName),
  919. ForEncodingName: makeString(n.ForEncodingName),
  920. ToEncodingName: makeString(n.ToEncodingName),
  921. FuncName: convertSlice(n.FuncName),
  922. Def: n.Def,
  923. }
  924. }
  925. func convertCreateDomainStmt(n *pg.CreateDomainStmt) *ast.CreateDomainStmt {
  926. if n == nil {
  927. return nil
  928. }
  929. return &ast.CreateDomainStmt{
  930. Domainname: convertSlice(n.Domainname),
  931. TypeName: convertTypeName(n.TypeName),
  932. CollClause: convertCollateClause(n.CollClause),
  933. Constraints: convertSlice(n.Constraints),
  934. }
  935. }
  936. func convertCreateEnumStmt(n *pg.CreateEnumStmt) *ast.CreateEnumStmt {
  937. if n == nil {
  938. return nil
  939. }
  940. rel, err := parseRelationFromNodes(n.TypeName)
  941. if err != nil {
  942. panic(err)
  943. }
  944. return &ast.CreateEnumStmt{
  945. TypeName: rel.TypeName(),
  946. Vals: convertSlice(n.Vals),
  947. }
  948. }
  949. func convertCreateEventTrigStmt(n *pg.CreateEventTrigStmt) *ast.CreateEventTrigStmt {
  950. if n == nil {
  951. return nil
  952. }
  953. return &ast.CreateEventTrigStmt{
  954. Trigname: makeString(n.Trigname),
  955. Eventname: makeString(n.Eventname),
  956. Whenclause: convertSlice(n.Whenclause),
  957. Funcname: convertSlice(n.Funcname),
  958. }
  959. }
  960. func convertCreateExtensionStmt(n *pg.CreateExtensionStmt) *ast.CreateExtensionStmt {
  961. if n == nil {
  962. return nil
  963. }
  964. return &ast.CreateExtensionStmt{
  965. Extname: makeString(n.Extname),
  966. IfNotExists: n.IfNotExists,
  967. Options: convertSlice(n.Options),
  968. }
  969. }
  970. func convertCreateFdwStmt(n *pg.CreateFdwStmt) *ast.CreateFdwStmt {
  971. if n == nil {
  972. return nil
  973. }
  974. return &ast.CreateFdwStmt{
  975. Fdwname: makeString(n.Fdwname),
  976. FuncOptions: convertSlice(n.FuncOptions),
  977. Options: convertSlice(n.Options),
  978. }
  979. }
  980. func convertCreateForeignServerStmt(n *pg.CreateForeignServerStmt) *ast.CreateForeignServerStmt {
  981. if n == nil {
  982. return nil
  983. }
  984. return &ast.CreateForeignServerStmt{
  985. Servername: makeString(n.Servername),
  986. Servertype: makeString(n.Servertype),
  987. Version: makeString(n.Version),
  988. Fdwname: makeString(n.Fdwname),
  989. IfNotExists: n.IfNotExists,
  990. Options: convertSlice(n.Options),
  991. }
  992. }
  993. func convertCreateForeignTableStmt(n *pg.CreateForeignTableStmt) *ast.CreateForeignTableStmt {
  994. if n == nil {
  995. return nil
  996. }
  997. return &ast.CreateForeignTableStmt{
  998. Servername: makeString(n.Servername),
  999. Options: convertSlice(n.Options),
  1000. }
  1001. }
  1002. func convertCreateFunctionStmt(n *pg.CreateFunctionStmt) *ast.CreateFunctionStmt {
  1003. if n == nil {
  1004. return nil
  1005. }
  1006. rel, err := parseRelationFromNodes(n.Funcname)
  1007. if err != nil {
  1008. panic(err)
  1009. }
  1010. return &ast.CreateFunctionStmt{
  1011. Replace: n.Replace,
  1012. Func: rel.FuncName(),
  1013. Params: convertSlice(n.Parameters),
  1014. ReturnType: convertTypeName(n.ReturnType),
  1015. Options: convertSlice(n.Options),
  1016. }
  1017. }
  1018. func convertCreateOpClassItem(n *pg.CreateOpClassItem) *ast.CreateOpClassItem {
  1019. if n == nil {
  1020. return nil
  1021. }
  1022. return &ast.CreateOpClassItem{
  1023. Itemtype: int(n.Itemtype),
  1024. Name: convertObjectWithArgs(n.Name),
  1025. Number: int(n.Number),
  1026. OrderFamily: convertSlice(n.OrderFamily),
  1027. ClassArgs: convertSlice(n.ClassArgs),
  1028. Storedtype: convertTypeName(n.Storedtype),
  1029. }
  1030. }
  1031. func convertCreateOpClassStmt(n *pg.CreateOpClassStmt) *ast.CreateOpClassStmt {
  1032. if n == nil {
  1033. return nil
  1034. }
  1035. return &ast.CreateOpClassStmt{
  1036. Opclassname: convertSlice(n.Opclassname),
  1037. Opfamilyname: convertSlice(n.Opfamilyname),
  1038. Amname: makeString(n.Amname),
  1039. Datatype: convertTypeName(n.Datatype),
  1040. Items: convertSlice(n.Items),
  1041. IsDefault: n.IsDefault,
  1042. }
  1043. }
  1044. func convertCreateOpFamilyStmt(n *pg.CreateOpFamilyStmt) *ast.CreateOpFamilyStmt {
  1045. if n == nil {
  1046. return nil
  1047. }
  1048. return &ast.CreateOpFamilyStmt{
  1049. Opfamilyname: convertSlice(n.Opfamilyname),
  1050. Amname: makeString(n.Amname),
  1051. }
  1052. }
  1053. func convertCreatePLangStmt(n *pg.CreatePLangStmt) *ast.CreatePLangStmt {
  1054. if n == nil {
  1055. return nil
  1056. }
  1057. return &ast.CreatePLangStmt{
  1058. Replace: n.Replace,
  1059. Plname: makeString(n.Plname),
  1060. Plhandler: convertSlice(n.Plhandler),
  1061. Plinline: convertSlice(n.Plinline),
  1062. Plvalidator: convertSlice(n.Plvalidator),
  1063. Pltrusted: n.Pltrusted,
  1064. }
  1065. }
  1066. func convertCreatePolicyStmt(n *pg.CreatePolicyStmt) *ast.CreatePolicyStmt {
  1067. if n == nil {
  1068. return nil
  1069. }
  1070. return &ast.CreatePolicyStmt{
  1071. PolicyName: makeString(n.PolicyName),
  1072. Table: convertRangeVar(n.Table),
  1073. CmdName: makeString(n.CmdName),
  1074. Permissive: n.Permissive,
  1075. Roles: convertSlice(n.Roles),
  1076. Qual: convertNode(n.Qual),
  1077. WithCheck: convertNode(n.WithCheck),
  1078. }
  1079. }
  1080. func convertCreatePublicationStmt(n *pg.CreatePublicationStmt) *ast.CreatePublicationStmt {
  1081. if n == nil {
  1082. return nil
  1083. }
  1084. return &ast.CreatePublicationStmt{
  1085. Pubname: makeString(n.Pubname),
  1086. Options: convertSlice(n.Options),
  1087. Tables: convertSlice(n.Pubobjects),
  1088. ForAllTables: n.ForAllTables,
  1089. }
  1090. }
  1091. func convertCreateRangeStmt(n *pg.CreateRangeStmt) *ast.CreateRangeStmt {
  1092. if n == nil {
  1093. return nil
  1094. }
  1095. return &ast.CreateRangeStmt{
  1096. TypeName: convertSlice(n.TypeName),
  1097. Params: convertSlice(n.Params),
  1098. }
  1099. }
  1100. func convertCreateRoleStmt(n *pg.CreateRoleStmt) *ast.CreateRoleStmt {
  1101. if n == nil {
  1102. return nil
  1103. }
  1104. return &ast.CreateRoleStmt{
  1105. StmtType: ast.RoleStmtType(n.StmtType),
  1106. Role: makeString(n.Role),
  1107. Options: convertSlice(n.Options),
  1108. }
  1109. }
  1110. func convertCreateSchemaStmt(n *pg.CreateSchemaStmt) *ast.CreateSchemaStmt {
  1111. if n == nil {
  1112. return nil
  1113. }
  1114. return &ast.CreateSchemaStmt{
  1115. Name: makeString(n.Schemaname),
  1116. Authrole: convertRoleSpec(n.Authrole),
  1117. SchemaElts: convertSlice(n.SchemaElts),
  1118. IfNotExists: n.IfNotExists,
  1119. }
  1120. }
  1121. func convertCreateSeqStmt(n *pg.CreateSeqStmt) *ast.CreateSeqStmt {
  1122. if n == nil {
  1123. return nil
  1124. }
  1125. return &ast.CreateSeqStmt{
  1126. Sequence: convertRangeVar(n.Sequence),
  1127. Options: convertSlice(n.Options),
  1128. OwnerId: ast.Oid(n.OwnerId),
  1129. ForIdentity: n.ForIdentity,
  1130. IfNotExists: n.IfNotExists,
  1131. }
  1132. }
  1133. func convertCreateStatsStmt(n *pg.CreateStatsStmt) *ast.CreateStatsStmt {
  1134. if n == nil {
  1135. return nil
  1136. }
  1137. return &ast.CreateStatsStmt{
  1138. Defnames: convertSlice(n.Defnames),
  1139. StatTypes: convertSlice(n.StatTypes),
  1140. Exprs: convertSlice(n.Exprs),
  1141. Relations: convertSlice(n.Relations),
  1142. IfNotExists: n.IfNotExists,
  1143. }
  1144. }
  1145. func convertCreateStmt(n *pg.CreateStmt) *ast.CreateStmt {
  1146. if n == nil {
  1147. return nil
  1148. }
  1149. return &ast.CreateStmt{
  1150. Relation: convertRangeVar(n.Relation),
  1151. TableElts: convertSlice(n.TableElts),
  1152. InhRelations: convertSlice(n.InhRelations),
  1153. Partbound: convertPartitionBoundSpec(n.Partbound),
  1154. Partspec: convertPartitionSpec(n.Partspec),
  1155. OfTypename: convertTypeName(n.OfTypename),
  1156. Constraints: convertSlice(n.Constraints),
  1157. Options: convertSlice(n.Options),
  1158. Oncommit: ast.OnCommitAction(n.Oncommit),
  1159. Tablespacename: makeString(n.Tablespacename),
  1160. IfNotExists: n.IfNotExists,
  1161. }
  1162. }
  1163. func convertCreateSubscriptionStmt(n *pg.CreateSubscriptionStmt) *ast.CreateSubscriptionStmt {
  1164. if n == nil {
  1165. return nil
  1166. }
  1167. return &ast.CreateSubscriptionStmt{
  1168. Subname: makeString(n.Subname),
  1169. Conninfo: makeString(n.Conninfo),
  1170. Publication: convertSlice(n.Publication),
  1171. Options: convertSlice(n.Options),
  1172. }
  1173. }
  1174. func convertCreateTableAsStmt(n *pg.CreateTableAsStmt) *ast.CreateTableAsStmt {
  1175. if n == nil {
  1176. return nil
  1177. }
  1178. res := &ast.CreateTableAsStmt{
  1179. Query: convertNode(n.Query),
  1180. Into: convertIntoClause(n.Into),
  1181. Relkind: ast.ObjectType(n.Objtype),
  1182. IsSelectInto: n.IsSelectInto,
  1183. IfNotExists: n.IfNotExists,
  1184. }
  1185. return res
  1186. }
  1187. func convertCreateTableSpaceStmt(n *pg.CreateTableSpaceStmt) *ast.CreateTableSpaceStmt {
  1188. if n == nil {
  1189. return nil
  1190. }
  1191. return &ast.CreateTableSpaceStmt{
  1192. Tablespacename: makeString(n.Tablespacename),
  1193. Owner: convertRoleSpec(n.Owner),
  1194. Location: makeString(n.Location),
  1195. Options: convertSlice(n.Options),
  1196. }
  1197. }
  1198. func convertCreateTransformStmt(n *pg.CreateTransformStmt) *ast.CreateTransformStmt {
  1199. if n == nil {
  1200. return nil
  1201. }
  1202. return &ast.CreateTransformStmt{
  1203. Replace: n.Replace,
  1204. TypeName: convertTypeName(n.TypeName),
  1205. Lang: makeString(n.Lang),
  1206. Fromsql: convertObjectWithArgs(n.Fromsql),
  1207. Tosql: convertObjectWithArgs(n.Tosql),
  1208. }
  1209. }
  1210. func convertCreateTrigStmt(n *pg.CreateTrigStmt) *ast.CreateTrigStmt {
  1211. if n == nil {
  1212. return nil
  1213. }
  1214. return &ast.CreateTrigStmt{
  1215. Trigname: makeString(n.Trigname),
  1216. Relation: convertRangeVar(n.Relation),
  1217. Funcname: convertSlice(n.Funcname),
  1218. Args: convertSlice(n.Args),
  1219. Row: n.Row,
  1220. Timing: int16(n.Timing),
  1221. Events: int16(n.Events),
  1222. Columns: convertSlice(n.Columns),
  1223. WhenClause: convertNode(n.WhenClause),
  1224. Isconstraint: n.Isconstraint,
  1225. TransitionRels: convertSlice(n.TransitionRels),
  1226. Deferrable: n.Deferrable,
  1227. Initdeferred: n.Initdeferred,
  1228. Constrrel: convertRangeVar(n.Constrrel),
  1229. }
  1230. }
  1231. func convertCreateUserMappingStmt(n *pg.CreateUserMappingStmt) *ast.CreateUserMappingStmt {
  1232. if n == nil {
  1233. return nil
  1234. }
  1235. return &ast.CreateUserMappingStmt{
  1236. User: convertRoleSpec(n.User),
  1237. Servername: makeString(n.Servername),
  1238. IfNotExists: n.IfNotExists,
  1239. Options: convertSlice(n.Options),
  1240. }
  1241. }
  1242. func convertCreatedbStmt(n *pg.CreatedbStmt) *ast.CreatedbStmt {
  1243. if n == nil {
  1244. return nil
  1245. }
  1246. return &ast.CreatedbStmt{
  1247. Dbname: makeString(n.Dbname),
  1248. Options: convertSlice(n.Options),
  1249. }
  1250. }
  1251. func convertCurrentOfExpr(n *pg.CurrentOfExpr) *ast.CurrentOfExpr {
  1252. if n == nil {
  1253. return nil
  1254. }
  1255. return &ast.CurrentOfExpr{
  1256. Xpr: convertNode(n.Xpr),
  1257. Cvarno: ast.Index(n.Cvarno),
  1258. CursorName: makeString(n.CursorName),
  1259. CursorParam: int(n.CursorParam),
  1260. }
  1261. }
  1262. func convertDeallocateStmt(n *pg.DeallocateStmt) *ast.DeallocateStmt {
  1263. if n == nil {
  1264. return nil
  1265. }
  1266. return &ast.DeallocateStmt{
  1267. Name: makeString(n.Name),
  1268. }
  1269. }
  1270. func convertDeclareCursorStmt(n *pg.DeclareCursorStmt) *ast.DeclareCursorStmt {
  1271. if n == nil {
  1272. return nil
  1273. }
  1274. return &ast.DeclareCursorStmt{
  1275. Portalname: makeString(n.Portalname),
  1276. Options: int(n.Options),
  1277. Query: convertNode(n.Query),
  1278. }
  1279. }
  1280. func convertDefElem(n *pg.DefElem) *ast.DefElem {
  1281. if n == nil {
  1282. return nil
  1283. }
  1284. return &ast.DefElem{
  1285. Defnamespace: makeString(n.Defnamespace),
  1286. Defname: makeString(n.Defname),
  1287. Arg: convertNode(n.Arg),
  1288. Defaction: ast.DefElemAction(n.Defaction),
  1289. Location: int(n.Location),
  1290. }
  1291. }
  1292. func convertDefineStmt(n *pg.DefineStmt) *ast.DefineStmt {
  1293. if n == nil {
  1294. return nil
  1295. }
  1296. return &ast.DefineStmt{
  1297. Kind: ast.ObjectType(n.Kind),
  1298. Oldstyle: n.Oldstyle,
  1299. Defnames: convertSlice(n.Defnames),
  1300. Args: convertSlice(n.Args),
  1301. Definition: convertSlice(n.Definition),
  1302. IfNotExists: n.IfNotExists,
  1303. }
  1304. }
  1305. func convertDeleteStmt(n *pg.DeleteStmt) *ast.DeleteStmt {
  1306. if n == nil {
  1307. return nil
  1308. }
  1309. return &ast.DeleteStmt{
  1310. Relations: &ast.List{
  1311. Items: []ast.Node{convertRangeVar(n.Relation)},
  1312. },
  1313. UsingClause: convertSlice(n.UsingClause),
  1314. WhereClause: convertNode(n.WhereClause),
  1315. ReturningList: convertSlice(n.ReturningList),
  1316. WithClause: convertWithClause(n.WithClause),
  1317. }
  1318. }
  1319. func convertDiscardStmt(n *pg.DiscardStmt) *ast.DiscardStmt {
  1320. if n == nil {
  1321. return nil
  1322. }
  1323. return &ast.DiscardStmt{
  1324. Target: ast.DiscardMode(n.Target),
  1325. }
  1326. }
  1327. func convertDoStmt(n *pg.DoStmt) *ast.DoStmt {
  1328. if n == nil {
  1329. return nil
  1330. }
  1331. return &ast.DoStmt{
  1332. Args: convertSlice(n.Args),
  1333. }
  1334. }
  1335. func convertDropOwnedStmt(n *pg.DropOwnedStmt) *ast.DropOwnedStmt {
  1336. if n == nil {
  1337. return nil
  1338. }
  1339. return &ast.DropOwnedStmt{
  1340. Roles: convertSlice(n.Roles),
  1341. Behavior: ast.DropBehavior(n.Behavior),
  1342. }
  1343. }
  1344. func convertDropRoleStmt(n *pg.DropRoleStmt) *ast.DropRoleStmt {
  1345. if n == nil {
  1346. return nil
  1347. }
  1348. return &ast.DropRoleStmt{
  1349. Roles: convertSlice(n.Roles),
  1350. MissingOk: n.MissingOk,
  1351. }
  1352. }
  1353. func convertDropStmt(n *pg.DropStmt) *ast.DropStmt {
  1354. if n == nil {
  1355. return nil
  1356. }
  1357. return &ast.DropStmt{
  1358. Objects: convertSlice(n.Objects),
  1359. RemoveType: ast.ObjectType(n.RemoveType),
  1360. Behavior: ast.DropBehavior(n.Behavior),
  1361. MissingOk: n.MissingOk,
  1362. Concurrent: n.Concurrent,
  1363. }
  1364. }
  1365. func convertDropSubscriptionStmt(n *pg.DropSubscriptionStmt) *ast.DropSubscriptionStmt {
  1366. if n == nil {
  1367. return nil
  1368. }
  1369. return &ast.DropSubscriptionStmt{
  1370. Subname: makeString(n.Subname),
  1371. MissingOk: n.MissingOk,
  1372. Behavior: ast.DropBehavior(n.Behavior),
  1373. }
  1374. }
  1375. func convertDropTableSpaceStmt(n *pg.DropTableSpaceStmt) *ast.DropTableSpaceStmt {
  1376. if n == nil {
  1377. return nil
  1378. }
  1379. return &ast.DropTableSpaceStmt{
  1380. Tablespacename: makeString(n.Tablespacename),
  1381. MissingOk: n.MissingOk,
  1382. }
  1383. }
  1384. func convertDropUserMappingStmt(n *pg.DropUserMappingStmt) *ast.DropUserMappingStmt {
  1385. if n == nil {
  1386. return nil
  1387. }
  1388. return &ast.DropUserMappingStmt{
  1389. User: convertRoleSpec(n.User),
  1390. Servername: makeString(n.Servername),
  1391. MissingOk: n.MissingOk,
  1392. }
  1393. }
  1394. func convertDropdbStmt(n *pg.DropdbStmt) *ast.DropdbStmt {
  1395. if n == nil {
  1396. return nil
  1397. }
  1398. return &ast.DropdbStmt{
  1399. Dbname: makeString(n.Dbname),
  1400. MissingOk: n.MissingOk,
  1401. }
  1402. }
  1403. func convertExecuteStmt(n *pg.ExecuteStmt) *ast.ExecuteStmt {
  1404. if n == nil {
  1405. return nil
  1406. }
  1407. return &ast.ExecuteStmt{
  1408. Name: makeString(n.Name),
  1409. Params: convertSlice(n.Params),
  1410. }
  1411. }
  1412. func convertExplainStmt(n *pg.ExplainStmt) *ast.ExplainStmt {
  1413. if n == nil {
  1414. return nil
  1415. }
  1416. return &ast.ExplainStmt{
  1417. Query: convertNode(n.Query),
  1418. Options: convertSlice(n.Options),
  1419. }
  1420. }
  1421. func convertFetchStmt(n *pg.FetchStmt) *ast.FetchStmt {
  1422. if n == nil {
  1423. return nil
  1424. }
  1425. return &ast.FetchStmt{
  1426. Direction: ast.FetchDirection(n.Direction),
  1427. HowMany: n.HowMany,
  1428. Portalname: makeString(n.Portalname),
  1429. Ismove: n.Ismove,
  1430. }
  1431. }
  1432. func convertFieldSelect(n *pg.FieldSelect) *ast.FieldSelect {
  1433. if n == nil {
  1434. return nil
  1435. }
  1436. return &ast.FieldSelect{
  1437. Xpr: convertNode(n.Xpr),
  1438. Arg: convertNode(n.Arg),
  1439. Fieldnum: ast.AttrNumber(n.Fieldnum),
  1440. Resulttype: ast.Oid(n.Resulttype),
  1441. Resulttypmod: n.Resulttypmod,
  1442. Resultcollid: ast.Oid(n.Resultcollid),
  1443. }
  1444. }
  1445. func convertFieldStore(n *pg.FieldStore) *ast.FieldStore {
  1446. if n == nil {
  1447. return nil
  1448. }
  1449. return &ast.FieldStore{
  1450. Xpr: convertNode(n.Xpr),
  1451. Arg: convertNode(n.Arg),
  1452. Newvals: convertSlice(n.Newvals),
  1453. Fieldnums: convertSlice(n.Fieldnums),
  1454. Resulttype: ast.Oid(n.Resulttype),
  1455. }
  1456. }
  1457. func convertFloat(n *pg.Float) *ast.Float {
  1458. if n == nil {
  1459. return nil
  1460. }
  1461. return &ast.Float{
  1462. Str: n.Fval,
  1463. }
  1464. }
  1465. func convertFromExpr(n *pg.FromExpr) *ast.FromExpr {
  1466. if n == nil {
  1467. return nil
  1468. }
  1469. return &ast.FromExpr{
  1470. Fromlist: convertSlice(n.Fromlist),
  1471. Quals: convertNode(n.Quals),
  1472. }
  1473. }
  1474. func convertFuncCall(n *pg.FuncCall) *ast.FuncCall {
  1475. if n == nil {
  1476. return nil
  1477. }
  1478. rel, err := parseRelationFromNodes(n.Funcname)
  1479. if err != nil {
  1480. // TODO: How should we handle errors?
  1481. panic(err)
  1482. }
  1483. return &ast.FuncCall{
  1484. Func: rel.FuncName(),
  1485. Funcname: convertSlice(n.Funcname),
  1486. Args: convertSlice(n.Args),
  1487. AggOrder: convertSlice(n.AggOrder),
  1488. AggFilter: convertNode(n.AggFilter),
  1489. AggWithinGroup: n.AggWithinGroup,
  1490. AggStar: n.AggStar,
  1491. AggDistinct: n.AggDistinct,
  1492. FuncVariadic: n.FuncVariadic,
  1493. Over: convertWindowDef(n.Over),
  1494. Location: int(n.Location),
  1495. }
  1496. }
  1497. func convertFuncExpr(n *pg.FuncExpr) *ast.FuncExpr {
  1498. if n == nil {
  1499. return nil
  1500. }
  1501. return &ast.FuncExpr{
  1502. Xpr: convertNode(n.Xpr),
  1503. Funcid: ast.Oid(n.Funcid),
  1504. Funcresulttype: ast.Oid(n.Funcresulttype),
  1505. Funcretset: n.Funcretset,
  1506. Funcvariadic: n.Funcvariadic,
  1507. Funcformat: ast.CoercionForm(n.Funcformat),
  1508. Funccollid: ast.Oid(n.Funccollid),
  1509. Inputcollid: ast.Oid(n.Inputcollid),
  1510. Args: convertSlice(n.Args),
  1511. Location: int(n.Location),
  1512. }
  1513. }
  1514. func convertFunctionParameter(n *pg.FunctionParameter) *ast.FunctionParameter {
  1515. if n == nil {
  1516. return nil
  1517. }
  1518. return &ast.FunctionParameter{
  1519. Name: makeString(n.Name),
  1520. ArgType: convertTypeName(n.ArgType),
  1521. Mode: ast.FunctionParameterMode(n.Mode),
  1522. Defexpr: convertNode(n.Defexpr),
  1523. }
  1524. }
  1525. func convertGrantRoleStmt(n *pg.GrantRoleStmt) *ast.GrantRoleStmt {
  1526. if n == nil {
  1527. return nil
  1528. }
  1529. return &ast.GrantRoleStmt{
  1530. GrantedRoles: convertSlice(n.GrantedRoles),
  1531. GranteeRoles: convertSlice(n.GranteeRoles),
  1532. IsGrant: n.IsGrant,
  1533. AdminOpt: n.AdminOpt,
  1534. Grantor: convertRoleSpec(n.Grantor),
  1535. Behavior: ast.DropBehavior(n.Behavior),
  1536. }
  1537. }
  1538. func convertGrantStmt(n *pg.GrantStmt) *ast.GrantStmt {
  1539. if n == nil {
  1540. return nil
  1541. }
  1542. return &ast.GrantStmt{
  1543. IsGrant: n.IsGrant,
  1544. Targtype: ast.GrantTargetType(n.Targtype),
  1545. Objtype: ast.GrantObjectType(n.Objtype),
  1546. Objects: convertSlice(n.Objects),
  1547. Privileges: convertSlice(n.Privileges),
  1548. Grantees: convertSlice(n.Grantees),
  1549. GrantOption: n.GrantOption,
  1550. Behavior: ast.DropBehavior(n.Behavior),
  1551. }
  1552. }
  1553. func convertGroupingFunc(n *pg.GroupingFunc) *ast.GroupingFunc {
  1554. if n == nil {
  1555. return nil
  1556. }
  1557. return &ast.GroupingFunc{
  1558. Xpr: convertNode(n.Xpr),
  1559. Args: convertSlice(n.Args),
  1560. Refs: convertSlice(n.Refs),
  1561. Cols: convertSlice(n.Cols),
  1562. Agglevelsup: ast.Index(n.Agglevelsup),
  1563. Location: int(n.Location),
  1564. }
  1565. }
  1566. func convertGroupingSet(n *pg.GroupingSet) *ast.GroupingSet {
  1567. if n == nil {
  1568. return nil
  1569. }
  1570. return &ast.GroupingSet{
  1571. Kind: ast.GroupingSetKind(n.Kind),
  1572. Content: convertSlice(n.Content),
  1573. Location: int(n.Location),
  1574. }
  1575. }
  1576. func convertImportForeignSchemaStmt(n *pg.ImportForeignSchemaStmt) *ast.ImportForeignSchemaStmt {
  1577. if n == nil {
  1578. return nil
  1579. }
  1580. return &ast.ImportForeignSchemaStmt{
  1581. ServerName: makeString(n.ServerName),
  1582. RemoteSchema: makeString(n.RemoteSchema),
  1583. LocalSchema: makeString(n.LocalSchema),
  1584. ListType: ast.ImportForeignSchemaType(n.ListType),
  1585. TableList: convertSlice(n.TableList),
  1586. Options: convertSlice(n.Options),
  1587. }
  1588. }
  1589. func convertIndexElem(n *pg.IndexElem) *ast.IndexElem {
  1590. if n == nil {
  1591. return nil
  1592. }
  1593. return &ast.IndexElem{
  1594. Name: makeString(n.Name),
  1595. Expr: convertNode(n.Expr),
  1596. Indexcolname: makeString(n.Indexcolname),
  1597. Collation: convertSlice(n.Collation),
  1598. Opclass: convertSlice(n.Opclass),
  1599. Ordering: ast.SortByDir(n.Ordering),
  1600. NullsOrdering: ast.SortByNulls(n.NullsOrdering),
  1601. }
  1602. }
  1603. func convertIndexStmt(n *pg.IndexStmt) *ast.IndexStmt {
  1604. if n == nil {
  1605. return nil
  1606. }
  1607. return &ast.IndexStmt{
  1608. Idxname: makeString(n.Idxname),
  1609. Relation: convertRangeVar(n.Relation),
  1610. AccessMethod: makeString(n.AccessMethod),
  1611. TableSpace: makeString(n.TableSpace),
  1612. IndexParams: convertSlice(n.IndexParams),
  1613. Options: convertSlice(n.Options),
  1614. WhereClause: convertNode(n.WhereClause),
  1615. ExcludeOpNames: convertSlice(n.ExcludeOpNames),
  1616. Idxcomment: makeString(n.Idxcomment),
  1617. IndexOid: ast.Oid(n.IndexOid),
  1618. OldNode: ast.Oid(n.OldNode),
  1619. Unique: n.Unique,
  1620. Primary: n.Primary,
  1621. Isconstraint: n.Isconstraint,
  1622. Deferrable: n.Deferrable,
  1623. Initdeferred: n.Initdeferred,
  1624. Transformed: n.Transformed,
  1625. Concurrent: n.Concurrent,
  1626. IfNotExists: n.IfNotExists,
  1627. }
  1628. }
  1629. func convertInferClause(n *pg.InferClause) *ast.InferClause {
  1630. if n == nil {
  1631. return nil
  1632. }
  1633. return &ast.InferClause{
  1634. IndexElems: convertSlice(n.IndexElems),
  1635. WhereClause: convertNode(n.WhereClause),
  1636. Conname: makeString(n.Conname),
  1637. Location: int(n.Location),
  1638. }
  1639. }
  1640. func convertInferenceElem(n *pg.InferenceElem) *ast.InferenceElem {
  1641. if n == nil {
  1642. return nil
  1643. }
  1644. return &ast.InferenceElem{
  1645. Xpr: convertNode(n.Xpr),
  1646. Expr: convertNode(n.Expr),
  1647. Infercollid: ast.Oid(n.Infercollid),
  1648. Inferopclass: ast.Oid(n.Inferopclass),
  1649. }
  1650. }
  1651. func convertInlineCodeBlock(n *pg.InlineCodeBlock) *ast.InlineCodeBlock {
  1652. if n == nil {
  1653. return nil
  1654. }
  1655. return &ast.InlineCodeBlock{
  1656. SourceText: makeString(n.SourceText),
  1657. LangOid: ast.Oid(n.LangOid),
  1658. LangIsTrusted: n.LangIsTrusted,
  1659. }
  1660. }
  1661. func convertInsertStmt(n *pg.InsertStmt) *ast.InsertStmt {
  1662. if n == nil {
  1663. return nil
  1664. }
  1665. return &ast.InsertStmt{
  1666. Relation: convertRangeVar(n.Relation),
  1667. Cols: convertSlice(n.Cols),
  1668. SelectStmt: convertNode(n.SelectStmt),
  1669. OnConflictClause: convertOnConflictClause(n.OnConflictClause),
  1670. ReturningList: convertSlice(n.ReturningList),
  1671. WithClause: convertWithClause(n.WithClause),
  1672. Override: ast.OverridingKind(n.Override),
  1673. }
  1674. }
  1675. func convertInteger(n *pg.Integer) *ast.Integer {
  1676. if n == nil {
  1677. return nil
  1678. }
  1679. return &ast.Integer{
  1680. Ival: int64(n.Ival),
  1681. }
  1682. }
  1683. func convertIntoClause(n *pg.IntoClause) *ast.IntoClause {
  1684. if n == nil {
  1685. return nil
  1686. }
  1687. return &ast.IntoClause{
  1688. Rel: convertRangeVar(n.Rel),
  1689. ColNames: convertSlice(n.ColNames),
  1690. Options: convertSlice(n.Options),
  1691. OnCommit: ast.OnCommitAction(n.OnCommit),
  1692. TableSpaceName: makeString(n.TableSpaceName),
  1693. ViewQuery: convertNode(n.ViewQuery),
  1694. SkipData: n.SkipData,
  1695. }
  1696. }
  1697. func convertJoinExpr(n *pg.JoinExpr) *ast.JoinExpr {
  1698. if n == nil {
  1699. return nil
  1700. }
  1701. return &ast.JoinExpr{
  1702. Jointype: ast.JoinType(n.Jointype),
  1703. IsNatural: n.IsNatural,
  1704. Larg: convertNode(n.Larg),
  1705. Rarg: convertNode(n.Rarg),
  1706. UsingClause: convertSlice(n.UsingClause),
  1707. Quals: convertNode(n.Quals),
  1708. Alias: convertAlias(n.Alias),
  1709. Rtindex: int(n.Rtindex),
  1710. }
  1711. }
  1712. func convertListenStmt(n *pg.ListenStmt) *ast.ListenStmt {
  1713. if n == nil {
  1714. return nil
  1715. }
  1716. return &ast.ListenStmt{
  1717. Conditionname: makeString(n.Conditionname),
  1718. }
  1719. }
  1720. func convertLoadStmt(n *pg.LoadStmt) *ast.LoadStmt {
  1721. if n == nil {
  1722. return nil
  1723. }
  1724. return &ast.LoadStmt{
  1725. Filename: makeString(n.Filename),
  1726. }
  1727. }
  1728. func convertLockStmt(n *pg.LockStmt) *ast.LockStmt {
  1729. if n == nil {
  1730. return nil
  1731. }
  1732. return &ast.LockStmt{
  1733. Relations: convertSlice(n.Relations),
  1734. Mode: int(n.Mode),
  1735. Nowait: n.Nowait,
  1736. }
  1737. }
  1738. func convertLockingClause(n *pg.LockingClause) *ast.LockingClause {
  1739. if n == nil {
  1740. return nil
  1741. }
  1742. return &ast.LockingClause{
  1743. LockedRels: convertSlice(n.LockedRels),
  1744. Strength: ast.LockClauseStrength(n.Strength),
  1745. WaitPolicy: ast.LockWaitPolicy(n.WaitPolicy),
  1746. }
  1747. }
  1748. func convertMinMaxExpr(n *pg.MinMaxExpr) *ast.MinMaxExpr {
  1749. if n == nil {
  1750. return nil
  1751. }
  1752. return &ast.MinMaxExpr{
  1753. Xpr: convertNode(n.Xpr),
  1754. Minmaxtype: ast.Oid(n.Minmaxtype),
  1755. Minmaxcollid: ast.Oid(n.Minmaxcollid),
  1756. Inputcollid: ast.Oid(n.Inputcollid),
  1757. Op: ast.MinMaxOp(n.Op),
  1758. Args: convertSlice(n.Args),
  1759. Location: int(n.Location),
  1760. }
  1761. }
  1762. func convertMultiAssignRef(n *pg.MultiAssignRef) *ast.MultiAssignRef {
  1763. if n == nil {
  1764. return nil
  1765. }
  1766. return &ast.MultiAssignRef{
  1767. Source: convertNode(n.Source),
  1768. Colno: int(n.Colno),
  1769. Ncolumns: int(n.Ncolumns),
  1770. }
  1771. }
  1772. func convertNamedArgExpr(n *pg.NamedArgExpr) *ast.NamedArgExpr {
  1773. if n == nil {
  1774. return nil
  1775. }
  1776. return &ast.NamedArgExpr{
  1777. Xpr: convertNode(n.Xpr),
  1778. Arg: convertNode(n.Arg),
  1779. Name: makeString(n.Name),
  1780. Argnumber: int(n.Argnumber),
  1781. Location: int(n.Location),
  1782. }
  1783. }
  1784. func convertNextValueExpr(n *pg.NextValueExpr) *ast.NextValueExpr {
  1785. if n == nil {
  1786. return nil
  1787. }
  1788. return &ast.NextValueExpr{
  1789. Xpr: convertNode(n.Xpr),
  1790. Seqid: ast.Oid(n.Seqid),
  1791. TypeId: ast.Oid(n.TypeId),
  1792. }
  1793. }
  1794. func convertNotifyStmt(n *pg.NotifyStmt) *ast.NotifyStmt {
  1795. if n == nil {
  1796. return nil
  1797. }
  1798. return &ast.NotifyStmt{
  1799. Conditionname: makeString(n.Conditionname),
  1800. Payload: makeString(n.Payload),
  1801. }
  1802. }
  1803. func convertNullTest(n *pg.NullTest) *ast.NullTest {
  1804. if n == nil {
  1805. return nil
  1806. }
  1807. return &ast.NullTest{
  1808. Xpr: convertNode(n.Xpr),
  1809. Arg: convertNode(n.Arg),
  1810. Nulltesttype: ast.NullTestType(n.Nulltesttype),
  1811. Argisrow: n.Argisrow,
  1812. Location: int(n.Location),
  1813. }
  1814. }
  1815. func convertObjectWithArgs(n *pg.ObjectWithArgs) *ast.ObjectWithArgs {
  1816. if n == nil {
  1817. return nil
  1818. }
  1819. return &ast.ObjectWithArgs{
  1820. Objname: convertSlice(n.Objname),
  1821. Objargs: convertSlice(n.Objargs),
  1822. ArgsUnspecified: n.ArgsUnspecified,
  1823. }
  1824. }
  1825. func convertOnConflictClause(n *pg.OnConflictClause) *ast.OnConflictClause {
  1826. if n == nil {
  1827. return nil
  1828. }
  1829. return &ast.OnConflictClause{
  1830. Action: ast.OnConflictAction(n.Action),
  1831. Infer: convertInferClause(n.Infer),
  1832. TargetList: convertSlice(n.TargetList),
  1833. WhereClause: convertNode(n.WhereClause),
  1834. Location: int(n.Location),
  1835. }
  1836. }
  1837. func convertOnConflictExpr(n *pg.OnConflictExpr) *ast.OnConflictExpr {
  1838. if n == nil {
  1839. return nil
  1840. }
  1841. return &ast.OnConflictExpr{
  1842. Action: ast.OnConflictAction(n.Action),
  1843. ArbiterElems: convertSlice(n.ArbiterElems),
  1844. ArbiterWhere: convertNode(n.ArbiterWhere),
  1845. Constraint: ast.Oid(n.Constraint),
  1846. OnConflictSet: convertSlice(n.OnConflictSet),
  1847. OnConflictWhere: convertNode(n.OnConflictWhere),
  1848. ExclRelIndex: int(n.ExclRelIndex),
  1849. ExclRelTlist: convertSlice(n.ExclRelTlist),
  1850. }
  1851. }
  1852. func convertOpExpr(n *pg.OpExpr) *ast.OpExpr {
  1853. if n == nil {
  1854. return nil
  1855. }
  1856. return &ast.OpExpr{
  1857. Xpr: convertNode(n.Xpr),
  1858. Opno: ast.Oid(n.Opno),
  1859. Opfuncid: ast.Oid(n.Opfuncid),
  1860. Opresulttype: ast.Oid(n.Opresulttype),
  1861. Opretset: n.Opretset,
  1862. Opcollid: ast.Oid(n.Opcollid),
  1863. Inputcollid: ast.Oid(n.Inputcollid),
  1864. Args: convertSlice(n.Args),
  1865. Location: int(n.Location),
  1866. }
  1867. }
  1868. func convertParam(n *pg.Param) *ast.Param {
  1869. if n == nil {
  1870. return nil
  1871. }
  1872. return &ast.Param{
  1873. Xpr: convertNode(n.Xpr),
  1874. Paramkind: ast.ParamKind(n.Paramkind),
  1875. Paramid: int(n.Paramid),
  1876. Paramtype: ast.Oid(n.Paramtype),
  1877. Paramtypmod: n.Paramtypmod,
  1878. Paramcollid: ast.Oid(n.Paramcollid),
  1879. Location: int(n.Location),
  1880. }
  1881. }
  1882. func convertParamRef(n *pg.ParamRef) *ast.ParamRef {
  1883. if n == nil {
  1884. return nil
  1885. }
  1886. var dollar bool
  1887. if n.Number != 0 {
  1888. dollar = true
  1889. }
  1890. return &ast.ParamRef{
  1891. Dollar: dollar,
  1892. Number: int(n.Number),
  1893. Location: int(n.Location),
  1894. }
  1895. }
  1896. func convertPartitionBoundSpec(n *pg.PartitionBoundSpec) *ast.PartitionBoundSpec {
  1897. if n == nil {
  1898. return nil
  1899. }
  1900. return &ast.PartitionBoundSpec{
  1901. Strategy: makeByte(n.Strategy),
  1902. Listdatums: convertSlice(n.Listdatums),
  1903. Lowerdatums: convertSlice(n.Lowerdatums),
  1904. Upperdatums: convertSlice(n.Upperdatums),
  1905. Location: int(n.Location),
  1906. }
  1907. }
  1908. func convertPartitionCmd(n *pg.PartitionCmd) *ast.PartitionCmd {
  1909. if n == nil {
  1910. return nil
  1911. }
  1912. return &ast.PartitionCmd{
  1913. Name: convertRangeVar(n.Name),
  1914. Bound: convertPartitionBoundSpec(n.Bound),
  1915. }
  1916. }
  1917. func convertPartitionElem(n *pg.PartitionElem) *ast.PartitionElem {
  1918. if n == nil {
  1919. return nil
  1920. }
  1921. return &ast.PartitionElem{
  1922. Name: makeString(n.Name),
  1923. Expr: convertNode(n.Expr),
  1924. Collation: convertSlice(n.Collation),
  1925. Opclass: convertSlice(n.Opclass),
  1926. Location: int(n.Location),
  1927. }
  1928. }
  1929. func convertPartitionRangeDatum(n *pg.PartitionRangeDatum) *ast.PartitionRangeDatum {
  1930. if n == nil {
  1931. return nil
  1932. }
  1933. return &ast.PartitionRangeDatum{
  1934. Kind: ast.PartitionRangeDatumKind(n.Kind),
  1935. Value: convertNode(n.Value),
  1936. Location: int(n.Location),
  1937. }
  1938. }
  1939. func convertPartitionSpec(n *pg.PartitionSpec) *ast.PartitionSpec {
  1940. if n == nil {
  1941. return nil
  1942. }
  1943. return &ast.PartitionSpec{
  1944. Strategy: makeString(n.Strategy),
  1945. PartParams: convertSlice(n.PartParams),
  1946. Location: int(n.Location),
  1947. }
  1948. }
  1949. func convertPrepareStmt(n *pg.PrepareStmt) *ast.PrepareStmt {
  1950. if n == nil {
  1951. return nil
  1952. }
  1953. return &ast.PrepareStmt{
  1954. Name: makeString(n.Name),
  1955. Argtypes: convertSlice(n.Argtypes),
  1956. Query: convertNode(n.Query),
  1957. }
  1958. }
  1959. func convertQuery(n *pg.Query) *ast.Query {
  1960. if n == nil {
  1961. return nil
  1962. }
  1963. return &ast.Query{
  1964. CommandType: ast.CmdType(n.CommandType),
  1965. QuerySource: ast.QuerySource(n.QuerySource),
  1966. CanSetTag: n.CanSetTag,
  1967. UtilityStmt: convertNode(n.UtilityStmt),
  1968. ResultRelation: int(n.ResultRelation),
  1969. HasAggs: n.HasAggs,
  1970. HasWindowFuncs: n.HasWindowFuncs,
  1971. HasTargetSrfs: n.HasTargetSrfs,
  1972. HasSubLinks: n.HasSubLinks,
  1973. HasDistinctOn: n.HasDistinctOn,
  1974. HasRecursive: n.HasRecursive,
  1975. HasModifyingCte: n.HasModifyingCte,
  1976. HasForUpdate: n.HasForUpdate,
  1977. HasRowSecurity: n.HasRowSecurity,
  1978. CteList: convertSlice(n.CteList),
  1979. Rtable: convertSlice(n.Rtable),
  1980. Jointree: convertFromExpr(n.Jointree),
  1981. TargetList: convertSlice(n.TargetList),
  1982. Override: ast.OverridingKind(n.Override),
  1983. OnConflict: convertOnConflictExpr(n.OnConflict),
  1984. ReturningList: convertSlice(n.ReturningList),
  1985. GroupClause: convertSlice(n.GroupClause),
  1986. GroupingSets: convertSlice(n.GroupingSets),
  1987. HavingQual: convertNode(n.HavingQual),
  1988. WindowClause: convertSlice(n.WindowClause),
  1989. DistinctClause: convertSlice(n.DistinctClause),
  1990. SortClause: convertSlice(n.SortClause),
  1991. LimitOffset: convertNode(n.LimitOffset),
  1992. LimitCount: convertNode(n.LimitCount),
  1993. RowMarks: convertSlice(n.RowMarks),
  1994. SetOperations: convertNode(n.SetOperations),
  1995. ConstraintDeps: convertSlice(n.ConstraintDeps),
  1996. WithCheckOptions: convertSlice(n.WithCheckOptions),
  1997. StmtLocation: int(n.StmtLocation),
  1998. StmtLen: int(n.StmtLen),
  1999. }
  2000. }
  2001. func convertRangeFunction(n *pg.RangeFunction) *ast.RangeFunction {
  2002. if n == nil {
  2003. return nil
  2004. }
  2005. return &ast.RangeFunction{
  2006. Lateral: n.Lateral,
  2007. Ordinality: n.Ordinality,
  2008. IsRowsfrom: n.IsRowsfrom,
  2009. Functions: convertSlice(n.Functions),
  2010. Alias: convertAlias(n.Alias),
  2011. Coldeflist: convertSlice(n.Coldeflist),
  2012. }
  2013. }
  2014. func convertRangeSubselect(n *pg.RangeSubselect) *ast.RangeSubselect {
  2015. if n == nil {
  2016. return nil
  2017. }
  2018. return &ast.RangeSubselect{
  2019. Lateral: n.Lateral,
  2020. Subquery: convertNode(n.Subquery),
  2021. Alias: convertAlias(n.Alias),
  2022. }
  2023. }
  2024. func convertRangeTableFunc(n *pg.RangeTableFunc) *ast.RangeTableFunc {
  2025. if n == nil {
  2026. return nil
  2027. }
  2028. return &ast.RangeTableFunc{
  2029. Lateral: n.Lateral,
  2030. Docexpr: convertNode(n.Docexpr),
  2031. Rowexpr: convertNode(n.Rowexpr),
  2032. Namespaces: convertSlice(n.Namespaces),
  2033. Columns: convertSlice(n.Columns),
  2034. Alias: convertAlias(n.Alias),
  2035. Location: int(n.Location),
  2036. }
  2037. }
  2038. func convertRangeTableFuncCol(n *pg.RangeTableFuncCol) *ast.RangeTableFuncCol {
  2039. if n == nil {
  2040. return nil
  2041. }
  2042. return &ast.RangeTableFuncCol{
  2043. Colname: makeString(n.Colname),
  2044. TypeName: convertTypeName(n.TypeName),
  2045. ForOrdinality: n.ForOrdinality,
  2046. IsNotNull: n.IsNotNull,
  2047. Colexpr: convertNode(n.Colexpr),
  2048. Coldefexpr: convertNode(n.Coldefexpr),
  2049. Location: int(n.Location),
  2050. }
  2051. }
  2052. func convertRangeTableSample(n *pg.RangeTableSample) *ast.RangeTableSample {
  2053. if n == nil {
  2054. return nil
  2055. }
  2056. return &ast.RangeTableSample{
  2057. Relation: convertNode(n.Relation),
  2058. Method: convertSlice(n.Method),
  2059. Args: convertSlice(n.Args),
  2060. Repeatable: convertNode(n.Repeatable),
  2061. Location: int(n.Location),
  2062. }
  2063. }
  2064. func convertRangeTblEntry(n *pg.RangeTblEntry) *ast.RangeTblEntry {
  2065. if n == nil {
  2066. return nil
  2067. }
  2068. return &ast.RangeTblEntry{
  2069. Rtekind: ast.RTEKind(n.Rtekind),
  2070. Relid: ast.Oid(n.Relid),
  2071. Relkind: makeByte(n.Relkind),
  2072. Tablesample: convertTableSampleClause(n.Tablesample),
  2073. Subquery: convertQuery(n.Subquery),
  2074. SecurityBarrier: n.SecurityBarrier,
  2075. Jointype: ast.JoinType(n.Jointype),
  2076. Joinaliasvars: convertSlice(n.Joinaliasvars),
  2077. Functions: convertSlice(n.Functions),
  2078. Funcordinality: n.Funcordinality,
  2079. Tablefunc: convertTableFunc(n.Tablefunc),
  2080. ValuesLists: convertSlice(n.ValuesLists),
  2081. Ctename: makeString(n.Ctename),
  2082. Ctelevelsup: ast.Index(n.Ctelevelsup),
  2083. SelfReference: n.SelfReference,
  2084. Coltypes: convertSlice(n.Coltypes),
  2085. Coltypmods: convertSlice(n.Coltypmods),
  2086. Colcollations: convertSlice(n.Colcollations),
  2087. Enrname: makeString(n.Enrname),
  2088. Enrtuples: n.Enrtuples,
  2089. Alias: convertAlias(n.Alias),
  2090. Eref: convertAlias(n.Eref),
  2091. Lateral: n.Lateral,
  2092. Inh: n.Inh,
  2093. InFromCl: n.InFromCl,
  2094. RequiredPerms: ast.AclMode(n.RequiredPerms),
  2095. CheckAsUser: ast.Oid(n.CheckAsUser),
  2096. SelectedCols: makeUint32Slice(n.SelectedCols),
  2097. InsertedCols: makeUint32Slice(n.InsertedCols),
  2098. UpdatedCols: makeUint32Slice(n.UpdatedCols),
  2099. SecurityQuals: convertSlice(n.SecurityQuals),
  2100. }
  2101. }
  2102. func convertRangeTblFunction(n *pg.RangeTblFunction) *ast.RangeTblFunction {
  2103. if n == nil {
  2104. return nil
  2105. }
  2106. return &ast.RangeTblFunction{
  2107. Funcexpr: convertNode(n.Funcexpr),
  2108. Funccolcount: int(n.Funccolcount),
  2109. Funccolnames: convertSlice(n.Funccolnames),
  2110. Funccoltypes: convertSlice(n.Funccoltypes),
  2111. Funccoltypmods: convertSlice(n.Funccoltypmods),
  2112. Funccolcollations: convertSlice(n.Funccolcollations),
  2113. Funcparams: makeUint32Slice(n.Funcparams),
  2114. }
  2115. }
  2116. func convertRangeTblRef(n *pg.RangeTblRef) *ast.RangeTblRef {
  2117. if n == nil {
  2118. return nil
  2119. }
  2120. return &ast.RangeTblRef{
  2121. Rtindex: int(n.Rtindex),
  2122. }
  2123. }
  2124. func convertRangeVar(n *pg.RangeVar) *ast.RangeVar {
  2125. if n == nil {
  2126. return nil
  2127. }
  2128. return &ast.RangeVar{
  2129. Catalogname: makeString(n.Catalogname),
  2130. Schemaname: makeString(n.Schemaname),
  2131. Relname: makeString(n.Relname),
  2132. Inh: n.Inh,
  2133. Relpersistence: makeByte(n.Relpersistence),
  2134. Alias: convertAlias(n.Alias),
  2135. Location: int(n.Location),
  2136. }
  2137. }
  2138. func convertRawStmt(n *pg.RawStmt) *ast.RawStmt {
  2139. if n == nil {
  2140. return nil
  2141. }
  2142. return &ast.RawStmt{
  2143. Stmt: convertNode(n.Stmt),
  2144. StmtLocation: int(n.StmtLocation),
  2145. StmtLen: int(n.StmtLen),
  2146. }
  2147. }
  2148. func convertReassignOwnedStmt(n *pg.ReassignOwnedStmt) *ast.ReassignOwnedStmt {
  2149. if n == nil {
  2150. return nil
  2151. }
  2152. return &ast.ReassignOwnedStmt{
  2153. Roles: convertSlice(n.Roles),
  2154. Newrole: convertRoleSpec(n.Newrole),
  2155. }
  2156. }
  2157. func convertRefreshMatViewStmt(n *pg.RefreshMatViewStmt) *ast.RefreshMatViewStmt {
  2158. if n == nil {
  2159. return nil
  2160. }
  2161. return &ast.RefreshMatViewStmt{
  2162. Concurrent: n.Concurrent,
  2163. SkipData: n.SkipData,
  2164. Relation: convertRangeVar(n.Relation),
  2165. }
  2166. }
  2167. func convertReindexStmt(n *pg.ReindexStmt) *ast.ReindexStmt {
  2168. if n == nil {
  2169. return nil
  2170. }
  2171. return &ast.ReindexStmt{
  2172. Kind: ast.ReindexObjectType(n.Kind),
  2173. Relation: convertRangeVar(n.Relation),
  2174. Name: makeString(n.Name),
  2175. // Options: int(n.Options), TODO: Support params
  2176. }
  2177. }
  2178. func convertRelabelType(n *pg.RelabelType) *ast.RelabelType {
  2179. if n == nil {
  2180. return nil
  2181. }
  2182. return &ast.RelabelType{
  2183. Xpr: convertNode(n.Xpr),
  2184. Arg: convertNode(n.Arg),
  2185. Resulttype: ast.Oid(n.Resulttype),
  2186. Resulttypmod: n.Resulttypmod,
  2187. Resultcollid: ast.Oid(n.Resultcollid),
  2188. Relabelformat: ast.CoercionForm(n.Relabelformat),
  2189. Location: int(n.Location),
  2190. }
  2191. }
  2192. func convertRenameStmt(n *pg.RenameStmt) *ast.RenameStmt {
  2193. if n == nil {
  2194. return nil
  2195. }
  2196. return &ast.RenameStmt{
  2197. RenameType: ast.ObjectType(n.RenameType),
  2198. RelationType: ast.ObjectType(n.RelationType),
  2199. Relation: convertRangeVar(n.Relation),
  2200. Object: convertNode(n.Object),
  2201. Subname: makeString(n.Subname),
  2202. Newname: makeString(n.Newname),
  2203. Behavior: ast.DropBehavior(n.Behavior),
  2204. MissingOk: n.MissingOk,
  2205. }
  2206. }
  2207. func convertReplicaIdentityStmt(n *pg.ReplicaIdentityStmt) *ast.ReplicaIdentityStmt {
  2208. if n == nil {
  2209. return nil
  2210. }
  2211. return &ast.ReplicaIdentityStmt{
  2212. IdentityType: makeByte(n.IdentityType),
  2213. Name: makeString(n.Name),
  2214. }
  2215. }
  2216. func convertResTarget(n *pg.ResTarget) *ast.ResTarget {
  2217. if n == nil {
  2218. return nil
  2219. }
  2220. return &ast.ResTarget{
  2221. Name: makeString(n.Name),
  2222. Indirection: convertSlice(n.Indirection),
  2223. Val: convertNode(n.Val),
  2224. Location: int(n.Location),
  2225. }
  2226. }
  2227. func convertRoleSpec(n *pg.RoleSpec) *ast.RoleSpec {
  2228. if n == nil {
  2229. return nil
  2230. }
  2231. return &ast.RoleSpec{
  2232. Roletype: ast.RoleSpecType(n.Roletype),
  2233. Rolename: makeString(n.Rolename),
  2234. Location: int(n.Location),
  2235. }
  2236. }
  2237. func convertRowCompareExpr(n *pg.RowCompareExpr) *ast.RowCompareExpr {
  2238. if n == nil {
  2239. return nil
  2240. }
  2241. return &ast.RowCompareExpr{
  2242. Xpr: convertNode(n.Xpr),
  2243. Rctype: ast.RowCompareType(n.Rctype),
  2244. Opnos: convertSlice(n.Opnos),
  2245. Opfamilies: convertSlice(n.Opfamilies),
  2246. Inputcollids: convertSlice(n.Inputcollids),
  2247. Largs: convertSlice(n.Largs),
  2248. Rargs: convertSlice(n.Rargs),
  2249. }
  2250. }
  2251. func convertRowExpr(n *pg.RowExpr) *ast.RowExpr {
  2252. if n == nil {
  2253. return nil
  2254. }
  2255. return &ast.RowExpr{
  2256. Xpr: convertNode(n.Xpr),
  2257. Args: convertSlice(n.Args),
  2258. RowTypeid: ast.Oid(n.RowTypeid),
  2259. RowFormat: ast.CoercionForm(n.RowFormat),
  2260. Colnames: convertSlice(n.Colnames),
  2261. Location: int(n.Location),
  2262. }
  2263. }
  2264. func convertRowMarkClause(n *pg.RowMarkClause) *ast.RowMarkClause {
  2265. if n == nil {
  2266. return nil
  2267. }
  2268. return &ast.RowMarkClause{
  2269. Rti: ast.Index(n.Rti),
  2270. Strength: ast.LockClauseStrength(n.Strength),
  2271. WaitPolicy: ast.LockWaitPolicy(n.WaitPolicy),
  2272. PushedDown: n.PushedDown,
  2273. }
  2274. }
  2275. func convertRuleStmt(n *pg.RuleStmt) *ast.RuleStmt {
  2276. if n == nil {
  2277. return nil
  2278. }
  2279. return &ast.RuleStmt{
  2280. Relation: convertRangeVar(n.Relation),
  2281. Rulename: makeString(n.Rulename),
  2282. WhereClause: convertNode(n.WhereClause),
  2283. Event: ast.CmdType(n.Event),
  2284. Instead: n.Instead,
  2285. Actions: convertSlice(n.Actions),
  2286. Replace: n.Replace,
  2287. }
  2288. }
  2289. func convertSQLValueFunction(n *pg.SQLValueFunction) *ast.SQLValueFunction {
  2290. if n == nil {
  2291. return nil
  2292. }
  2293. return &ast.SQLValueFunction{
  2294. Xpr: convertNode(n.Xpr),
  2295. Op: ast.SQLValueFunctionOp(n.Op),
  2296. Type: ast.Oid(n.Type),
  2297. Typmod: n.Typmod,
  2298. Location: int(n.Location),
  2299. }
  2300. }
  2301. func convertScalarArrayOpExpr(n *pg.ScalarArrayOpExpr) *ast.ScalarArrayOpExpr {
  2302. if n == nil {
  2303. return nil
  2304. }
  2305. return &ast.ScalarArrayOpExpr{
  2306. Xpr: convertNode(n.Xpr),
  2307. Opno: ast.Oid(n.Opno),
  2308. Opfuncid: ast.Oid(n.Opfuncid),
  2309. UseOr: n.UseOr,
  2310. Inputcollid: ast.Oid(n.Inputcollid),
  2311. Args: convertSlice(n.Args),
  2312. Location: int(n.Location),
  2313. }
  2314. }
  2315. func convertSecLabelStmt(n *pg.SecLabelStmt) *ast.SecLabelStmt {
  2316. if n == nil {
  2317. return nil
  2318. }
  2319. return &ast.SecLabelStmt{
  2320. Objtype: ast.ObjectType(n.Objtype),
  2321. Object: convertNode(n.Object),
  2322. Provider: makeString(n.Provider),
  2323. Label: makeString(n.Label),
  2324. }
  2325. }
  2326. func convertSelectStmt(n *pg.SelectStmt) *ast.SelectStmt {
  2327. if n == nil {
  2328. return nil
  2329. }
  2330. op, err := convertSetOperation(n.Op)
  2331. if err != nil {
  2332. panic(err)
  2333. }
  2334. return &ast.SelectStmt{
  2335. DistinctClause: convertSlice(n.DistinctClause),
  2336. IntoClause: convertIntoClause(n.IntoClause),
  2337. TargetList: convertSlice(n.TargetList),
  2338. FromClause: convertSlice(n.FromClause),
  2339. WhereClause: convertNode(n.WhereClause),
  2340. GroupClause: convertSlice(n.GroupClause),
  2341. HavingClause: convertNode(n.HavingClause),
  2342. WindowClause: convertSlice(n.WindowClause),
  2343. ValuesLists: convertSlice(n.ValuesLists),
  2344. SortClause: convertSlice(n.SortClause),
  2345. LimitOffset: convertNode(n.LimitOffset),
  2346. LimitCount: convertNode(n.LimitCount),
  2347. LockingClause: convertSlice(n.LockingClause),
  2348. WithClause: convertWithClause(n.WithClause),
  2349. Op: op,
  2350. All: n.All,
  2351. Larg: convertSelectStmt(n.Larg),
  2352. Rarg: convertSelectStmt(n.Rarg),
  2353. }
  2354. }
  2355. func convertSetOperationStmt(n *pg.SetOperationStmt) *ast.SetOperationStmt {
  2356. if n == nil {
  2357. return nil
  2358. }
  2359. op, err := convertSetOperation(n.Op)
  2360. if err != nil {
  2361. panic(err)
  2362. }
  2363. return &ast.SetOperationStmt{
  2364. Op: op,
  2365. All: n.All,
  2366. Larg: convertNode(n.Larg),
  2367. Rarg: convertNode(n.Rarg),
  2368. ColTypes: convertSlice(n.ColTypes),
  2369. ColTypmods: convertSlice(n.ColTypmods),
  2370. ColCollations: convertSlice(n.ColCollations),
  2371. GroupClauses: convertSlice(n.GroupClauses),
  2372. }
  2373. }
  2374. func convertSetToDefault(n *pg.SetToDefault) *ast.SetToDefault {
  2375. if n == nil {
  2376. return nil
  2377. }
  2378. return &ast.SetToDefault{
  2379. Xpr: convertNode(n.Xpr),
  2380. TypeId: ast.Oid(n.TypeId),
  2381. TypeMod: n.TypeMod,
  2382. Collation: ast.Oid(n.Collation),
  2383. Location: int(n.Location),
  2384. }
  2385. }
  2386. func convertSortBy(n *pg.SortBy) *ast.SortBy {
  2387. if n == nil {
  2388. return nil
  2389. }
  2390. return &ast.SortBy{
  2391. Node: convertNode(n.Node),
  2392. SortbyDir: ast.SortByDir(n.SortbyDir),
  2393. SortbyNulls: ast.SortByNulls(n.SortbyNulls),
  2394. UseOp: convertSlice(n.UseOp),
  2395. Location: int(n.Location),
  2396. }
  2397. }
  2398. func convertSortGroupClause(n *pg.SortGroupClause) *ast.SortGroupClause {
  2399. if n == nil {
  2400. return nil
  2401. }
  2402. return &ast.SortGroupClause{
  2403. TleSortGroupRef: ast.Index(n.TleSortGroupRef),
  2404. Eqop: ast.Oid(n.Eqop),
  2405. Sortop: ast.Oid(n.Sortop),
  2406. NullsFirst: n.NullsFirst,
  2407. Hashable: n.Hashable,
  2408. }
  2409. }
  2410. func convertString(n *pg.String) *ast.String {
  2411. if n == nil {
  2412. return nil
  2413. }
  2414. return &ast.String{
  2415. Str: n.Sval,
  2416. }
  2417. }
  2418. func convertSubLink(n *pg.SubLink) *ast.SubLink {
  2419. if n == nil {
  2420. return nil
  2421. }
  2422. slt, err := convertSubLinkType(n.SubLinkType)
  2423. if err != nil {
  2424. panic(err)
  2425. }
  2426. return &ast.SubLink{
  2427. Xpr: convertNode(n.Xpr),
  2428. SubLinkType: slt,
  2429. SubLinkId: int(n.SubLinkId),
  2430. Testexpr: convertNode(n.Testexpr),
  2431. OperName: convertSlice(n.OperName),
  2432. Subselect: convertNode(n.Subselect),
  2433. Location: int(n.Location),
  2434. }
  2435. }
  2436. func convertSubPlan(n *pg.SubPlan) *ast.SubPlan {
  2437. if n == nil {
  2438. return nil
  2439. }
  2440. slt, err := convertSubLinkType(n.SubLinkType)
  2441. if err != nil {
  2442. panic(err)
  2443. }
  2444. return &ast.SubPlan{
  2445. Xpr: convertNode(n.Xpr),
  2446. SubLinkType: slt,
  2447. Testexpr: convertNode(n.Testexpr),
  2448. ParamIds: convertSlice(n.ParamIds),
  2449. PlanId: int(n.PlanId),
  2450. PlanName: makeString(n.PlanName),
  2451. FirstColType: ast.Oid(n.FirstColType),
  2452. FirstColTypmod: n.FirstColTypmod,
  2453. FirstColCollation: ast.Oid(n.FirstColCollation),
  2454. UseHashTable: n.UseHashTable,
  2455. UnknownEqFalse: n.UnknownEqFalse,
  2456. ParallelSafe: n.ParallelSafe,
  2457. SetParam: convertSlice(n.SetParam),
  2458. ParParam: convertSlice(n.ParParam),
  2459. Args: convertSlice(n.Args),
  2460. StartupCost: ast.Cost(n.StartupCost),
  2461. PerCallCost: ast.Cost(n.PerCallCost),
  2462. }
  2463. }
  2464. func convertTableFunc(n *pg.TableFunc) *ast.TableFunc {
  2465. if n == nil {
  2466. return nil
  2467. }
  2468. return &ast.TableFunc{
  2469. NsUris: convertSlice(n.NsUris),
  2470. NsNames: convertSlice(n.NsNames),
  2471. Docexpr: convertNode(n.Docexpr),
  2472. Rowexpr: convertNode(n.Rowexpr),
  2473. Colnames: convertSlice(n.Colnames),
  2474. Coltypes: convertSlice(n.Coltypes),
  2475. Coltypmods: convertSlice(n.Coltypmods),
  2476. Colcollations: convertSlice(n.Colcollations),
  2477. Colexprs: convertSlice(n.Colexprs),
  2478. Coldefexprs: convertSlice(n.Coldefexprs),
  2479. Notnulls: makeUint32Slice(n.Notnulls),
  2480. Ordinalitycol: int(n.Ordinalitycol),
  2481. Location: int(n.Location),
  2482. }
  2483. }
  2484. func convertTableLikeClause(n *pg.TableLikeClause) *ast.TableLikeClause {
  2485. if n == nil {
  2486. return nil
  2487. }
  2488. return &ast.TableLikeClause{
  2489. Relation: convertRangeVar(n.Relation),
  2490. Options: n.Options,
  2491. }
  2492. }
  2493. func convertTableSampleClause(n *pg.TableSampleClause) *ast.TableSampleClause {
  2494. if n == nil {
  2495. return nil
  2496. }
  2497. return &ast.TableSampleClause{
  2498. Tsmhandler: ast.Oid(n.Tsmhandler),
  2499. Args: convertSlice(n.Args),
  2500. Repeatable: convertNode(n.Repeatable),
  2501. }
  2502. }
  2503. func convertTargetEntry(n *pg.TargetEntry) *ast.TargetEntry {
  2504. if n == nil {
  2505. return nil
  2506. }
  2507. return &ast.TargetEntry{
  2508. Xpr: convertNode(n.Xpr),
  2509. Expr: convertNode(n.Expr),
  2510. Resno: ast.AttrNumber(n.Resno),
  2511. Resname: makeString(n.Resname),
  2512. Ressortgroupref: ast.Index(n.Ressortgroupref),
  2513. Resorigtbl: ast.Oid(n.Resorigtbl),
  2514. Resorigcol: ast.AttrNumber(n.Resorigcol),
  2515. Resjunk: n.Resjunk,
  2516. }
  2517. }
  2518. func convertTransactionStmt(n *pg.TransactionStmt) *ast.TransactionStmt {
  2519. if n == nil {
  2520. return nil
  2521. }
  2522. return &ast.TransactionStmt{
  2523. Kind: ast.TransactionStmtKind(n.Kind),
  2524. Options: convertSlice(n.Options),
  2525. Gid: makeString(n.Gid),
  2526. }
  2527. }
  2528. func convertTriggerTransition(n *pg.TriggerTransition) *ast.TriggerTransition {
  2529. if n == nil {
  2530. return nil
  2531. }
  2532. return &ast.TriggerTransition{
  2533. Name: makeString(n.Name),
  2534. IsNew: n.IsNew,
  2535. IsTable: n.IsTable,
  2536. }
  2537. }
  2538. func convertTruncateStmt(n *pg.TruncateStmt) *ast.TruncateStmt {
  2539. if n == nil {
  2540. return nil
  2541. }
  2542. return &ast.TruncateStmt{
  2543. Relations: convertSlice(n.Relations),
  2544. RestartSeqs: n.RestartSeqs,
  2545. Behavior: ast.DropBehavior(n.Behavior),
  2546. }
  2547. }
  2548. func convertTypeCast(n *pg.TypeCast) *ast.TypeCast {
  2549. if n == nil {
  2550. return nil
  2551. }
  2552. return &ast.TypeCast{
  2553. Arg: convertNode(n.Arg),
  2554. TypeName: convertTypeName(n.TypeName),
  2555. Location: int(n.Location),
  2556. }
  2557. }
  2558. func convertTypeName(n *pg.TypeName) *ast.TypeName {
  2559. if n == nil {
  2560. return nil
  2561. }
  2562. return &ast.TypeName{
  2563. Names: convertSlice(n.Names),
  2564. TypeOid: ast.Oid(n.TypeOid),
  2565. Setof: n.Setof,
  2566. PctType: n.PctType,
  2567. Typmods: convertSlice(n.Typmods),
  2568. Typemod: n.Typemod,
  2569. ArrayBounds: convertSlice(n.ArrayBounds),
  2570. Location: int(n.Location),
  2571. }
  2572. }
  2573. func convertUnlistenStmt(n *pg.UnlistenStmt) *ast.UnlistenStmt {
  2574. if n == nil {
  2575. return nil
  2576. }
  2577. return &ast.UnlistenStmt{
  2578. Conditionname: makeString(n.Conditionname),
  2579. }
  2580. }
  2581. func convertUpdateStmt(n *pg.UpdateStmt) *ast.UpdateStmt {
  2582. if n == nil {
  2583. return nil
  2584. }
  2585. return &ast.UpdateStmt{
  2586. Relations: &ast.List{
  2587. Items: []ast.Node{convertRangeVar(n.Relation)},
  2588. },
  2589. TargetList: convertSlice(n.TargetList),
  2590. WhereClause: convertNode(n.WhereClause),
  2591. FromClause: convertSlice(n.FromClause),
  2592. ReturningList: convertSlice(n.ReturningList),
  2593. WithClause: convertWithClause(n.WithClause),
  2594. }
  2595. }
  2596. func convertVacuumStmt(n *pg.VacuumStmt) *ast.VacuumStmt {
  2597. if n == nil {
  2598. return nil
  2599. }
  2600. return &ast.VacuumStmt{
  2601. // FIXME: The VacuumStmt node has changed quite a bit
  2602. // Options: n.Options
  2603. // Relation: convertRangeVar(n.Relation),
  2604. // VaCols: convertSlice(n.VaCols),
  2605. }
  2606. }
  2607. func convertVar(n *pg.Var) *ast.Var {
  2608. if n == nil {
  2609. return nil
  2610. }
  2611. return &ast.Var{
  2612. Xpr: convertNode(n.Xpr),
  2613. Varno: ast.Index(n.Varno),
  2614. Varattno: ast.AttrNumber(n.Varattno),
  2615. Vartype: ast.Oid(n.Vartype),
  2616. Vartypmod: n.Vartypmod,
  2617. Varcollid: ast.Oid(n.Varcollid),
  2618. Varlevelsup: ast.Index(n.Varlevelsup),
  2619. Location: int(n.Location),
  2620. }
  2621. }
  2622. func convertVariableSetStmt(n *pg.VariableSetStmt) *ast.VariableSetStmt {
  2623. if n == nil {
  2624. return nil
  2625. }
  2626. return &ast.VariableSetStmt{
  2627. Kind: ast.VariableSetKind(n.Kind),
  2628. Name: makeString(n.Name),
  2629. Args: convertSlice(n.Args),
  2630. IsLocal: n.IsLocal,
  2631. }
  2632. }
  2633. func convertVariableShowStmt(n *pg.VariableShowStmt) *ast.VariableShowStmt {
  2634. if n == nil {
  2635. return nil
  2636. }
  2637. return &ast.VariableShowStmt{
  2638. Name: makeString(n.Name),
  2639. }
  2640. }
  2641. func convertViewStmt(n *pg.ViewStmt) *ast.ViewStmt {
  2642. if n == nil {
  2643. return nil
  2644. }
  2645. return &ast.ViewStmt{
  2646. View: convertRangeVar(n.View),
  2647. Aliases: convertSlice(n.Aliases),
  2648. Query: convertNode(n.Query),
  2649. Replace: n.Replace,
  2650. Options: convertSlice(n.Options),
  2651. WithCheckOption: ast.ViewCheckOption(n.WithCheckOption),
  2652. }
  2653. }
  2654. func convertWindowClause(n *pg.WindowClause) *ast.WindowClause {
  2655. if n == nil {
  2656. return nil
  2657. }
  2658. return &ast.WindowClause{
  2659. Name: makeString(n.Name),
  2660. Refname: makeString(n.Refname),
  2661. PartitionClause: convertSlice(n.PartitionClause),
  2662. OrderClause: convertSlice(n.OrderClause),
  2663. FrameOptions: int(n.FrameOptions),
  2664. StartOffset: convertNode(n.StartOffset),
  2665. EndOffset: convertNode(n.EndOffset),
  2666. Winref: ast.Index(n.Winref),
  2667. CopiedOrder: n.CopiedOrder,
  2668. }
  2669. }
  2670. func convertWindowDef(n *pg.WindowDef) *ast.WindowDef {
  2671. if n == nil {
  2672. return nil
  2673. }
  2674. return &ast.WindowDef{
  2675. Name: makeString(n.Name),
  2676. Refname: makeString(n.Refname),
  2677. PartitionClause: convertSlice(n.PartitionClause),
  2678. OrderClause: convertSlice(n.OrderClause),
  2679. FrameOptions: int(n.FrameOptions),
  2680. StartOffset: convertNode(n.StartOffset),
  2681. EndOffset: convertNode(n.EndOffset),
  2682. Location: int(n.Location),
  2683. }
  2684. }
  2685. func convertWindowFunc(n *pg.WindowFunc) *ast.WindowFunc {
  2686. if n == nil {
  2687. return nil
  2688. }
  2689. return &ast.WindowFunc{
  2690. Xpr: convertNode(n.Xpr),
  2691. Winfnoid: ast.Oid(n.Winfnoid),
  2692. Wintype: ast.Oid(n.Wintype),
  2693. Wincollid: ast.Oid(n.Wincollid),
  2694. Inputcollid: ast.Oid(n.Inputcollid),
  2695. Args: convertSlice(n.Args),
  2696. Aggfilter: convertNode(n.Aggfilter),
  2697. Winref: ast.Index(n.Winref),
  2698. Winstar: n.Winstar,
  2699. Winagg: n.Winagg,
  2700. Location: int(n.Location),
  2701. }
  2702. }
  2703. func convertWithCheckOption(n *pg.WithCheckOption) *ast.WithCheckOption {
  2704. if n == nil {
  2705. return nil
  2706. }
  2707. return &ast.WithCheckOption{
  2708. Kind: ast.WCOKind(n.Kind),
  2709. Relname: makeString(n.Relname),
  2710. Polname: makeString(n.Polname),
  2711. Qual: convertNode(n.Qual),
  2712. Cascaded: n.Cascaded,
  2713. }
  2714. }
  2715. func convertWithClause(n *pg.WithClause) *ast.WithClause {
  2716. if n == nil {
  2717. return nil
  2718. }
  2719. return &ast.WithClause{
  2720. Ctes: convertSlice(n.Ctes),
  2721. Recursive: n.Recursive,
  2722. Location: int(n.Location),
  2723. }
  2724. }
  2725. func convertXmlExpr(n *pg.XmlExpr) *ast.XmlExpr {
  2726. if n == nil {
  2727. return nil
  2728. }
  2729. return &ast.XmlExpr{
  2730. Xpr: convertNode(n.Xpr),
  2731. Op: ast.XmlExprOp(n.Op),
  2732. Name: makeString(n.Name),
  2733. NamedArgs: convertSlice(n.NamedArgs),
  2734. ArgNames: convertSlice(n.ArgNames),
  2735. Args: convertSlice(n.Args),
  2736. Xmloption: ast.XmlOptionType(n.Xmloption),
  2737. Type: ast.Oid(n.Type),
  2738. Typmod: n.Typmod,
  2739. Location: int(n.Location),
  2740. }
  2741. }
  2742. func convertXmlSerialize(n *pg.XmlSerialize) *ast.XmlSerialize {
  2743. if n == nil {
  2744. return nil
  2745. }
  2746. return &ast.XmlSerialize{
  2747. Xmloption: ast.XmlOptionType(n.Xmloption),
  2748. Expr: convertNode(n.Expr),
  2749. TypeName: convertTypeName(n.TypeName),
  2750. Location: int(n.Location),
  2751. }
  2752. }
  2753. func convertNode(node *pg.Node) ast.Node {
  2754. if node == nil || node.Node == nil {
  2755. return &ast.TODO{}
  2756. }
  2757. switch n := node.Node.(type) {
  2758. case *pg.Node_AArrayExpr:
  2759. return convertA_ArrayExpr(n.AArrayExpr)
  2760. case *pg.Node_AConst:
  2761. return convertA_Const(n.AConst)
  2762. case *pg.Node_AExpr:
  2763. return convertA_Expr(n.AExpr)
  2764. case *pg.Node_AIndices:
  2765. return convertA_Indices(n.AIndices)
  2766. case *pg.Node_AIndirection:
  2767. return convertA_Indirection(n.AIndirection)
  2768. case *pg.Node_AStar:
  2769. return convertA_Star(n.AStar)
  2770. case *pg.Node_AccessPriv:
  2771. return convertAccessPriv(n.AccessPriv)
  2772. case *pg.Node_Aggref:
  2773. return convertAggref(n.Aggref)
  2774. case *pg.Node_Alias:
  2775. return convertAlias(n.Alias)
  2776. case *pg.Node_AlterCollationStmt:
  2777. return convertAlterCollationStmt(n.AlterCollationStmt)
  2778. case *pg.Node_AlterDatabaseSetStmt:
  2779. return convertAlterDatabaseSetStmt(n.AlterDatabaseSetStmt)
  2780. case *pg.Node_AlterDatabaseStmt:
  2781. return convertAlterDatabaseStmt(n.AlterDatabaseStmt)
  2782. case *pg.Node_AlterDefaultPrivilegesStmt:
  2783. return convertAlterDefaultPrivilegesStmt(n.AlterDefaultPrivilegesStmt)
  2784. case *pg.Node_AlterDomainStmt:
  2785. return convertAlterDomainStmt(n.AlterDomainStmt)
  2786. case *pg.Node_AlterEnumStmt:
  2787. return convertAlterEnumStmt(n.AlterEnumStmt)
  2788. case *pg.Node_AlterEventTrigStmt:
  2789. return convertAlterEventTrigStmt(n.AlterEventTrigStmt)
  2790. case *pg.Node_AlterExtensionContentsStmt:
  2791. return convertAlterExtensionContentsStmt(n.AlterExtensionContentsStmt)
  2792. case *pg.Node_AlterExtensionStmt:
  2793. return convertAlterExtensionStmt(n.AlterExtensionStmt)
  2794. case *pg.Node_AlterFdwStmt:
  2795. return convertAlterFdwStmt(n.AlterFdwStmt)
  2796. case *pg.Node_AlterForeignServerStmt:
  2797. return convertAlterForeignServerStmt(n.AlterForeignServerStmt)
  2798. case *pg.Node_AlterFunctionStmt:
  2799. return convertAlterFunctionStmt(n.AlterFunctionStmt)
  2800. case *pg.Node_AlterObjectDependsStmt:
  2801. return convertAlterObjectDependsStmt(n.AlterObjectDependsStmt)
  2802. case *pg.Node_AlterObjectSchemaStmt:
  2803. return convertAlterObjectSchemaStmt(n.AlterObjectSchemaStmt)
  2804. case *pg.Node_AlterOpFamilyStmt:
  2805. return convertAlterOpFamilyStmt(n.AlterOpFamilyStmt)
  2806. case *pg.Node_AlterOperatorStmt:
  2807. return convertAlterOperatorStmt(n.AlterOperatorStmt)
  2808. case *pg.Node_AlterOwnerStmt:
  2809. return convertAlterOwnerStmt(n.AlterOwnerStmt)
  2810. case *pg.Node_AlterPolicyStmt:
  2811. return convertAlterPolicyStmt(n.AlterPolicyStmt)
  2812. case *pg.Node_AlterPublicationStmt:
  2813. return convertAlterPublicationStmt(n.AlterPublicationStmt)
  2814. case *pg.Node_AlterRoleSetStmt:
  2815. return convertAlterRoleSetStmt(n.AlterRoleSetStmt)
  2816. case *pg.Node_AlterRoleStmt:
  2817. return convertAlterRoleStmt(n.AlterRoleStmt)
  2818. case *pg.Node_AlterSeqStmt:
  2819. return convertAlterSeqStmt(n.AlterSeqStmt)
  2820. case *pg.Node_AlterSubscriptionStmt:
  2821. return convertAlterSubscriptionStmt(n.AlterSubscriptionStmt)
  2822. case *pg.Node_AlterSystemStmt:
  2823. return convertAlterSystemStmt(n.AlterSystemStmt)
  2824. case *pg.Node_AlterTsconfigurationStmt:
  2825. return convertAlterTSConfigurationStmt(n.AlterTsconfigurationStmt)
  2826. case *pg.Node_AlterTsdictionaryStmt:
  2827. return convertAlterTSDictionaryStmt(n.AlterTsdictionaryStmt)
  2828. case *pg.Node_AlterTableCmd:
  2829. return convertAlterTableCmd(n.AlterTableCmd)
  2830. case *pg.Node_AlterTableMoveAllStmt:
  2831. return convertAlterTableMoveAllStmt(n.AlterTableMoveAllStmt)
  2832. case *pg.Node_AlterTableSpaceOptionsStmt:
  2833. return convertAlterTableSpaceOptionsStmt(n.AlterTableSpaceOptionsStmt)
  2834. case *pg.Node_AlterTableStmt:
  2835. return convertAlterTableStmt(n.AlterTableStmt)
  2836. case *pg.Node_AlterUserMappingStmt:
  2837. return convertAlterUserMappingStmt(n.AlterUserMappingStmt)
  2838. case *pg.Node_AlternativeSubPlan:
  2839. return convertAlternativeSubPlan(n.AlternativeSubPlan)
  2840. case *pg.Node_ArrayCoerceExpr:
  2841. return convertArrayCoerceExpr(n.ArrayCoerceExpr)
  2842. case *pg.Node_ArrayExpr:
  2843. return convertArrayExpr(n.ArrayExpr)
  2844. case *pg.Node_BitString:
  2845. return convertBitString(n.BitString)
  2846. case *pg.Node_BoolExpr:
  2847. return convertBoolExpr(n.BoolExpr)
  2848. case *pg.Node_Boolean:
  2849. return convertBoolean(n.Boolean)
  2850. case *pg.Node_BooleanTest:
  2851. return convertBooleanTest(n.BooleanTest)
  2852. case *pg.Node_CallStmt:
  2853. return convertCallStmt(n.CallStmt)
  2854. case *pg.Node_CaseExpr:
  2855. return convertCaseExpr(n.CaseExpr)
  2856. case *pg.Node_CaseTestExpr:
  2857. return convertCaseTestExpr(n.CaseTestExpr)
  2858. case *pg.Node_CaseWhen:
  2859. return convertCaseWhen(n.CaseWhen)
  2860. case *pg.Node_CheckPointStmt:
  2861. return convertCheckPointStmt(n.CheckPointStmt)
  2862. case *pg.Node_ClosePortalStmt:
  2863. return convertClosePortalStmt(n.ClosePortalStmt)
  2864. case *pg.Node_ClusterStmt:
  2865. return convertClusterStmt(n.ClusterStmt)
  2866. case *pg.Node_CoalesceExpr:
  2867. return convertCoalesceExpr(n.CoalesceExpr)
  2868. case *pg.Node_CoerceToDomain:
  2869. return convertCoerceToDomain(n.CoerceToDomain)
  2870. case *pg.Node_CoerceToDomainValue:
  2871. return convertCoerceToDomainValue(n.CoerceToDomainValue)
  2872. case *pg.Node_CoerceViaIo:
  2873. return convertCoerceViaIO(n.CoerceViaIo)
  2874. case *pg.Node_CollateClause:
  2875. return convertCollateClause(n.CollateClause)
  2876. case *pg.Node_CollateExpr:
  2877. return convertCollateExpr(n.CollateExpr)
  2878. case *pg.Node_ColumnDef:
  2879. return convertColumnDef(n.ColumnDef)
  2880. case *pg.Node_ColumnRef:
  2881. return convertColumnRef(n.ColumnRef)
  2882. case *pg.Node_CommentStmt:
  2883. return convertCommentStmt(n.CommentStmt)
  2884. case *pg.Node_CommonTableExpr:
  2885. return convertCommonTableExpr(n.CommonTableExpr)
  2886. case *pg.Node_CompositeTypeStmt:
  2887. return convertCompositeTypeStmt(n.CompositeTypeStmt)
  2888. case *pg.Node_Constraint:
  2889. return convertConstraint(n.Constraint)
  2890. case *pg.Node_ConstraintsSetStmt:
  2891. return convertConstraintsSetStmt(n.ConstraintsSetStmt)
  2892. case *pg.Node_ConvertRowtypeExpr:
  2893. return convertConvertRowtypeExpr(n.ConvertRowtypeExpr)
  2894. case *pg.Node_CopyStmt:
  2895. return convertCopyStmt(n.CopyStmt)
  2896. case *pg.Node_CreateAmStmt:
  2897. return convertCreateAmStmt(n.CreateAmStmt)
  2898. case *pg.Node_CreateCastStmt:
  2899. return convertCreateCastStmt(n.CreateCastStmt)
  2900. case *pg.Node_CreateConversionStmt:
  2901. return convertCreateConversionStmt(n.CreateConversionStmt)
  2902. case *pg.Node_CreateDomainStmt:
  2903. return convertCreateDomainStmt(n.CreateDomainStmt)
  2904. case *pg.Node_CreateEnumStmt:
  2905. return convertCreateEnumStmt(n.CreateEnumStmt)
  2906. case *pg.Node_CreateEventTrigStmt:
  2907. return convertCreateEventTrigStmt(n.CreateEventTrigStmt)
  2908. case *pg.Node_CreateExtensionStmt:
  2909. return convertCreateExtensionStmt(n.CreateExtensionStmt)
  2910. case *pg.Node_CreateFdwStmt:
  2911. return convertCreateFdwStmt(n.CreateFdwStmt)
  2912. case *pg.Node_CreateForeignServerStmt:
  2913. return convertCreateForeignServerStmt(n.CreateForeignServerStmt)
  2914. case *pg.Node_CreateForeignTableStmt:
  2915. return convertCreateForeignTableStmt(n.CreateForeignTableStmt)
  2916. case *pg.Node_CreateFunctionStmt:
  2917. return convertCreateFunctionStmt(n.CreateFunctionStmt)
  2918. case *pg.Node_CreateOpClassItem:
  2919. return convertCreateOpClassItem(n.CreateOpClassItem)
  2920. case *pg.Node_CreateOpClassStmt:
  2921. return convertCreateOpClassStmt(n.CreateOpClassStmt)
  2922. case *pg.Node_CreateOpFamilyStmt:
  2923. return convertCreateOpFamilyStmt(n.CreateOpFamilyStmt)
  2924. case *pg.Node_CreatePlangStmt:
  2925. return convertCreatePLangStmt(n.CreatePlangStmt)
  2926. case *pg.Node_CreatePolicyStmt:
  2927. return convertCreatePolicyStmt(n.CreatePolicyStmt)
  2928. case *pg.Node_CreatePublicationStmt:
  2929. return convertCreatePublicationStmt(n.CreatePublicationStmt)
  2930. case *pg.Node_CreateRangeStmt:
  2931. return convertCreateRangeStmt(n.CreateRangeStmt)
  2932. case *pg.Node_CreateRoleStmt:
  2933. return convertCreateRoleStmt(n.CreateRoleStmt)
  2934. case *pg.Node_CreateSchemaStmt:
  2935. return convertCreateSchemaStmt(n.CreateSchemaStmt)
  2936. case *pg.Node_CreateSeqStmt:
  2937. return convertCreateSeqStmt(n.CreateSeqStmt)
  2938. case *pg.Node_CreateStatsStmt:
  2939. return convertCreateStatsStmt(n.CreateStatsStmt)
  2940. case *pg.Node_CreateStmt:
  2941. return convertCreateStmt(n.CreateStmt)
  2942. case *pg.Node_CreateSubscriptionStmt:
  2943. return convertCreateSubscriptionStmt(n.CreateSubscriptionStmt)
  2944. case *pg.Node_CreateTableAsStmt:
  2945. return convertCreateTableAsStmt(n.CreateTableAsStmt)
  2946. case *pg.Node_CreateTableSpaceStmt:
  2947. return convertCreateTableSpaceStmt(n.CreateTableSpaceStmt)
  2948. case *pg.Node_CreateTransformStmt:
  2949. return convertCreateTransformStmt(n.CreateTransformStmt)
  2950. case *pg.Node_CreateTrigStmt:
  2951. return convertCreateTrigStmt(n.CreateTrigStmt)
  2952. case *pg.Node_CreateUserMappingStmt:
  2953. return convertCreateUserMappingStmt(n.CreateUserMappingStmt)
  2954. case *pg.Node_CreatedbStmt:
  2955. return convertCreatedbStmt(n.CreatedbStmt)
  2956. case *pg.Node_CurrentOfExpr:
  2957. return convertCurrentOfExpr(n.CurrentOfExpr)
  2958. case *pg.Node_DeallocateStmt:
  2959. return convertDeallocateStmt(n.DeallocateStmt)
  2960. case *pg.Node_DeclareCursorStmt:
  2961. return convertDeclareCursorStmt(n.DeclareCursorStmt)
  2962. case *pg.Node_DefElem:
  2963. return convertDefElem(n.DefElem)
  2964. case *pg.Node_DefineStmt:
  2965. return convertDefineStmt(n.DefineStmt)
  2966. case *pg.Node_DeleteStmt:
  2967. return convertDeleteStmt(n.DeleteStmt)
  2968. case *pg.Node_DiscardStmt:
  2969. return convertDiscardStmt(n.DiscardStmt)
  2970. case *pg.Node_DoStmt:
  2971. return convertDoStmt(n.DoStmt)
  2972. case *pg.Node_DropOwnedStmt:
  2973. return convertDropOwnedStmt(n.DropOwnedStmt)
  2974. case *pg.Node_DropRoleStmt:
  2975. return convertDropRoleStmt(n.DropRoleStmt)
  2976. case *pg.Node_DropStmt:
  2977. return convertDropStmt(n.DropStmt)
  2978. case *pg.Node_DropSubscriptionStmt:
  2979. return convertDropSubscriptionStmt(n.DropSubscriptionStmt)
  2980. case *pg.Node_DropTableSpaceStmt:
  2981. return convertDropTableSpaceStmt(n.DropTableSpaceStmt)
  2982. case *pg.Node_DropUserMappingStmt:
  2983. return convertDropUserMappingStmt(n.DropUserMappingStmt)
  2984. case *pg.Node_DropdbStmt:
  2985. return convertDropdbStmt(n.DropdbStmt)
  2986. case *pg.Node_ExecuteStmt:
  2987. return convertExecuteStmt(n.ExecuteStmt)
  2988. case *pg.Node_ExplainStmt:
  2989. return convertExplainStmt(n.ExplainStmt)
  2990. case *pg.Node_FetchStmt:
  2991. return convertFetchStmt(n.FetchStmt)
  2992. case *pg.Node_FieldSelect:
  2993. return convertFieldSelect(n.FieldSelect)
  2994. case *pg.Node_FieldStore:
  2995. return convertFieldStore(n.FieldStore)
  2996. case *pg.Node_Float:
  2997. return convertFloat(n.Float)
  2998. case *pg.Node_FromExpr:
  2999. return convertFromExpr(n.FromExpr)
  3000. case *pg.Node_FuncCall:
  3001. return convertFuncCall(n.FuncCall)
  3002. case *pg.Node_FuncExpr:
  3003. return convertFuncExpr(n.FuncExpr)
  3004. case *pg.Node_FunctionParameter:
  3005. return convertFunctionParameter(n.FunctionParameter)
  3006. case *pg.Node_GrantRoleStmt:
  3007. return convertGrantRoleStmt(n.GrantRoleStmt)
  3008. case *pg.Node_GrantStmt:
  3009. return convertGrantStmt(n.GrantStmt)
  3010. case *pg.Node_GroupingFunc:
  3011. return convertGroupingFunc(n.GroupingFunc)
  3012. case *pg.Node_GroupingSet:
  3013. return convertGroupingSet(n.GroupingSet)
  3014. case *pg.Node_ImportForeignSchemaStmt:
  3015. return convertImportForeignSchemaStmt(n.ImportForeignSchemaStmt)
  3016. case *pg.Node_IndexElem:
  3017. return convertIndexElem(n.IndexElem)
  3018. case *pg.Node_IndexStmt:
  3019. return convertIndexStmt(n.IndexStmt)
  3020. case *pg.Node_InferClause:
  3021. return convertInferClause(n.InferClause)
  3022. case *pg.Node_InferenceElem:
  3023. return convertInferenceElem(n.InferenceElem)
  3024. case *pg.Node_InlineCodeBlock:
  3025. return convertInlineCodeBlock(n.InlineCodeBlock)
  3026. case *pg.Node_InsertStmt:
  3027. return convertInsertStmt(n.InsertStmt)
  3028. case *pg.Node_Integer:
  3029. return convertInteger(n.Integer)
  3030. case *pg.Node_IntoClause:
  3031. return convertIntoClause(n.IntoClause)
  3032. case *pg.Node_JoinExpr:
  3033. return convertJoinExpr(n.JoinExpr)
  3034. case *pg.Node_List:
  3035. return convertList(n.List)
  3036. case *pg.Node_ListenStmt:
  3037. return convertListenStmt(n.ListenStmt)
  3038. case *pg.Node_LoadStmt:
  3039. return convertLoadStmt(n.LoadStmt)
  3040. case *pg.Node_LockStmt:
  3041. return convertLockStmt(n.LockStmt)
  3042. case *pg.Node_LockingClause:
  3043. return convertLockingClause(n.LockingClause)
  3044. case *pg.Node_MinMaxExpr:
  3045. return convertMinMaxExpr(n.MinMaxExpr)
  3046. case *pg.Node_MultiAssignRef:
  3047. return convertMultiAssignRef(n.MultiAssignRef)
  3048. case *pg.Node_NamedArgExpr:
  3049. return convertNamedArgExpr(n.NamedArgExpr)
  3050. case *pg.Node_NextValueExpr:
  3051. return convertNextValueExpr(n.NextValueExpr)
  3052. case *pg.Node_NotifyStmt:
  3053. return convertNotifyStmt(n.NotifyStmt)
  3054. case *pg.Node_NullTest:
  3055. return convertNullTest(n.NullTest)
  3056. case *pg.Node_ObjectWithArgs:
  3057. return convertObjectWithArgs(n.ObjectWithArgs)
  3058. case *pg.Node_OnConflictClause:
  3059. return convertOnConflictClause(n.OnConflictClause)
  3060. case *pg.Node_OnConflictExpr:
  3061. return convertOnConflictExpr(n.OnConflictExpr)
  3062. case *pg.Node_OpExpr:
  3063. return convertOpExpr(n.OpExpr)
  3064. case *pg.Node_Param:
  3065. return convertParam(n.Param)
  3066. case *pg.Node_ParamRef:
  3067. return convertParamRef(n.ParamRef)
  3068. case *pg.Node_PartitionBoundSpec:
  3069. return convertPartitionBoundSpec(n.PartitionBoundSpec)
  3070. case *pg.Node_PartitionCmd:
  3071. return convertPartitionCmd(n.PartitionCmd)
  3072. case *pg.Node_PartitionElem:
  3073. return convertPartitionElem(n.PartitionElem)
  3074. case *pg.Node_PartitionRangeDatum:
  3075. return convertPartitionRangeDatum(n.PartitionRangeDatum)
  3076. case *pg.Node_PartitionSpec:
  3077. return convertPartitionSpec(n.PartitionSpec)
  3078. case *pg.Node_PrepareStmt:
  3079. return convertPrepareStmt(n.PrepareStmt)
  3080. case *pg.Node_Query:
  3081. return convertQuery(n.Query)
  3082. case *pg.Node_RangeFunction:
  3083. return convertRangeFunction(n.RangeFunction)
  3084. case *pg.Node_RangeSubselect:
  3085. return convertRangeSubselect(n.RangeSubselect)
  3086. case *pg.Node_RangeTableFunc:
  3087. return convertRangeTableFunc(n.RangeTableFunc)
  3088. case *pg.Node_RangeTableFuncCol:
  3089. return convertRangeTableFuncCol(n.RangeTableFuncCol)
  3090. case *pg.Node_RangeTableSample:
  3091. return convertRangeTableSample(n.RangeTableSample)
  3092. case *pg.Node_RangeTblEntry:
  3093. return convertRangeTblEntry(n.RangeTblEntry)
  3094. case *pg.Node_RangeTblFunction:
  3095. return convertRangeTblFunction(n.RangeTblFunction)
  3096. case *pg.Node_RangeTblRef:
  3097. return convertRangeTblRef(n.RangeTblRef)
  3098. case *pg.Node_RangeVar:
  3099. return convertRangeVar(n.RangeVar)
  3100. case *pg.Node_RawStmt:
  3101. return convertRawStmt(n.RawStmt)
  3102. case *pg.Node_ReassignOwnedStmt:
  3103. return convertReassignOwnedStmt(n.ReassignOwnedStmt)
  3104. case *pg.Node_RefreshMatViewStmt:
  3105. return convertRefreshMatViewStmt(n.RefreshMatViewStmt)
  3106. case *pg.Node_ReindexStmt:
  3107. return convertReindexStmt(n.ReindexStmt)
  3108. case *pg.Node_RelabelType:
  3109. return convertRelabelType(n.RelabelType)
  3110. case *pg.Node_RenameStmt:
  3111. return convertRenameStmt(n.RenameStmt)
  3112. case *pg.Node_ReplicaIdentityStmt:
  3113. return convertReplicaIdentityStmt(n.ReplicaIdentityStmt)
  3114. case *pg.Node_ResTarget:
  3115. return convertResTarget(n.ResTarget)
  3116. case *pg.Node_RoleSpec:
  3117. return convertRoleSpec(n.RoleSpec)
  3118. case *pg.Node_RowCompareExpr:
  3119. return convertRowCompareExpr(n.RowCompareExpr)
  3120. case *pg.Node_RowExpr:
  3121. return convertRowExpr(n.RowExpr)
  3122. case *pg.Node_RowMarkClause:
  3123. return convertRowMarkClause(n.RowMarkClause)
  3124. case *pg.Node_RuleStmt:
  3125. return convertRuleStmt(n.RuleStmt)
  3126. case *pg.Node_SqlvalueFunction:
  3127. return convertSQLValueFunction(n.SqlvalueFunction)
  3128. case *pg.Node_ScalarArrayOpExpr:
  3129. return convertScalarArrayOpExpr(n.ScalarArrayOpExpr)
  3130. case *pg.Node_SecLabelStmt:
  3131. return convertSecLabelStmt(n.SecLabelStmt)
  3132. case *pg.Node_SelectStmt:
  3133. return convertSelectStmt(n.SelectStmt)
  3134. case *pg.Node_SetOperationStmt:
  3135. return convertSetOperationStmt(n.SetOperationStmt)
  3136. case *pg.Node_SetToDefault:
  3137. return convertSetToDefault(n.SetToDefault)
  3138. case *pg.Node_SortBy:
  3139. return convertSortBy(n.SortBy)
  3140. case *pg.Node_SortGroupClause:
  3141. return convertSortGroupClause(n.SortGroupClause)
  3142. case *pg.Node_String_:
  3143. return convertString(n.String_)
  3144. case *pg.Node_SubLink:
  3145. return convertSubLink(n.SubLink)
  3146. case *pg.Node_SubPlan:
  3147. return convertSubPlan(n.SubPlan)
  3148. case *pg.Node_TableFunc:
  3149. return convertTableFunc(n.TableFunc)
  3150. case *pg.Node_TableLikeClause:
  3151. return convertTableLikeClause(n.TableLikeClause)
  3152. case *pg.Node_TableSampleClause:
  3153. return convertTableSampleClause(n.TableSampleClause)
  3154. case *pg.Node_TargetEntry:
  3155. return convertTargetEntry(n.TargetEntry)
  3156. case *pg.Node_TransactionStmt:
  3157. return convertTransactionStmt(n.TransactionStmt)
  3158. case *pg.Node_TriggerTransition:
  3159. return convertTriggerTransition(n.TriggerTransition)
  3160. case *pg.Node_TruncateStmt:
  3161. return convertTruncateStmt(n.TruncateStmt)
  3162. case *pg.Node_TypeCast:
  3163. return convertTypeCast(n.TypeCast)
  3164. case *pg.Node_TypeName:
  3165. return convertTypeName(n.TypeName)
  3166. case *pg.Node_UnlistenStmt:
  3167. return convertUnlistenStmt(n.UnlistenStmt)
  3168. case *pg.Node_UpdateStmt:
  3169. return convertUpdateStmt(n.UpdateStmt)
  3170. case *pg.Node_VacuumStmt:
  3171. return convertVacuumStmt(n.VacuumStmt)
  3172. case *pg.Node_Var:
  3173. return convertVar(n.Var)
  3174. case *pg.Node_VariableSetStmt:
  3175. return convertVariableSetStmt(n.VariableSetStmt)
  3176. case *pg.Node_VariableShowStmt:
  3177. return convertVariableShowStmt(n.VariableShowStmt)
  3178. case *pg.Node_ViewStmt:
  3179. return convertViewStmt(n.ViewStmt)
  3180. case *pg.Node_WindowClause:
  3181. return convertWindowClause(n.WindowClause)
  3182. case *pg.Node_WindowDef:
  3183. return convertWindowDef(n.WindowDef)
  3184. case *pg.Node_WindowFunc:
  3185. return convertWindowFunc(n.WindowFunc)
  3186. case *pg.Node_WithCheckOption:
  3187. return convertWithCheckOption(n.WithCheckOption)
  3188. case *pg.Node_WithClause:
  3189. return convertWithClause(n.WithClause)
  3190. case *pg.Node_XmlExpr:
  3191. return convertXmlExpr(n.XmlExpr)
  3192. case *pg.Node_XmlSerialize:
  3193. return convertXmlSerialize(n.XmlSerialize)
  3194. default:
  3195. return &ast.TODO{}
  3196. }
  3197. }