list.slt 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. mode cockroach
  10. # The LIST type has an uncommon OID. If tokio-postres (the driver used
  11. # by sqllogictest) encounters an OID it doesn't recognize (LIST in
  12. # this case), then it queries pg_type (a wrapper around mz_types) for
  13. # information about it. Our LIST type currently doesn't have an entry in
  14. # mz_types, so that query fails and tokio-postgres is unable to execute
  15. # queries with LISTs. As a workaround until LIST is reflected in pg_type,
  16. # we just convert everything to `text`.
  17. simple conn=mz_system,user=mz_system
  18. ALTER SYSTEM SET enable_list_n_layers = true
  19. ----
  20. COMPLETE 0
  21. simple conn=mz_system,user=mz_system
  22. ALTER SYSTEM SET enable_list_length_max = true
  23. ----
  24. COMPLETE 0
  25. simple conn=mz_system,user=mz_system
  26. ALTER SYSTEM SET enable_list_remove = true
  27. ----
  28. COMPLETE 0
  29. query T
  30. SELECT (LIST[1,2,3])::text
  31. ----
  32. {1,2,3}
  33. query error LIST types integer and integer list cannot be matched
  34. SELECT LIST[1,LIST[2,3]]
  35. query T
  36. SELECT (LIST[[1],[2,3]])::text
  37. ----
  38. {{1},{2,3}}
  39. query error cannot determine type of empty list
  40. SELECT LIST[]
  41. query T
  42. SELECT (LIST[] :: INT LIST)::text
  43. ----
  44. {}
  45. query T
  46. SELECT (LIST[null])::text
  47. ----
  48. {NULL}
  49. query T
  50. SELECT (LIST[1, null])::text
  51. ----
  52. {1,NULL}
  53. query T
  54. SELECT (LIST[1, null] :: INT LIST)::text
  55. ----
  56. {1,NULL}
  57. query T
  58. SELECT (LIST[[1, null], []] :: INT LIST LIST)::text
  59. ----
  60. {{1,NULL},{}}
  61. # Lists support arbitrarily deep nesting
  62. query T
  63. SELECT (LIST[[[[1], [2]]], [[[3]]]])::text
  64. ----
  65. {{{{1},{2}}},{{{3}}}}
  66. # List(Int) cannot be cast to List(List(Int))
  67. query error LIST could not convert type integer to integer list
  68. SELECT LIST[1, null] :: INT LIST LIST
  69. query T
  70. SELECT (LIST[1, null] :: TEXT LIST)::text
  71. ----
  72. {1,NULL}
  73. query T
  74. SELECT (LIST['foo', 'f}o', '"\', null, 'null', 'NULL'])::text
  75. ----
  76. {foo,"f}o","\"\\",NULL,null,"NULL"}
  77. query T
  78. SELECT (list[list[list['"']]])::text
  79. ----
  80. {{{"\""}}}
  81. query T
  82. SELECT (list['{1}'])::text
  83. ----
  84. {"{1}"}
  85. query T
  86. SELECT (LIST[LIST[]::text list, LIST['a', 'b'], LIST['z']])::text
  87. ----
  88. {{},{a,b},{z}}
  89. # 🔬 list subscripts
  90. # 🔬🔬 list indexes
  91. query R
  92. SELECT LIST [1, 2, 3][2]
  93. ----
  94. 2
  95. # exceeds maximum index
  96. query R
  97. SELECT LIST [1, 2, 3][100]
  98. ----
  99. NULL
  100. # negative
  101. query R
  102. SELECT LIST [1, 2, 3][-1]
  103. ----
  104. NULL
  105. # exceeds maximum layer
  106. query error cannot index into
  107. SELECT LIST [1, 2, 3][1][1]
  108. # exceeds maximum layer
  109. query error cannot subscript
  110. SELECT LIST[1,2,3][1:1][1][1:1];
  111. query error cannot subscript
  112. SELECT LIST[1,2,3][1][1:1][1];
  113. # 🔬🔬 list slices
  114. query T
  115. SELECT (LIST [1, 2, 3][2:3])::text
  116. ----
  117. {2,3}
  118. query T
  119. SELECT (LIST [1, 2, 3][2:])::text
  120. ----
  121. {2,3}
  122. query T
  123. SELECT (LIST [1, 2, 3][:2])::text
  124. ----
  125. {1,2}
  126. query T
  127. SELECT (LIST [1, 2, 3][:])::text
  128. ----
  129. {1,2,3}
  130. # start exceeds maximum index
  131. query T
  132. SELECT (LIST [1, 2, 3][100:])::text
  133. ----
  134. {}
  135. # end exceeds maximum index
  136. query T
  137. SELECT (LIST [1, 2, 3][:100])::text
  138. ----
  139. {1,2,3}
  140. # 🔬🔬 list repeated slices
  141. query T
  142. SELECT (LIST [1, 2, 3, 4, 5][3:5][1:2][:])::text
  143. ----
  144. {3,4}
  145. # 🔬🔬 list slices + index
  146. query T
  147. SELECT (LIST [[1],[2],[3]][2:3])[2]::text
  148. ----
  149. {3}
  150. # 🔬 list list subscripts
  151. # 🔬🔬 list list indexes
  152. query T
  153. SELECT (LIST [[1, 2, 3], [4, 5]][1])::text
  154. ----
  155. {1,2,3}
  156. query R
  157. SELECT LIST [[1, 2, 3], [4, 5]][1][3]
  158. ----
  159. 3
  160. # exceeds maximum index
  161. query T
  162. SELECT (LIST [[1, 2, 3], [4, 5]][100])::text
  163. ----
  164. NULL
  165. query T
  166. SELECT (LIST [[1, 2, 3], [4, 5]][1][100])::text
  167. ----
  168. NULL
  169. query T
  170. SELECT (LIST [[1, 2, 3], [4, 5]][100][1])::text
  171. ----
  172. NULL
  173. # exceeds maximum layer
  174. query error cannot index into
  175. SELECT LIST [[1, 2, 3], [4, 5]][1][1][1]
  176. # 🔬🔬 list list slices
  177. query T
  178. SELECT (LIST [[1, 2, 3], [4, 5]][2:2])::text
  179. ----
  180. {{4,5}}
  181. query T
  182. SELECT (LIST [[1, 2, 3], [4, 5]][2:])::text
  183. ----
  184. {{4,5}}
  185. # end exceeds maximum index
  186. query T
  187. SELECT (LIST [[1, 2, 3], [4, 5]][:100][:])::text
  188. ----
  189. {{1,2,3},{4,5}}
  190. # 🔬🔬🔬 index + slice
  191. query T
  192. SELECT list[list[1,2], list[3,4]][2][2:2]::text;
  193. ----
  194. {4}
  195. query T
  196. SELECT list[[1,2], list[3,4]][2][2:]::text;
  197. ----
  198. {4}
  199. query T
  200. SELECT list[[1,2], list[3,4]][2][:2]::text;
  201. ----
  202. {3,4}
  203. # 🔬🔬🔬 slice + index
  204. query T
  205. SELECT list[list[1,2], list[3,4]][2:2][2]::text;
  206. ----
  207. NULL
  208. query T
  209. SELECT list[list[1,2], list[3,4]][:2][2]::text;
  210. ----
  211. {3,4}
  212. query T
  213. SELECT list[[1,2], list[3,4]][2:][2]::text;
  214. ----
  215. NULL
  216. # 🔬🔬🔬 layered list slices patterns, linear
  217. query T
  218. SELECT list[list[1,2], list[3,4]][1:2][2:2]::text;
  219. ----
  220. {{3,4}}
  221. query T
  222. SELECT list[list[1,2], list[3,4]][:2][2:2]::text;
  223. ----
  224. {{3,4}}
  225. query T
  226. SELECT list[list[1,2], list[3,4]][:2][2:]::text;
  227. ----
  228. {{3,4}}
  229. query T
  230. SELECT list[list[1,2], list[3,4]][:][2:]::text;
  231. ----
  232. {{3,4}}
  233. # 🔬🔬 list list slices + index
  234. query T
  235. SELECT (LIST [[1, 2, 3], [4, 5]][2:2])[1][2]::text
  236. ----
  237. 5
  238. # 🔬 list list list
  239. # 🔬🔬 list list list indexes
  240. query T
  241. SELECT (LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][1])::text
  242. ----
  243. {{1,2},{3,4,5}}
  244. query T
  245. SELECT (LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][1][2])::text
  246. ----
  247. {3,4,5}
  248. query R
  249. SELECT LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][1][2][3]
  250. ----
  251. 5
  252. # exceeds maximum index
  253. query T
  254. SELECT (LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][100])::text
  255. ----
  256. NULL
  257. query T
  258. SELECT (LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][1][100])::text
  259. ----
  260. NULL
  261. query R
  262. SELECT LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][1][2][100]
  263. ----
  264. NULL
  265. query R
  266. SELECT LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][100][2][3]
  267. ----
  268. NULL
  269. query R
  270. SELECT LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][1][100][3]
  271. ----
  272. NULL
  273. # exceeds maximum layer
  274. query error cannot index into
  275. SELECT LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][1][2][3][1]
  276. # 🔬🔬 list list list slices
  277. query T
  278. SELECT (LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][1:2])::text
  279. ----
  280. {{{1,2},{3,4,5}},{{6}}}
  281. # start exceeds maximum index
  282. query T
  283. SELECT (LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][100:100])::text
  284. ----
  285. {}
  286. # end exceeds maximum index
  287. query T
  288. SELECT (LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][:100])::text
  289. ----
  290. {{{1,2},{3,4,5}},{{6}},{{7,8},{9}}}
  291. # 🔬🔬🔬 layered list repeated slices
  292. query T
  293. SELECT (LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][2:3][:][2:2])::text
  294. ----
  295. {{{7,8},{9}}}
  296. # 🔬🔬 list list list slices + index
  297. query T
  298. SELECT (LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][2:3])[2]::text
  299. ----
  300. {{7,8},{9}}
  301. query T
  302. SELECT (LIST[1, 2, 3][NULL])::text
  303. ----
  304. NULL
  305. query T
  306. SELECT (LIST[1, 2, 3][NULL:NULL])::text
  307. ----
  308. NULL
  309. query T
  310. SELECT (LIST[1, 2, 3][1:NULL])::text
  311. ----
  312. NULL
  313. query T
  314. SELECT (LIST[1, 2, 3][NULL:1])::text
  315. ----
  316. NULL
  317. query T
  318. SELECT (LIST[1, 2, 3][NULL:])::text
  319. ----
  320. NULL
  321. query T
  322. SELECT (LIST[1, 2, 3][:NULL])::text
  323. ----
  324. NULL
  325. query T
  326. SELECT (LIST[NULL][:])::text
  327. ----
  328. {NULL}
  329. query T
  330. SELECT (LIST[1, NULL, 3][:NULL])::text
  331. ----
  332. NULL
  333. query T
  334. SELECT ((LIST [[1, NULL, 3], NULL, [4, NULL, 6]]::INT LIST LIST)[2:])::text
  335. ----
  336. {NULL,{4,NULL,6}}
  337. # 🔬🔬 Slices and NULLs
  338. # NULL literals are not touched by slice operations
  339. query T
  340. SELECT ((LIST[NULL]::INT LIST)[1:1])::text
  341. ----
  342. {NULL}
  343. # 🔬 Empty lists expressions
  344. query T
  345. SELECT ((LIST[]::INT LIST)[1])::text
  346. ----
  347. NULL
  348. query T
  349. SELECT ((LIST[]::INT LIST)[:])::text
  350. ----
  351. {}
  352. query T
  353. SELECT ((LIST[]::INT LIST)[1:1])::text
  354. ----
  355. {}
  356. # 🔬 Other subscript values
  357. # 🔬🔬 end > start
  358. query T
  359. SELECT (LIST[1, 2, 3][2:1])::text
  360. ----
  361. {}
  362. # 🔬🔬 Negative values
  363. query T
  364. SELECT (LIST[1, 2, 3][-100])::text
  365. ----
  366. NULL
  367. query T
  368. SELECT (LIST[1, 2, 3][-100:])::text
  369. ----
  370. {1,2,3}
  371. query T
  372. SELECT (LIST[1, 2, 3][-100:99])::text
  373. ----
  374. {1,2,3}
  375. query T
  376. SELECT (LIST[1, 2, 3][-100:-99])::text
  377. ----
  378. {}
  379. query T
  380. SELECT (LIST[1, 2, 3][-100:-101])::text
  381. ----
  382. {}
  383. query T
  384. SELECT (LIST[1, 2, 3][:-100])::text
  385. ----
  386. {}
  387. # 🔬🔬 min/max
  388. query R
  389. SELECT LIST[1][9223372036854775807::bigint]
  390. ----
  391. NULL
  392. query R
  393. SELECT LIST[1][-9223372036854775807::bigint]
  394. ----
  395. NULL
  396. query T
  397. SELECT (LIST[1][9223372036854775807::bigint:9223372036854775807::bigint])::text
  398. ----
  399. {}
  400. query T
  401. SELECT (LIST[1][9223372036854775807::bigint:-9223372036854775807::bigint])::text
  402. ----
  403. {}
  404. query T
  405. SELECT (LIST[1][-9223372036854775807::bigint:9223372036854775807::bigint])::text
  406. ----
  407. {1}
  408. query T
  409. SELECT (LIST[1][-9223372036854775807::bigint:-9223372036854775807::bigint])::text
  410. ----
  411. {}
  412. # 🔬 Non-int subscript values
  413. # 🔬🔬 Ok
  414. query R
  415. SELECT LIST[1,2,3][1.4]
  416. ----
  417. 1
  418. query R
  419. SELECT LIST[1,2,3][1.5]
  420. ----
  421. 2
  422. query R
  423. SELECT LIST[1,2,3][1.5::real]
  424. ----
  425. 2
  426. query R
  427. SELECT LIST[1,2,3][1.5::float]
  428. ----
  429. 2
  430. query R
  431. SELECT LIST[1,2,3][1.5 + 1.6]
  432. ----
  433. 3
  434. query T
  435. SELECT (LIST[1,2,3][0.1 * 2 : 0.5 + 1.6])::text
  436. ----
  437. {1,2}
  438. query T
  439. SELECT (LIST[1,2,3][LIST[1][2.0 / 2]])::text
  440. ----
  441. 1
  442. # 🔬🔬 Err
  443. query error invalid input syntax for type bigint: invalid digit found in string: "dog"
  444. SELECT LIST[1,2,3]['dog']
  445. query error subscripting does not support casting from date to bigint
  446. SELECT LIST [[1, 2, 3], [4, 5]][DATE '2001-01-01']
  447. query error subscripting does not support casting from timestamp without time zone to bigint
  448. SELECT LIST [[1, 2, 3], [4, 5]][TIMESTAMP '2001-01-01']
  449. query error invalid input syntax for type bigint: invalid digit found in string: "dog"
  450. SELECT (LIST[1,2,3][1:'dog'])::text
  451. query error subscripting does not support casting from date to bigint
  452. SELECT LIST [[1, 2, 3], [4, 5]][1:DATE '2001-01-01']
  453. query error subscripting does not support casting from timestamp without time zone to bigint
  454. SELECT LIST [[1, 2, 3], [4, 5]][1:TIMESTAMP '2001-01-01']
  455. # 🔬 Built-in functions
  456. # 🔬🔬 list_append
  457. # 🔬🔬🔬 list + element
  458. query T
  459. SELECT (list_append(LIST[1, 2], 3))::text
  460. ----
  461. {1,2,3}
  462. # 🔬🔬🔬 list list + list (list + element)
  463. query T
  464. SELECT (list_append(LIST[[1], [2]], LIST[3]))::text
  465. ----
  466. {{1},{2},{3}}
  467. # 🔬🔬🔬🔬 polymorphism
  468. query T
  469. SELECT pg_typeof(list_append(LIST[1::int2], 1::int8))
  470. ----
  471. bigint list
  472. query T
  473. SELECT pg_typeof(list_append(LIST[1::int8], 1::int2))
  474. ----
  475. bigint list
  476. # 🔬🔬🔬 NULL elements
  477. # 🔬🔬🔬🔬 list + element
  478. query T
  479. SELECT (list_append(LIST[1], NULL))::text
  480. ----
  481. {1,NULL}
  482. query T
  483. SELECT (list_append(NULL, 1))::text
  484. ----
  485. {1}
  486. query T
  487. SELECT (list_append(LIST[1], NULL))::text
  488. ----
  489. {1,NULL}
  490. query T
  491. SELECT (list_append(NULL, NULL::INT))::text
  492. ----
  493. {NULL}
  494. query T
  495. SELECT (list_append(NULL::INT LIST, NULL))::text
  496. ----
  497. {NULL}
  498. # 🔬🔬🔬🔬 list list + list (list + element)
  499. query T
  500. SELECT (list_append(LIST[[1]], NULL))::text
  501. ----
  502. {{1},NULL}
  503. query T
  504. SELECT (list_append(NULL, LIST[1]))::text
  505. ----
  506. {{1}}
  507. query T
  508. SELECT (list_append(NULL::INT LIST LIST, NULL))::text
  509. ----
  510. {NULL}
  511. query T
  512. SELECT (list_append(NULL, NULL::INT LIST))::text
  513. ----
  514. {NULL}
  515. # 🔬🔬🔬 errors
  516. query T
  517. SELECT list_append(NULL, NULL)::text
  518. ----
  519. {NULL}
  520. query error invalid input syntax for type integer
  521. SELECT list_append(LIST[1], 'a')::text
  522. query error db error: ERROR: function list_append\(integer list, integer list\) does not exist
  523. SELECT list_append(LIST[1], LIST[2])
  524. query error db error: ERROR: function list_append\(integer, integer list\) does not exist
  525. SELECT list_append(1, LIST[1])
  526. # 🔬🔬 list_cat
  527. # 🔬🔬🔬 list + list
  528. query T
  529. SELECT (list_cat(LIST[1, 2], LIST[3, 4]))::text
  530. ----
  531. {1,2,3,4}
  532. query T
  533. SELECT (list_cat(LIST[[1]], LIST[[2]]))::text
  534. ----
  535. {{1},{2}}
  536. # 🔬🔬🔬 NULL elements
  537. # 🔬🔬🔬🔬 list + list
  538. query T
  539. SELECT (list_cat(LIST[1], NULL))::text
  540. ----
  541. {1}
  542. query T
  543. SELECT (list_cat(LIST[1], NULL))::text
  544. ----
  545. {1}
  546. query T
  547. SELECT (list_cat(NULL, LIST[1]))::text
  548. ----
  549. {1}
  550. query T
  551. SELECT (list_cat(NULL::INT LIST, NULL))::text
  552. ----
  553. NULL
  554. query T
  555. SELECT (list_cat(NULL, NULL::INT LIST))::text
  556. ----
  557. NULL
  558. # 🔬🔬🔬🔬 polymorphism
  559. query T
  560. SELECT pg_typeof(list_cat(LIST[1::int2], LIST[1::int8]))
  561. ----
  562. bigint list
  563. query T
  564. SELECT pg_typeof(list_cat(LIST[1::int8], LIST[1::int2]))
  565. ----
  566. bigint list
  567. # 🔬🔬🔬 errors
  568. query error
  569. SELECT list_cat(NULL, NULL)
  570. query error
  571. SELECT list_cat('a', LIST[1])
  572. query error
  573. SELECT list_cat(LIST[1], LIST[[2]])
  574. # 🔬🔬 list_n_layers
  575. query R
  576. SELECT list_n_layers(LIST [1, 2, 3])
  577. ----
  578. 1
  579. query R
  580. SELECT list_n_layers(LIST []::INT LIST)
  581. ----
  582. 1
  583. query R
  584. SELECT list_n_layers(LIST[[1],[1]])
  585. ----
  586. 2
  587. query R
  588. SELECT list_n_layers(LIST [[[1], [1]], [[1]]])
  589. ----
  590. 3
  591. # 🔬🔬🔬 slices
  592. query R
  593. SELECT list_n_layers(LIST[[1],[1]][1:1])
  594. ----
  595. 2
  596. query R
  597. SELECT list_n_layers(LIST [[[1], [1]], [[1]]][1:2])
  598. ----
  599. 3
  600. # 🔬🔬🔬 interior lists
  601. query R
  602. SELECT list_n_layers(LIST[[1],[1]][1])
  603. ----
  604. 1
  605. query R
  606. SELECT list_n_layers(LIST [[[1], [1]], [[1]]][1])
  607. ----
  608. 2
  609. query R
  610. SELECT list_n_layers(LIST [[[1], [1]], [[1]]][1][1])
  611. ----
  612. 1
  613. # 🔬🔬🔬 NULL elements
  614. query R
  615. SELECT list_n_layers(LIST[NULL]::INT LIST)
  616. ----
  617. 1
  618. query R
  619. SELECT list_n_layers(LIST[NULL]::INT LIST LIST)
  620. ----
  621. 2
  622. query R
  623. SELECT list_n_layers(LIST[[1], NULL]::INT LIST LIST)
  624. ----
  625. 2
  626. query R
  627. SELECT list_n_layers((LIST[[1],NULL]::INT LIST LIST)[2])
  628. ----
  629. 1
  630. query error could not determine polymorphic type because input has type unknown
  631. SELECT list_n_layers(NULL)
  632. # 🔬🔬 list_length
  633. query R
  634. SELECT list_length(LIST [1])
  635. ----
  636. 1
  637. query R
  638. SELECT list_length(LIST [1, 1])
  639. ----
  640. 2
  641. query R
  642. SELECT list_length(LIST[[1],[1]])
  643. ----
  644. 2
  645. query R
  646. SELECT list_length(LIST [[[1], [1]], [[1]]])
  647. ----
  648. 2
  649. query R
  650. SELECT list_length(LIST []::INT LIST)
  651. ----
  652. 0
  653. # 🔬🔬🔬 slices
  654. query R
  655. SELECT list_length(LIST[[1],[1]][1:1])
  656. ----
  657. 1
  658. query R
  659. SELECT list_length(LIST [[[1, 2], [3, 4, 5]], [[6]], [[7, 8], [9]]][1:2])
  660. ----
  661. 2
  662. # 🔬🔬🔬 indexing operations
  663. query R
  664. SELECT list_length(LIST [[[1], [1]], [[1]]][1])
  665. ----
  666. 2
  667. query R
  668. SELECT list_length(LIST [[[1], [1]], [[1]]][1][1])
  669. ----
  670. 1
  671. # 🔬🔬🔬 NULL elements
  672. query R
  673. SELECT list_length(LIST[1, NULL]::INT LIST)
  674. ----
  675. 2
  676. query R
  677. SELECT list_length(LIST[[1],NULL]::INT LIST LIST)
  678. ----
  679. 2
  680. query R
  681. SELECT list_length((LIST[[1],NULL]::INT LIST LIST)[2])
  682. ----
  683. NULL
  684. query error could not determine polymorphic type because input has type unknown
  685. SELECT list_length(NULL)
  686. # 🔬🔬 list_length_max
  687. query R
  688. SELECT list_length_max(LIST [1, 2, 3], 1)
  689. ----
  690. 3
  691. query R
  692. SELECT list_length_max(LIST [1, 2, 3, 4], 1)
  693. ----
  694. 4
  695. query R
  696. SELECT list_length_max(LIST[[1],[2,3]], 2)
  697. ----
  698. 2
  699. query R
  700. SELECT list_length_max(LIST [[[1, 2, 3], [4]], [[5]]], 2)
  701. ----
  702. 2
  703. query R
  704. SELECT list_length_max(LIST [[[1, 2, 3], [4]], [[5]]], 3)
  705. ----
  706. 3
  707. query R
  708. SELECT list_length_max(LIST []::INT LIST, 1)
  709. ----
  710. 0
  711. query R
  712. SELECT list_length_max(LIST [[]]::INT LIST LIST, 2)
  713. ----
  714. 0
  715. # 🔬🔬🔬 slices
  716. query R
  717. SELECT list_length_max(LIST[[1], [2]][1:1], 1)
  718. ----
  719. 1
  720. query R
  721. SELECT list_length_max(LIST[[1], [2, 3]][2:2], 2)
  722. ----
  723. 2
  724. query R
  725. SELECT list_length_max(LIST [[[1, 2, 3], [4]], [[5]]][1:2], 1)
  726. ----
  727. 2
  728. query R
  729. SELECT list_length_max(LIST [[[1, 2, 3], [4]], [[5]]][1:1], 2)
  730. ----
  731. 2
  732. query R
  733. SELECT list_length_max(LIST [[[1, 2, 3], [4]], [[5]]][1:1], 3)
  734. ----
  735. 3
  736. # 🔬🔬🔬 indexing operations
  737. query R
  738. SELECT list_length_max(LIST[[1], [2, 3]][2], 1)
  739. ----
  740. 2
  741. query R
  742. SELECT list_length_max(LIST [[[1, 2, 3], [4]], [[5]]][1], 1)
  743. ----
  744. 2
  745. query R
  746. SELECT list_length_max(LIST [[[1, 2, 3], [4]], [[5]]][1], 2)
  747. ----
  748. 3
  749. query R
  750. SELECT list_length_max(LIST [[[1, 2, 3], [4]], [[5]]][1][2], 1)
  751. ----
  752. 1
  753. # 🔬🔬🔬 NULL elements
  754. query R
  755. SELECT list_length_max(NULL::INT LIST, 1)
  756. ----
  757. NULL
  758. query R
  759. SELECT list_length_max(LIST[1, NULL, 3]::INT LIST, 1)
  760. ----
  761. 3
  762. query R
  763. SELECT list_length_max(LIST[[1],NULL]::INT LIST LIST, 1)
  764. ----
  765. 2
  766. query R
  767. SELECT list_length_max((LIST[[1],NULL]::INT LIST LIST), 2)
  768. ----
  769. 1
  770. query T
  771. SELECT (list_length_max((LIST[NULL]::INT LIST LIST), 2))::text
  772. ----
  773. NULL
  774. # 🔬🔬🔬 errors
  775. query error invalid layer: 2; must use value within \[1, 1\]
  776. SELECT list_length_max((LIST[1]::INT LIST), 2)
  777. query error invalid layer: 2; must use value within \[1, 1\]
  778. SELECT list_length_max((LIST[NULL]::INT LIST), 2)
  779. query error invalid layer: 3; must use value within \[1, 2\]
  780. SELECT list_length_max((LIST[NULL]::INT LIST LIST), 3)
  781. query error invalid layer: 0; must use value within \[1, 1\]
  782. SELECT list_length_max((LIST[1]::INT LIST), 0)
  783. query error invalid layer: -1; must use value within \[1, 1\]
  784. SELECT list_length_max((LIST[1]::INT LIST), -1)
  785. query error invalid layer: -1; must use value within \[1, 1\]
  786. SELECT list_length_max((LIST[1]::INT LIST), LIST[-1][1])
  787. query error could not determine polymorphic type because input has type unknown
  788. SELECT list_length_max(NULL, 1)
  789. # 🔬🔬 list_prepend
  790. # 🔬🔬🔬 element + list
  791. query T
  792. SELECT (list_prepend(1, LIST[2, 3]))::text
  793. ----
  794. {1,2,3}
  795. # 🔬🔬🔬 list + list list (element + list)
  796. query T
  797. SELECT (list_prepend(LIST[1], LIST[[2], [3]]))::text
  798. ----
  799. {{1},{2},{3}}
  800. # 🔬🔬🔬🔬 polymorphism
  801. query T
  802. SELECT pg_typeof(list_prepend(1::int2, LIST[1::int8]))
  803. ----
  804. bigint list
  805. query T
  806. SELECT pg_typeof(list_prepend(1::int8, LIST[1::int2]))
  807. ----
  808. bigint list
  809. # 🔬🔬🔬 NULL elements
  810. # 🔬🔬🔬🔬 element + list
  811. query T
  812. SELECT (list_prepend(NULL, LIST[1]))::text
  813. ----
  814. {NULL,1}
  815. query T
  816. SELECT (list_prepend(NULL::INT, LIST[1]))::text
  817. ----
  818. {NULL,1}
  819. query T
  820. SELECT (list_prepend(1, NULL::INT LIST))::text
  821. ----
  822. {1}
  823. query T
  824. SELECT (list_prepend(NULL::INT, NULL::INT LIST))::text
  825. ----
  826. {NULL}
  827. # 🔬🔬🔬🔬 list + list list (element + list)
  828. query T
  829. SELECT (list_prepend(NULL, LIST[[1]]))::text
  830. ----
  831. {NULL,{1}}
  832. query T
  833. SELECT (list_prepend(LIST[1], NULL))::text
  834. ----
  835. {{1}}
  836. query T
  837. SELECT (list_prepend(NULL::INT LIST, NULL))::text
  838. ----
  839. {NULL}
  840. query T
  841. SELECT (list_prepend(NULL, NULL::INT LIST LIST))::text
  842. ----
  843. {NULL}
  844. # 🔬🔬🔬 errors
  845. query error
  846. SELECT list_prepend(NULL, NULL)
  847. query error
  848. SELECT list_prepend('a', LIST[1])
  849. query error
  850. SELECT list_prepend(LIST[1], LIST[2])
  851. query error
  852. SELECT list_prepend(LIST[1], 1)
  853. # 🔬🔬 unnest
  854. query I rowsort
  855. SELECT unnest FROM unnest(LIST[1,2,3])
  856. ----
  857. 1
  858. 2
  859. 3
  860. query T rowsort
  861. SELECT unnest::text FROM unnest(LIST[[1,2],[3]])
  862. ----
  863. {1,2}
  864. {3}
  865. query T
  866. SELECT unnest::text FROM unnest(LIST[NULL])
  867. ----
  868. NULL
  869. query I rowsort
  870. SELECT unnest FROM unnest(LIST[NULL,1])
  871. ----
  872. NULL
  873. 1
  874. query T
  875. SELECT unnest::text FROM unnest(NULL::int list)
  876. ----
  877. query error db error: ERROR: function unnest\(unknown\) is not unique
  878. SELECT * FROM unnest(NULL)
  879. # 🔬 List casts
  880. # 🔬🔬 Between lists
  881. # 🔬🔬🔬 Unlayered lists
  882. query T
  883. SELECT (LIST['1']::int list)::text
  884. ----
  885. {1}
  886. query T
  887. SELECT (LIST[NULL]::int list)::text
  888. ----
  889. {NULL}
  890. query T
  891. SELECT (LIST[NULL, '1']::int list)::text
  892. ----
  893. {NULL,1}
  894. query T
  895. SELECT (LIST[1.4, 1.5]::int list)::text
  896. ----
  897. {1,2}
  898. query T
  899. SELECT (LIST[1.4::float, -1.5::float]::int list)::text
  900. ----
  901. {1,-2}
  902. query T
  903. SELECT (NULL::int list)::text
  904. ----
  905. NULL
  906. # 🔬🔬🔬🔬 Errors
  907. query error invalid input syntax for type integer: invalid digit found in string: "dog"
  908. SELECT (LIST['1', 'dog']::int list)::text
  909. query error LIST could not convert type date to integer
  910. SELECT LIST[DATE '2008-02-01']::int list
  911. # 🔬🔬🔬 Layered and jagged lists
  912. query T
  913. SELECT (LIST[[1.4::float], [-1.5::float, 2.5::float]]::int list list)::text
  914. ----
  915. {{1},{-2,2}}
  916. query T
  917. SELECT (LIST[[1.4::float], [-1.5::float, 2.5::float], NULL::float list]::int list list)::text
  918. ----
  919. {{1},{-2,2},NULL}
  920. # 🔬🔬🔬 Non-numeric types
  921. query T
  922. SELECT (LIST[TIMESTAMP '2008-02-01 15:04:05', TIMESTAMP '2007-02-01 15:04:05']::date list)::text
  923. ----
  924. {2008-02-01,2007-02-01}
  925. query T
  926. SELECT (LIST[DATE '2008-02-01', DATE '2007-02-01']::timestamp list)::text
  927. ----
  928. {"2008-02-01 00:00:00","2007-02-01 00:00:00"}
  929. # 🔬🔬 list to text
  930. query T
  931. SELECT (LIST['1']::text)::text
  932. ----
  933. {1}
  934. query T
  935. SELECT (LIST[NULL]::text)::text
  936. ----
  937. {NULL}
  938. query T
  939. SELECT (LIST[NULL, '1']::text)::text
  940. ----
  941. {NULL,1}
  942. query T
  943. SELECT (LIST[NULL, 1]::text)::text
  944. ----
  945. {NULL,1}
  946. query T
  947. SELECT (LIST[NULL, '1']::text)::text
  948. ----
  949. {NULL,1}
  950. query T
  951. SELECT (LIST[NULL, 1]::text)::text
  952. ----
  953. {NULL,1}
  954. query T
  955. SELECT (LIST[1.4, -1.5]::text)::text
  956. ----
  957. {1.4,-1.5}
  958. query T
  959. SELECT (LIST[[1.4], [-1.5]]::text)::text
  960. ----
  961. {{1.4},{-1.5}}
  962. query T
  963. SELECT (LIST[[1.4::float], [-1.5::float, 2.5::float]]::text)::text
  964. ----
  965. {{1.4},{-1.5,2.5}}
  966. # Show that these are actually strings
  967. query I
  968. SELECT length(LIST['1','2']::text)
  969. ----
  970. 5
  971. query error db error: ERROR: function length\(text list\) does not exist
  972. SELECT length(LIST['1','2'])
  973. # 🔬🔬 text to list
  974. # 🔬🔬🔬 text to int list
  975. query I
  976. SELECT * FROM unnest('{1,2,3}'::int list)
  977. ----
  978. 1
  979. 2
  980. 3
  981. query T rowsort
  982. SELECT unnest::text FROM unnest('{{1,2},{3}}'::int list list)
  983. ----
  984. {1,2}
  985. {3}
  986. query T rowsort
  987. SELECT unnest::text FROM unnest('{{{1},{2}},{{3}}}'::int list list list)
  988. ----
  989. {{1},{2}}
  990. {{3}}
  991. query T
  992. SELECT ('{NULL}'::int list)::text
  993. ----
  994. {NULL}
  995. query T
  996. SELECT ('{}'::int list)::text
  997. ----
  998. {}
  999. # 🔬🔬🔬 text to text list
  1000. query T
  1001. SELECT ('{"a"," b","c ", d,e }'::text list)::text
  1002. ----
  1003. {a," b","c ",d,e}
  1004. query T
  1005. SELECT ('{{"a"," b","c "},{ d,e }}'::text list list)::text
  1006. ----
  1007. {{a," b","c "},{d,e}}
  1008. # NULL-esque string handling
  1009. query TI rowsort
  1010. SELECT unnest, length(unnest) from unnest('{NULL,nUlL,"NULL"}'::text list) ORDER BY length
  1011. ----
  1012. NULL 4
  1013. NULL NULL
  1014. NULL NULL
  1015. # Test some escape values
  1016. query TI rowsort
  1017. SELECT unnest, length(unnest) from unnest('{"a,b","\\","a\\b\"c\\d\""}'::text list) ORDER BY length
  1018. ----
  1019. \ 1
  1020. a,b 3
  1021. a\b"c\d" 8
  1022. query T
  1023. SELECT ('{NULL}'::text list)::text
  1024. ----
  1025. {NULL}
  1026. query T
  1027. SELECT ('{}'::text list)::text
  1028. ----
  1029. {}
  1030. # 🔬🔬🔬🔬 Quote escapes
  1031. # Preserves leading and trailing spaces within escape, but not outside of escape
  1032. query T
  1033. SELECT ('{ " a " }'::text list)::text
  1034. ----
  1035. {" a "}
  1036. # Escapes content
  1037. query T
  1038. SELECT ('{"} \""}'::text list)::text
  1039. ----
  1040. {"} \""}
  1041. query T
  1042. SELECT ('{"{a}"}'::text list)::text
  1043. ----
  1044. {"{a}"}
  1045. query T
  1046. SELECT ('{"",""}'::text list)::text
  1047. ----
  1048. {"",""}
  1049. # This demos that the double quotes from the input are actually stripped
  1050. query TI
  1051. SELECT unnest, length(unnest) FROM unnest('{"",""}'::text list)
  1052. ----
  1053. (empty) 0
  1054. (empty) 0
  1055. # Mixture of escape and non-escaped elements
  1056. query T
  1057. SELECT ('{"{",a}'::text list)::text
  1058. ----
  1059. {"{",a}
  1060. # Escape gets reset after each element
  1061. query T
  1062. SELECT ('{"{",\\}'::text list)::text
  1063. ----
  1064. {"{","\\"}
  1065. # Elements within double quotes gets unescaped before being cast
  1066. query T
  1067. SELECT ('{{a, "", "\""}, "{a, \"\", \"\\\"\"}"}'::text list list)::text
  1068. ----
  1069. {{a,"","\""},{a,"","\""}}
  1070. # Unquoted elements cannot have special characters interleaved within them
  1071. query error invalid input syntax for type list: malformed literal; must escape special character '"'
  1072. SELECT ('{a"b"}'::text list)::text
  1073. query error invalid input syntax for type list: malformed literal; must escape special character '\{'
  1074. SELECT ('{a{b}'::text list)::text
  1075. query error invalid input syntax for type list: malformed array literal; contains 'b' after terminal '\}'
  1076. SELECT ('{a}b}'::text list)::text
  1077. # No non-whitespace characters after the escape
  1078. query error invalid input syntax for type list: expected ',' or '\}', got 'b'
  1079. SELECT ('{"a"b}'::text list)::text
  1080. query error invalid input syntax for type list: expected ',' or '\}', got '"'
  1081. SELECT ('{""""}'::text list)::text
  1082. query error invalid input syntax for type list: expected ',' or '\}', got '"'
  1083. SELECT ('{"""}'::text list)::text
  1084. # 🔬🔬🔬🔬 Unquoted escapes
  1085. # Escapes work on special characters
  1086. query T
  1087. SELECT ('{\{, \}, \", \,}'::text list)::text
  1088. ----
  1089. {"{","}","\"",","}
  1090. # Preserves escaped white space
  1091. query T
  1092. SELECT ('{\ a}'::text list)::text
  1093. ----
  1094. {" a"}
  1095. query T
  1096. SELECT ('{a \ }'::text list)::text
  1097. ----
  1098. {"a "}
  1099. query T
  1100. SELECT ('{\ a \ }'::text list)::text
  1101. ----
  1102. {" a "}
  1103. query T
  1104. SELECT ('{a \ \ }'::text list)::text
  1105. ----
  1106. {"a "}
  1107. # list lists are only escaped once; if they were escaped at each level, they
  1108. # would no longer escape leading or trailing whitespace
  1109. query T
  1110. SELECT ('{{\ a}}'::text list list)::text
  1111. ----
  1112. {{" a"}}
  1113. query T
  1114. SELECT ('{{a \ }}'::text list list)::text
  1115. ----
  1116. {{"a "}}
  1117. query T
  1118. SELECT ('{{\ a \ }}'::text list list)::text
  1119. ----
  1120. {{" a "}}
  1121. query T
  1122. SELECT ('{{a \ \ }}'::text list list)::text
  1123. ----
  1124. {{"a "}}
  1125. # Unescaped space is trimmed
  1126. query T
  1127. SELECT ('{\ \ a , b \ }'::text list)::text
  1128. ----
  1129. {" a","b "}
  1130. query T
  1131. SELECT ('{ a \ \ , \ b }'::text list)::text
  1132. ----
  1133. {"a "," b"}
  1134. query T
  1135. SELECT ('{a \ \ , \ b }'::text list)::text
  1136. ----
  1137. {"a "," b"}
  1138. query T
  1139. SELECT ('{ { a \ } }'::text list list)::text
  1140. ----
  1141. {{"a "}}
  1142. query T
  1143. SELECT ('{ {a \ } }'::text list list)::text
  1144. ----
  1145. {{"a "}}
  1146. query T
  1147. SELECT ('{ \ a}'::text list)::text
  1148. ----
  1149. {" a"}
  1150. # Leading/trailing escaped special characters are honored
  1151. query T
  1152. SELECT ('{\"a\"}'::text list)::text
  1153. ----
  1154. {"\"a\""}
  1155. query T
  1156. SELECT ('{\{a\}}'::text list)::text
  1157. ----
  1158. {"{a}"}
  1159. # Escaping backslashes works
  1160. query T
  1161. SELECT ('{ \\\\a\\\\ }'::text list)::text
  1162. ----
  1163. {"\\\\a\\\\"}
  1164. # Escaping a non-special character has no visible effect on the output; normal
  1165. # whitespacing rules apply
  1166. query T
  1167. SELECT ('{ \a }'::text list)::text
  1168. ----
  1169. {a}
  1170. # Escaping a character in NULL turns it into the string "NULL"
  1171. query T
  1172. SELECT ('{N\ULL}'::text list)::text
  1173. ----
  1174. {"NULL"}
  1175. # Escaping terminal character means it isn't available to close the list
  1176. query error invalid input syntax for type list: unterminated element
  1177. SELECT ('{\}'::text list)::text
  1178. query error invalid input syntax for type list: unexpected end of input
  1179. SELECT ('{{\}}'::text list list)::text
  1180. # 🔬🔬🔬 text to other lists
  1181. query T
  1182. SELECT ('{1y 2d 3h, "4y 5d 6h"}'::interval list)::text
  1183. ----
  1184. {"1 year 2 days 03:00:00","4 years 5 days 06:00:00"}
  1185. query T
  1186. SELECT ('{2001-02-03, "2004-05-06"}'::date list)::text
  1187. ----
  1188. {2001-02-03,2004-05-06}
  1189. query T
  1190. SELECT ('{NULL}'::date list)::text
  1191. ----
  1192. {NULL}
  1193. # 🔬🔬🔬 misc. checks
  1194. # Elements within double quotes have their double quotes before being cast to
  1195. # their element type
  1196. query T
  1197. SELECT ('{"1"}'::int list)::text
  1198. ----
  1199. {1}
  1200. query T
  1201. SELECT ('{"1"}'::text list)::text
  1202. ----
  1203. {1}
  1204. query T
  1205. SELECT ('{"{}"}'::int list list)::text
  1206. ----
  1207. {{}}
  1208. query T
  1209. SELECT ('{"{}"}'::text list list)::text
  1210. ----
  1211. {{}}
  1212. # Empty lists
  1213. query T
  1214. SELECT ('{ }'::text list)::text
  1215. ----
  1216. {}
  1217. query T
  1218. SELECT ('{ { } }'::text list list)::text
  1219. ----
  1220. {{}}
  1221. # 🔬🔬🔬 errors
  1222. # Empty string is invalid
  1223. query error invalid input syntax for type list: expected '\{', found empty string: ""
  1224. SELECT (''::text list)::text
  1225. # Not a list
  1226. query error invalid input syntax for type list: expected '\{', found 1: "1"
  1227. SELECT ('1'::int list)::text
  1228. # Invalid element
  1229. query error invalid input syntax for type list: invalid input syntax for type integer: invalid digit found in string: "a": "\{a\}"
  1230. SELECT ('{a}'::int list)::text
  1231. # 'NULL' isn't a valid string for a list; just use unescaped NULL
  1232. query error invalid input syntax for type list: expected '\{', found N: "NULL"
  1233. SELECT ('NULL'::int list)::text
  1234. # Too many leading brackets
  1235. query error invalid input syntax for type list: unescaped '\{' at beginning of element
  1236. SELECT ('{{1}}'::int list)::text
  1237. # Too many leading brackets
  1238. query error invalid input syntax for type list: unescaped '\{' at beginning of element
  1239. SELECT ('{{1}'::int list)::text
  1240. query error invalid input syntax for type list: unexpected end of input: "\{\{1\}"
  1241. SELECT ('{{1}'::int list list)::text
  1242. # Too many following brackets
  1243. query error invalid input syntax for type list: malformed array literal; contains '\}' after terminal '\}': "\{1\}\}"
  1244. SELECT ('{1}}'::int list)::text
  1245. query error invalid input syntax for type list: invalid input syntax for type list: expected '\{', found 1: "1": "\{1\}\}"
  1246. SELECT ('{1}}'::int list list)::text
  1247. # Cannot have commas followed or preceded by empty elements
  1248. query error invalid input syntax for type list: malformed literal; missing element: "\{a, \}"
  1249. SELECT ('{a, }'::text list)::text
  1250. query error invalid input syntax for type list: malformed literal; missing element: "\{ ,a\}"
  1251. SELECT ('{ ,a}'::text list)::text
  1252. # 🔬🔬🔬🔬 homogeneous text lists
  1253. query error char list not yet supported
  1254. SELECT (LIST['ab'::char, 'cd'::varchar, 'ef'::text])::text
  1255. query T
  1256. SELECT (LIST['cd'::varchar, 'ef'::text])::text
  1257. ----
  1258. {cd,ef}
  1259. # 🔬🔬 char lists
  1260. # ensures that the list type does not pick up an elements' typmod
  1261. query error char list not yet supported
  1262. SELECT LIST['abc'::char(1), 'abc'::char(2), 'abc'::char(3)]::text;
  1263. query error char list not yet supported
  1264. SELECT LIST['abc'::char(3), 'abc'::char(2), 'abc'::char(1)]::text;
  1265. query error char list not yet supported
  1266. SELECT pg_typeof(LIST['abc'::char(1), 'abc'::char(2), 'abc'::char(3)]);
  1267. # 🔬🔬 varchar lists
  1268. # ensures that the list type does not pick up an elements' typmod
  1269. query T
  1270. SELECT LIST['abc'::varchar(1), 'abc'::varchar(2), 'abc'::varchar(3)]::text;
  1271. ----
  1272. {a,ab,abc}
  1273. query T
  1274. SELECT LIST['abc'::varchar(3), 'abc'::varchar(2), 'abc'::varchar(1)]::text;
  1275. ----
  1276. {abc,ab,a}
  1277. query T
  1278. SELECT pg_typeof(LIST['abc'::varchar(1), 'abc'::varchar(2), 'abc'::varchar(3)]);
  1279. ----
  1280. character varying list
  1281. # 🔬 Built-in operations
  1282. # 🔬🔬 concatenation (||)
  1283. # 🔬🔬🔬 list + list
  1284. query T
  1285. SELECT (LIST[1, 2] || LIST[3, 4])::text
  1286. ----
  1287. {1,2,3,4}
  1288. query T
  1289. SELECT (LIST[[1], [2]] || LIST[[3], [4]])::text
  1290. ----
  1291. {{1},{2},{3},{4}}
  1292. # Concatenation properly casts text to appropriate list type
  1293. query T
  1294. SELECT (LIST[1] || '{2}')::text
  1295. ----
  1296. {1,2}
  1297. # Differently scaled numerics are implicitly castable to one another
  1298. query T
  1299. SELECT ('{1.2}'::numeric(38,5) list || '{2.3}'::numeric(38,0) list)::text;
  1300. ----
  1301. {1.2,2}
  1302. # ...including on multiple layers
  1303. query T
  1304. SELECT ('{{1.2}}'::numeric(38,5) list list || '{{2.3}}'::numeric(38,0) list list)::text;
  1305. ----
  1306. {{1.2},{2}}
  1307. # Determining common list element type for numerics does not rescale values
  1308. query T
  1309. SELECT LIST[1.234::numeric(39,2), 2.345]::text;
  1310. ----
  1311. {1.23,2.345}
  1312. query T
  1313. SELECT LIST[1.234::numeric(39,2), 2.345]::numeric(39, 2) list::text;
  1314. ----
  1315. {1.23,2.35}
  1316. # 🔬🔬🔬🔬 polymorphic
  1317. query T
  1318. SELECT pg_typeof(LIST[1::int2] || LIST[2::int8])
  1319. ----
  1320. bigint list
  1321. query T
  1322. SELECT pg_typeof(LIST[1::int8] || LIST[2::int2])
  1323. ----
  1324. bigint list
  1325. # 🔬🔬🔬 list + element
  1326. query T
  1327. SELECT (LIST[1, 2] || 3)::text
  1328. ----
  1329. {1,2,3}
  1330. query T
  1331. SELECT ('{1.2}'::numeric(38,5) list || '2.3'::numeric(38,0))::text;
  1332. ----
  1333. {1.2,2}
  1334. # 🔬🔬🔬🔬 polymorphic
  1335. query T
  1336. SELECT pg_typeof(LIST[1::int2] || 2::int8)
  1337. ----
  1338. bigint list
  1339. query T
  1340. SELECT pg_typeof(LIST[1::int8] || 2::int2)
  1341. ----
  1342. bigint list
  1343. # 🔬🔬🔬 element + list
  1344. query T
  1345. SELECT (1 || LIST[2, 3])::text
  1346. ----
  1347. {1,2,3}
  1348. query T
  1349. SELECT ('1.2'::numeric(38,5) || '{2.3}'::numeric(38,0) list)::text;
  1350. ----
  1351. {1.2,2}
  1352. # 🔬🔬🔬🔬 polymorphic
  1353. query T
  1354. SELECT pg_typeof(1::int2 || LIST[2::int8])
  1355. ----
  1356. bigint list
  1357. query T
  1358. SELECT pg_typeof(1::int8 || LIST[2::int2])
  1359. ----
  1360. bigint list
  1361. # 🔬🔬🔬 list list + list (list + element)
  1362. query T
  1363. SELECT (LIST[[1], [2]] || LIST[3])::text
  1364. ----
  1365. {{1},{2},{3}}
  1366. query T
  1367. SELECT ('{{1.2}}'::numeric(38,5) list list || '{2.3}'::numeric(38,0) list)::text;
  1368. ----
  1369. {{1.2},{2}}
  1370. # 🔬🔬🔬 list + list list (element + list)
  1371. query T
  1372. SELECT (LIST[1] || LIST[[2], [3]])::text
  1373. ----
  1374. {{1},{2},{3}}
  1375. query T
  1376. SELECT ('{1.2}'::numeric(38,5) list || '{{2.3}}'::numeric(38,0) list list)::text;
  1377. ----
  1378. {{1.2},{2}}
  1379. # 🔬🔬🔬 NULL elements
  1380. # 🔬🔬🔬🔬 list + list
  1381. # Our type system resolves `list || NULL` as a form of `list || list`
  1382. query T
  1383. SELECT (LIST[1] || NULL)::text
  1384. ----
  1385. {1}
  1386. query T
  1387. SELECT (NULL || LIST[1])::text
  1388. ----
  1389. {1}
  1390. query T
  1391. SELECT (LIST[1] || NULL::INT LIST)::text
  1392. ----
  1393. {1}
  1394. query T
  1395. SELECT ( NULL::INT LIST || LIST[1])::text
  1396. ----
  1397. {1}
  1398. query T
  1399. SELECT (NULL::INT LIST || NULL::INT LIST)::text
  1400. ----
  1401. NULL
  1402. # 🔬🔬🔬🔬 list + element
  1403. query T
  1404. SELECT (LIST[1] || NULL::INT)::text
  1405. ----
  1406. {1,NULL}
  1407. query T
  1408. SELECT (NULL::INT LIST || 1)::text
  1409. ----
  1410. {1}
  1411. query T
  1412. SELECT (NULL::INT LIST || NULL::INT)::text
  1413. ----
  1414. {NULL}
  1415. # 🔬🔬🔬🔬 element + list
  1416. query T
  1417. SELECT (NULL::INT || LIST[1])::text
  1418. ----
  1419. {NULL,1}
  1420. query T
  1421. SELECT (1 || NULL::INT LIST)::text
  1422. ----
  1423. {1}
  1424. query T
  1425. SELECT (NULL::INT || NULL::INT LIST)::text
  1426. ----
  1427. {NULL}
  1428. # 🔬🔬🔬🔬 list list + list (list + element)
  1429. query T
  1430. SELECT (LIST[[1]] || NULL::INT LIST)::text
  1431. ----
  1432. {{1},NULL}
  1433. query T
  1434. SELECT (NULL::INT LIST LIST || LIST[1])::text
  1435. ----
  1436. {{1}}
  1437. query T
  1438. SELECT (NULL::INT LIST LIST || NULL::INT LIST)::text
  1439. ----
  1440. {NULL}
  1441. # 🔬🔬🔬🔬 list + list list (element + list)
  1442. query T
  1443. SELECT (NULL::INT LIST || LIST[[1]])::text
  1444. ----
  1445. {NULL,{1}}
  1446. query T
  1447. SELECT (LIST[1] || NULL::INT LIST LIST)::text
  1448. ----
  1449. {{1}}
  1450. query T
  1451. SELECT (NULL::INT LIST || NULL::INT LIST LIST)::text
  1452. ----
  1453. {NULL}
  1454. # 🔬🔬🔬 errors
  1455. query error no overload for int4 list || unknown: Cannot concatenate int4 list and string list
  1456. SELECT LIST[1] || LIST['a']
  1457. query error no overload for int4 list || unknown: Cannot concatenate int4 list and string
  1458. SELECT LIST[1] || 'a'
  1459. query error no overload for unknown || int4 list: Cannot concatenate string list and int4 list
  1460. SELECT LIST[NULL] || LIST[1]
  1461. query error no overload for unknown || int4 list: Cannot concatenate string list list and int4 list
  1462. SELECT LIST[[NULL]] || LIST[1]
  1463. query error no overload for int4 list list list || int4 list: Cannot concatenate int4 list list list and int4 list
  1464. SELECT LIST[[[1]]] || LIST[2]
  1465. # Literal text cannot be implicitly cast to list
  1466. query error no overload for int4 list || string: arguments cannot be implicitly cast to any implementation's parameters; try providing explicit casts
  1467. SELECT LIST[1] || '{2}'::text
  1468. # Two lists containing implicitly castable element types are not implicitly castable to one another
  1469. query error no overload for f32 list || f64 list: arguments cannot be implicitly cast to any implementation's parameters; try providing explicit casts
  1470. SELECT '{1}'::float4 list || '{2}'::float8 list
  1471. # 🔬🔬 equality (=)
  1472. # 🔬🔬🔬 list = list
  1473. query T
  1474. SELECT LIST[1, 2] = LIST[1, 2]
  1475. ----
  1476. true
  1477. query T
  1478. SELECT LIST[1, 2] = LIST[1, 3]
  1479. ----
  1480. false
  1481. query T
  1482. SELECT LIST[[1], [2]] = LIST[[1], [2]]
  1483. ----
  1484. true
  1485. query T
  1486. SELECT LIST[[1], [2]] = LIST[[1], [3]]
  1487. ----
  1488. false
  1489. # Equality properly casts text to appropriate list type
  1490. query T
  1491. SELECT LIST[1] = '{1}'
  1492. ----
  1493. true
  1494. query T
  1495. SELECT LIST[1] = '{2}'
  1496. ----
  1497. false
  1498. # 🔬🔬🔬 errors
  1499. query error db error: ERROR: operator does not exist: integer list = text list
  1500. SELECT LIST[1] = LIST['a']
  1501. query error db error: ERROR: operator does not exist: text list = integer list
  1502. SELECT LIST[NULL] = LIST[1]
  1503. query error db error: ERROR: operator does not exist: text list list = integer list
  1504. SELECT LIST[[NULL]] = LIST[1]
  1505. query error db error: ERROR: operator does not exist: integer list list list = integer list
  1506. SELECT LIST[[[1]]] = LIST[2]
  1507. # Literal text cannot be implicitly cast to list
  1508. query error db error: ERROR: operator does not exist: integer list = text
  1509. SELECT LIST[1] = '{2}'::text
  1510. # Two lists containing implicitly castable element types are not implicitly castable to one another
  1511. query error db error: ERROR: operator does not exist: real list = double precision list
  1512. SELECT '{1}'::float4 list = '{2}'::float8 list
  1513. # 🔬 CREATE TYPE .. AS LIST
  1514. query error type "pg_enum" does not exist
  1515. CREATE TYPE tbl_list AS LIST (ELEMENT TYPE=pg_enum)
  1516. query error CREATE TYPE ... AS LIST option ELEMENT TYPE can only use named data types, but found unnamed data type pg_catalog.int4 list. Use CREATE TYPE to create a named type first
  1517. CREATE TYPE unnamed_element_list AS LIST (ELEMENT TYPE=int4 list)
  1518. statement ok
  1519. CREATE TYPE int4_list_c AS LIST (ELEMENT TYPE = int4);
  1520. query T
  1521. SELECT '{1,2}'::int4_list_c::text;
  1522. ----
  1523. {1,2}
  1524. query T
  1525. SELECT oid >= 20000 FROM pg_type WHERE typname = 'int4_list_c';
  1526. ----
  1527. true
  1528. query T
  1529. SELECT '{{1,2}}'::int4_list_c list::text
  1530. ----
  1531. {{1,2}}
  1532. query T
  1533. SELECT pg_typeof(NULL::int4_list_c);
  1534. ----
  1535. int4_list_c
  1536. statement ok
  1537. CREATE TYPE int4_list_list_c AS LIST (ELEMENT TYPE = int4_list_c);
  1538. query T
  1539. SELECT '{{1,2}}'::int4_list_list_c::text;
  1540. ----
  1541. {{1,2}}
  1542. query error type "bool list" does not exist
  1543. CREATE TYPE nested_list AS LIST (ELEMENT TYPE = "bool list")
  1544. query error db error: ERROR: cannot reference pseudo type mz_catalog\.list
  1545. CREATE TYPE nested_list AS LIST (ELEMENT TYPE = list)
  1546. # 🔬🔬 Check each valid non-array element type
  1547. statement ok
  1548. CREATE TYPE bool_list_c AS LIST (ELEMENT TYPE=bool);
  1549. query T
  1550. SELECT '{true}'::bool_list_c::text
  1551. ----
  1552. {t}
  1553. statement ok
  1554. CREATE TYPE int8_list_c AS LIST (ELEMENT TYPE=int8);
  1555. query T
  1556. SELECT '{1,2}'::int8_list_c::text
  1557. ----
  1558. {1,2}
  1559. query T
  1560. SELECT '{1,2}'::int4_list_c::text
  1561. ----
  1562. {1,2}
  1563. statement ok
  1564. CREATE TYPE text_list_c AS LIST (ELEMENT TYPE=text);
  1565. query T
  1566. SELECT '{a,b}'::text_list_c::text
  1567. ----
  1568. {a,b}
  1569. statement ok
  1570. CREATE TYPE float4_list_c AS LIST (ELEMENT TYPE=float4);
  1571. query T
  1572. SELECT '{1.2,2.3}'::float4_list_c::text
  1573. ----
  1574. {1.2,2.3}
  1575. statement ok
  1576. CREATE TYPE float8_list_c AS LIST (ELEMENT TYPE=float8);
  1577. query T
  1578. SELECT '{1.2,2.3}'::float8_list_c::text
  1579. ----
  1580. {1.2,2.3}
  1581. statement ok
  1582. CREATE TYPE date_list_c AS LIST (ELEMENT TYPE=date);
  1583. query T
  1584. SELECT '{2001-01-01}'::date_list_c::text
  1585. ----
  1586. {2001-01-01}
  1587. statement ok
  1588. CREATE TYPE time_list_c AS LIST (ELEMENT TYPE=time);
  1589. query T
  1590. SELECT '{12:34:56}'::time_list_c::text
  1591. ----
  1592. {12:34:56}
  1593. statement ok
  1594. CREATE TYPE timestamp_list_c AS LIST (ELEMENT TYPE=timestamp);
  1595. query T
  1596. SELECT '{2001-01-01 12:34:56}'::timestamp_list_c::text
  1597. ----
  1598. {"2001-01-01 12:34:56"}
  1599. statement ok
  1600. CREATE TYPE timestamptz_list_c AS LIST (ELEMENT TYPE=timestamptz);
  1601. query T
  1602. SELECT '{2001-01-01 12:34:56}'::timestamptz_list_c::text
  1603. ----
  1604. {"2001-01-01 12:34:56+00"}
  1605. statement ok
  1606. CREATE TYPE interval_list_c AS LIST (ELEMENT TYPE=interval);
  1607. query T
  1608. SELECT '{1y 2d 3h 4m}'::interval_list_c::text
  1609. ----
  1610. {"1 year 2 days 03:04:00"}
  1611. statement ok
  1612. CREATE TYPE numeric_list_c AS LIST (ELEMENT TYPE=numeric);
  1613. query T
  1614. SELECT '{1.23,2.34}'::numeric_list_c::text
  1615. ----
  1616. {1.23,2.34}
  1617. statement ok
  1618. CREATE TYPE jsonb_list_c AS LIST (ELEMENT TYPE=jsonb);
  1619. query T
  1620. SELECT '{\{\"1\":2\}}'::jsonb_list_c::text;
  1621. ----
  1622. {"{\"1\":2}"}
  1623. # 🔬🔬 Check custom type name resolution
  1624. statement ok
  1625. CREATE TYPE bool AS LIST (ELEMENT TYPE=int4)
  1626. query error invalid input syntax for type boolean: "\{1,2\}"
  1627. SELECT '{1,2}'::bool;
  1628. query T
  1629. SELECT '{1,2}'::public.bool::text;
  1630. ----
  1631. {1,2}
  1632. # 🔬🔬 Check subtype resolution
  1633. # Supports qualified subtypes
  1634. statement ok
  1635. CREATE TYPE qualified_int4_list AS LIST (ELEMENT TYPE=pg_catalog.int4)
  1636. statement ok
  1637. CREATE TYPE qualified_qualified_int4_list AS LIST (ELEMENT TYPE=public.qualified_int4_list)
  1638. # Supports type aliases
  1639. statement ok
  1640. CREATE TYPE int_list AS MAP (KEY TYPE = pg_catalog.text, VALUE TYPE = int)
  1641. # 🔬🔬 Built-in operations
  1642. query T
  1643. SELECT ('{1}'::int4_list_c || 2)::text;
  1644. ----
  1645. {1,2}
  1646. query T
  1647. SELECT (1 || '{2}'::int4_list_c)::text;
  1648. ----
  1649. {1,2}
  1650. # 🔬 Explicit casts w/ custom types
  1651. query T
  1652. SELECT ('{1.2,2.3}'::numeric_list_c)::text;
  1653. ----
  1654. {1.2,2.3}
  1655. query T
  1656. SELECT ('{1.2,2.34567890}'::numeric_list_c::numeric(38,5) list)::text;
  1657. ----
  1658. {1.2,2.34568}
  1659. query T
  1660. SELECT ('{1.2,2.3}'::numeric(38,5) list::numeric_list_c)::text;
  1661. ----
  1662. {1.2,2.3}
  1663. # 🔬 Implicit casts between custom types
  1664. # 🔬🔬 1-D casts
  1665. statement ok
  1666. CREATE TYPE int4_list AS LIST (ELEMENT TYPE = int4)
  1667. statement ok
  1668. CREATE TYPE int4_list_too AS LIST (ELEMENT TYPE = int4)
  1669. query T
  1670. SELECT ('{1}'::int4_list || '{2}'::int list)::text;
  1671. ----
  1672. {1,2}
  1673. query error
  1674. SELECT '{1}'::int4_list || '{2}'::int4_list_too;
  1675. # Anonymous type cast to custom type, which is not interoperable with a
  1676. # different custom type
  1677. query error
  1678. SELECT '{1}'::int4_list || '{2}'::int list || '{3}'::int4_list_too
  1679. query T
  1680. SELECT ('{1}'::int4_list_too || '{2}'::int4_list::int4_list_too)::text;
  1681. ----
  1682. {1,2}
  1683. query T
  1684. SELECT ('{1}'::int4_list_too || '{2}'::int4_list::int list)::text;
  1685. ----
  1686. {1,2}
  1687. query T
  1688. SELECT ('{1}'::int4_list || 2)::text;
  1689. ----
  1690. {1,2}
  1691. # 🔬🔬 2-D casts
  1692. statement ok
  1693. CREATE TYPE int4_list_list AS LIST (ELEMENT TYPE = int4_list)
  1694. statement ok
  1695. CREATE TYPE int4_list_list_too AS LIST (ELEMENT TYPE = int4_list_too)
  1696. # Custom type interoperable with anonymous type
  1697. query T
  1698. SELECT ('{{1}}'::int4_list_list || '{{2}}'::int list list)::text;
  1699. ----
  1700. {{1},{2}}
  1701. # Other custom types cast to same custom type
  1702. query T
  1703. SELECT ('{{1}}'::int4_list_list_too || '{{2}}'::int4_list_list::int4_list_list_too)::text;
  1704. ----
  1705. {{1},{2}}
  1706. # Other custom type cast to anonymous type
  1707. query T
  1708. SELECT ('{{1}}'::int4_list_list_too || '{{2}}'::int4_list_list::int list list)::text;
  1709. ----
  1710. {{1},{2}}
  1711. # Different custom types
  1712. query error
  1713. SELECT '{{1}}'::int4_list_list || '{{2}}'::int4_list_list_too;
  1714. # Different custom types as element types
  1715. query error
  1716. SELECT '{{1}}'::int4_list list || '{{2}}'::int4_list_list_too list;
  1717. # Custom element type
  1718. query T
  1719. SELECT ('{{1}}'::int4_list_list || '{2}'::int4_list)::text;
  1720. ----
  1721. {{1},{2}}
  1722. # Anonymous element type
  1723. query T
  1724. SELECT ('{{1}}'::int4_list_list || '{2}'::int4 list)::text;
  1725. ----
  1726. {{1},{2}}
  1727. # Non-matching element type
  1728. query error
  1729. SELECT '{{1}}'::int4_list_list || '{2}'::int4_list_too;
  1730. query error
  1731. SELECT '{1}'::int4_list_too || '{{2}}'::int4_list_list
  1732. # Element types match, but "head" type does not
  1733. query error
  1734. SELECT '{{1}}'::int4_list_list || '{{2}}'::int4_list list
  1735. query error
  1736. SELECT '{{1}}'::int4_list list || '{{2}}'::int4_list_list
  1737. # Custom element type w/ anonymous complex type
  1738. query T
  1739. SELECT ('{{1}}'::int4_list list || '{{2}}'::int4_list list)::text
  1740. ----
  1741. {{1},{2}}
  1742. # Custom element exactly matches
  1743. query T
  1744. SELECT ('{{1}}'::int4_list list || '{2}'::int4_list)::text
  1745. ----
  1746. {{1},{2}}
  1747. # Custom element + anonymous element
  1748. query T
  1749. SELECT ('{{1}}'::int4_list list || '{2}'::int4 list)::text
  1750. ----
  1751. {{1},{2}}
  1752. # list_agg
  1753. query T
  1754. SELECT list_agg(a)::text FROM (SELECT 1 AS a WHERE false)
  1755. ----
  1756. NULL
  1757. query T
  1758. SELECT list_agg(1)::text
  1759. ----
  1760. {1}
  1761. query T
  1762. select list_agg(unnest)::text FROM (SELECT NULL) x JOIN LATERAL unnest(ARRAY[1,2,NULL]) ON true;
  1763. ----
  1764. {1,2,NULL}
  1765. statement ok
  1766. CREATE TABLE t1 (a int)
  1767. statement ok
  1768. INSERT INTO t1 VALUES (1), (2), (3), (NULL), (NULL)
  1769. query T
  1770. SELECT list_agg(a)::text FROM (select a from t1 where a IS NOT NULL)
  1771. ----
  1772. {1,2,3}
  1773. query T
  1774. SELECT list_agg(a)::text FROM (select a from t1 where a IS NULL)
  1775. ----
  1776. {NULL,NULL}
  1777. query T
  1778. SELECT list_agg(a)::text FROM t1
  1779. ----
  1780. {1,2,3,NULL,NULL}
  1781. query T
  1782. SELECT list_agg(a::text)::text FROM t1
  1783. ----
  1784. {1,2,3,NULL,NULL}
  1785. query T
  1786. SELECT (list_agg(a) FILTER (WHERE a IS NOT NULL))::text FROM t1
  1787. ----
  1788. {1,2,3}
  1789. query T
  1790. SELECT (list_agg(a) FILTER (WHERE a IS NULL))::text FROM t1
  1791. ----
  1792. {NULL,NULL}
  1793. query error db error: ERROR: function list_agg\(integer, integer\) does not exist
  1794. SELECT list_agg(1, 2)
  1795. statement ok
  1796. CREATE TABLE t2 (a int, b date)
  1797. statement ok
  1798. INSERT INTO t2 VALUES (1, date '2020-01-01'), (NULL, date '2020-01-02')
  1799. query T
  1800. SELECT list_agg((a, b))::text FROM t2
  1801. ----
  1802. {"(1,2020-01-01)","(,2020-01-02)"}
  1803. query TTT
  1804. SELECT list_agg((a, b))::text, list_agg(a)::text, list_agg(b)::text FROM t2
  1805. ----
  1806. {"(1,2020-01-01)","(,2020-01-02)"} {1,NULL} {2020-01-01,2020-01-02}
  1807. query T
  1808. SELECT list_agg(ARRAY[1])::text
  1809. ----
  1810. {{1}}
  1811. query error list_agg on char
  1812. SELECT list_agg('a'::char)::text
  1813. query error list_agg on char
  1814. SELECT list_agg('a'::char(2))::text
  1815. query T
  1816. SELECT list_agg(a)::text FROM (VALUES ('{1,2}'::int list), ('{3}'), (NULL)) v(a);
  1817. ----
  1818. {{1,2},{3},NULL}
  1819. query T
  1820. SELECT list_agg(a)::text FROM (VALUES (array[1,2]), (array[3]), (NULL)) v(a);
  1821. ----
  1822. {{1,2},{3},NULL}
  1823. statement ok
  1824. INSERT INTO t2 VALUES (3, date '2020-01-03')
  1825. query T
  1826. SELECT list_agg(a ORDER BY b)::text FROM t2
  1827. ----
  1828. {1,NULL,3}
  1829. query T
  1830. SELECT list_agg(a ORDER BY a DESC)::text FROM t2
  1831. ----
  1832. {NULL,3,1}
  1833. query T
  1834. SELECT list_agg(a ORDER BY a)::text FROM t2
  1835. ----
  1836. {1,3,NULL}
  1837. query T
  1838. SELECT (list_agg(a ORDER BY a) FILTER (WHERE b IS NOT NULL))::text FROM t2
  1839. ----
  1840. {1,3,NULL}
  1841. query T
  1842. SELECT (list_agg(a ORDER BY a) FILTER (WHERE b > '2050-01-01'))::text FROM t2
  1843. ----
  1844. {}
  1845. query T
  1846. SELECT list_agg(a ORDER BY b)::text FROM (VALUES (1, -1), (2, -2), (3, -3)) _ (a, b)
  1847. ----
  1848. {3,2,1}
  1849. query T
  1850. SELECT list_agg(a ORDER BY abs(b))::text FROM (VALUES (1, -1), (2, -2), (3, -3)) _ (a, b)
  1851. ----
  1852. {1,2,3}
  1853. query T
  1854. SELECT list_agg(a ORDER BY a > 10, -a)::text FROM (VALUES (1, -1), (2, -2), (3, -3)) _ (a, b)
  1855. ----
  1856. {3,2,1}
  1857. query T
  1858. SELECT list_agg(a ORDER BY (SELECT abs(-b)))::text FROM (VALUES (1, -1), (2, -2), (3, -3)) _ (a, b)
  1859. ----
  1860. {1,2,3}
  1861. query T
  1862. SELECT list_agg(a ORDER BY a+1 DESC)::text FROM (VALUES (1, -1), (2, -2), (3, -3)) _ (a, b)
  1863. ----
  1864. {3,2,1}
  1865. query T
  1866. SELECT list_agg(a ORDER BY -a DESC)::text FROM (VALUES (1, -1), (2, -2), (3, -3)) _ (a, b)
  1867. ----
  1868. {1,2,3}
  1869. query error column "no_such_column" does not exist
  1870. SELECT array_agg(a ORDER BY no_such_column)::text FROM (VALUES (1, -1)) AS a(a);
  1871. query error division by zero
  1872. SELECT array_agg(a ORDER BY a/0)::text FROM (VALUES (1, -1)) AS a(a);
  1873. query error more than one record produced in subquery
  1874. SELECT list_agg(a ORDER BY (SELECT 'a' FROM t2))::text FROM t2;
  1875. query error Expected subselect to return 1 column, got 2 columns
  1876. SELECT list_agg(a ORDER BY (SELECT * FROM t2)) FROM t2
  1877. query T
  1878. SELECT array_agg(column1 ORDER BY 1234)::text FROM (VALUES (1)) _;
  1879. ----
  1880. {1}
  1881. # Test that a function that does not support ORDER BY is correct.
  1882. query T
  1883. SELECT sum(a ORDER BY b) FROM t2
  1884. ----
  1885. 4
  1886. # list_remove
  1887. query T
  1888. SELECT list_remove(LIST[1,2,3,2], 2)::text
  1889. ----
  1890. {1,3}
  1891. query T
  1892. SELECT list_remove(LIST[1,2,3,2], 5)::text
  1893. ----
  1894. {1,2,3,2}
  1895. query T
  1896. SELECT list_remove(LIST[1,2,3,NULL::INT], NULL::INT)::text
  1897. ----
  1898. {1,2,3}
  1899. query T
  1900. SELECT list_remove(LIST[1,NULL::INT,2,3,NULL::INT], NULL::INT)::text
  1901. ----
  1902. {1,2,3}
  1903. query T
  1904. SELECT list_remove(NULL::integer list, NULL::INT)::text
  1905. ----
  1906. NULL
  1907. query T
  1908. SELECT list_remove(NULL::integer list, 1)::text
  1909. ----
  1910. NULL
  1911. query T
  1912. SELECT list_remove(LIST[1,1,1], 1)::text
  1913. ----
  1914. {}
  1915. query T
  1916. SELECT list_remove(LIST[[1,2],[1],[1,2,3], LIST[1]], LIST[1])::text
  1917. ----
  1918. {{1,2},{1,2,3}}
  1919. query T
  1920. SELECT list_remove(LIST[[1,2],[1],[1,2,3],LIST[1]], LIST[1,2,3])::text
  1921. ----
  1922. {{1,2},{1},{1}}
  1923. ## polymorphism
  1924. query T
  1925. SELECT pg_typeof(list_remove(LIST[1::int8,2,3,2], 2::int2))
  1926. ----
  1927. bigint list
  1928. query T
  1929. SELECT pg_typeof(list_remove(LIST[1::int2,2,3,2], 2::int8))
  1930. ----
  1931. bigint list
  1932. # array to list
  1933. query T
  1934. SELECT '{1,2,3}'::int[]::int list::text;
  1935. ----
  1936. {1,2,3}
  1937. query T
  1938. SELECT pg_typeof('{1,2,3}'::int[]::int list);
  1939. ----
  1940. integer list
  1941. query T
  1942. SELECT '{}'::int[]::int list::text;
  1943. ----
  1944. {}
  1945. query T
  1946. SELECT pg_typeof('{1,2,3}'::int[]::int list);
  1947. ----
  1948. integer list
  1949. query T
  1950. SELECT NULL::int[]::int list::text;
  1951. ----
  1952. NULL
  1953. query T
  1954. SELECT pg_typeof(NULL::int[]::int list);
  1955. ----
  1956. integer list
  1957. query error casting multi-dimensional array to list; got array with 2 dimensions not yet supported
  1958. SELECT '{{1},{2},{3}}'::int[]::int list::text;
  1959. # Verify nested lists
  1960. statement ok
  1961. CREATE TABLE users (id int not null, other_field int not null)
  1962. statement ok
  1963. CREATE TABLE customer (id int not null, first_name string not null, last_name string not null, zip string not null)
  1964. statement ok
  1965. INSERT INTO users VALUES (1, 10), (2, 5), (3, 8);
  1966. statement ok
  1967. INSERT INTO customer VALUES (1, 'alice', 'lasta', '10003'::text), (2, 'bob', 'lastb', '10013'::text), (3, 'charlie', 'lastc', '11217'::text);
  1968. query error LIST could not convert type integer list to text list
  1969. SELECT LIST[LIST[customer.first_name, customer.last_name], LIST[customer.zip], LIST[customer.id]]::text FROM customer JOIN users ON customer.id = users.id ORDER BY users.other_field DESC LIMIT 2
  1970. query T
  1971. SELECT LIST[LIST[customer.first_name, customer.last_name], LIST[customer.zip], LIST[customer.id::text]]::text FROM customer JOIN users ON customer.id = users.id ORDER BY users.other_field DESC LIMIT 2
  1972. ----
  1973. {{alice,lasta},{10003},{1}}
  1974. {{charlie,lastc},{11217},{3}}
  1975. ## Optimization: Reducing ListIndex(ListCreate, literal) and multidimensional variations
  1976. # Most of these tests could also be in src/expr/tests/testdata/reduce, but writing these big ListCreate expressions is a
  1977. # bit cumbersome in that format.
  1978. statement ok
  1979. CREATE TABLE t3(f1 int, f2 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int, n int, m int, l int list)
  1980. statement ok
  1981. CREATE VIEW m3 AS SELECT * FROM t3
  1982. statement ok
  1983. CREATE DEFAULT INDEX ON m3
  1984. statement ok
  1985. INSERT INTO t3 VALUES (1, 2, 3, 4, 5, 6, 7, 8, 1, 2, list[42, 43])
  1986. statement ok
  1987. INSERT INTO t3 VALUES (11, 12, 13, 14, 15, 16, 17, 18, 11, 12, list[82, 83])
  1988. query T multiline
  1989. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT LIST[f1, f2, f3, f4, f5][3] from m3
  1990. ----
  1991. Explained Query (fast path):
  1992. Project (#2{f3})
  1993. ReadIndex on=materialize.public.m3 m3_primary_idx=[*** full scan ***]
  1994. Used Indexes:
  1995. - materialize.public.m3_primary_idx (*** full scan ***)
  1996. Target cluster: quickstart
  1997. EOF
  1998. query I rowsort
  1999. SELECT LIST[f1, f2, f3, f4, f5][3] from m3
  2000. ----
  2001. 3
  2002. 13
  2003. # Reducing multidimensional ListIndex when all indexes are literals
  2004. query T multiline
  2005. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT LIST[[f1, f2], [f3, f4]][2][1] from m3
  2006. ----
  2007. Explained Query (fast path):
  2008. Project (#2{f3})
  2009. ReadIndex on=materialize.public.m3 m3_primary_idx=[*** full scan ***]
  2010. Used Indexes:
  2011. - materialize.public.m3_primary_idx (*** full scan ***)
  2012. Target cluster: quickstart
  2013. EOF
  2014. query I rowsort
  2015. SELECT LIST[[f1, f2], [f3, f4]][2][1] from m3
  2016. ----
  2017. 3
  2018. 13
  2019. query T multiline
  2020. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [2][1][2] from m3
  2021. ----
  2022. Explained Query (fast path):
  2023. Project (#5{f6})
  2024. ReadIndex on=materialize.public.m3 m3_primary_idx=[*** full scan ***]
  2025. Used Indexes:
  2026. - materialize.public.m3_primary_idx (*** full scan ***)
  2027. Target cluster: quickstart
  2028. EOF
  2029. query I rowsort
  2030. SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [2][1][2] from m3
  2031. ----
  2032. 6
  2033. 16
  2034. # Reducing multidimensional ListIndex when some of the indexes are not literals, and therefore can't be removed.
  2035. # We use `types, no fast path` to be able to check that the type is not changing.
  2036. query T multiline
  2037. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations, types, no fast path) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f7, f8, f3, f4]], [[f5, f6], [f7, f8]]] [n][m][n] from m3
  2038. ----
  2039. Explained Query:
  2040. Project (#12) // { arity: 1, types: "(integer?)" }
  2041. Map (integer_to_bigint(#8{n}), list_index(list[list[list[#0{f1}, #1{f2}], list[#6{f7}, #7{f8}, #2{f3}, #3{f4}]], list[list[#4{f5}, #5{f6}], list[#6{f7}, #7{f8}]]], #11, integer_to_bigint(#9{m}), #11)) // { arity: 13, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?, bigint?, integer?)" }
  2042. ReadIndex on=m3 m3_primary_idx=[*** full scan ***] // { arity: 11, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?)" }
  2043. Used Indexes:
  2044. - materialize.public.m3_primary_idx (*** full scan ***)
  2045. Target cluster: quickstart
  2046. EOF
  2047. query I rowsort
  2048. SELECT LIST[[[f1, f2], [f7, f8, f3, f4]], [[f5, f6], [f7, f8]]] [n][m][n] from m3
  2049. ----
  2050. 7
  2051. NULL
  2052. query T multiline
  2053. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations, types, no fast path) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [n][m][1] from m3
  2054. ----
  2055. Explained Query:
  2056. Project (#11) // { arity: 1, types: "(integer?)" }
  2057. Map (list_index(list[list[#0{f1}, #2{f3}], list[#4{f5}, #6{f7}]], integer_to_bigint(#8{n}), integer_to_bigint(#9{m}))) // { arity: 12, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?, integer?)" }
  2058. ReadIndex on=m3 m3_primary_idx=[*** full scan ***] // { arity: 11, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?)" }
  2059. Used Indexes:
  2060. - materialize.public.m3_primary_idx (*** full scan ***)
  2061. Target cluster: quickstart
  2062. EOF
  2063. query I rowsort
  2064. SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [n][m][1] from m3
  2065. ----
  2066. 3
  2067. NULL
  2068. query T multiline
  2069. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations, types, no fast path) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [n][2][m] from m3
  2070. ----
  2071. Explained Query:
  2072. Project (#11) // { arity: 1, types: "(integer?)" }
  2073. Map (list_index(list[list[#2{f3}, #3{f4}], list[#6{f7}, #7{f8}]], integer_to_bigint(#8{n}), integer_to_bigint(#9{m}))) // { arity: 12, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?, integer?)" }
  2074. ReadIndex on=m3 m3_primary_idx=[*** full scan ***] // { arity: 11, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?)" }
  2075. Used Indexes:
  2076. - materialize.public.m3_primary_idx (*** full scan ***)
  2077. Target cluster: quickstart
  2078. EOF
  2079. query I rowsort
  2080. SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [n][2][m] from m3
  2081. ----
  2082. 4
  2083. NULL
  2084. query T multiline
  2085. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations, types, no fast path) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [1][n][m] from m3
  2086. ----
  2087. Explained Query:
  2088. Project (#11) // { arity: 1, types: "(integer?)" }
  2089. Map (list_index(list[list[#0{f1}, #1{f2}], list[#2{f3}, #3{f4}]], integer_to_bigint(#8{n}), integer_to_bigint(#9{m}))) // { arity: 12, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?, integer?)" }
  2090. ReadIndex on=m3 m3_primary_idx=[*** full scan ***] // { arity: 11, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?)" }
  2091. Used Indexes:
  2092. - materialize.public.m3_primary_idx (*** full scan ***)
  2093. Target cluster: quickstart
  2094. EOF
  2095. query I rowsort
  2096. SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [1][n][m] from m3
  2097. ----
  2098. 2
  2099. NULL
  2100. query T multiline
  2101. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations, types, no fast path) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [2][1][n] from m3
  2102. ----
  2103. Explained Query:
  2104. Project (#11) // { arity: 1, types: "(integer?)" }
  2105. Map (list_index(list[#4{f5}, #5{f6}], integer_to_bigint(#8{n}))) // { arity: 12, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?, integer?)" }
  2106. ReadIndex on=m3 m3_primary_idx=[*** full scan ***] // { arity: 11, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?)" }
  2107. Used Indexes:
  2108. - materialize.public.m3_primary_idx (*** full scan ***)
  2109. Target cluster: quickstart
  2110. EOF
  2111. query I rowsort
  2112. SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [2][1][n] from m3
  2113. ----
  2114. 5
  2115. NULL
  2116. query T multiline
  2117. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations, types, no fast path) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [2][n][2] from m3
  2118. ----
  2119. Explained Query:
  2120. Project (#11) // { arity: 1, types: "(integer?)" }
  2121. Map (list_index(list[#5{f6}, #7{f8}], integer_to_bigint(#8{n}))) // { arity: 12, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?, integer?)" }
  2122. ReadIndex on=m3 m3_primary_idx=[*** full scan ***] // { arity: 11, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?)" }
  2123. Used Indexes:
  2124. - materialize.public.m3_primary_idx (*** full scan ***)
  2125. Target cluster: quickstart
  2126. EOF
  2127. query I rowsort
  2128. SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [2][n][2] from m3
  2129. ----
  2130. 6
  2131. NULL
  2132. query T multiline
  2133. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations, types, no fast path) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [n][2][2] from m3
  2134. ----
  2135. Explained Query:
  2136. Project (#11) // { arity: 1, types: "(integer?)" }
  2137. Map (list_index(list[#3{f4}, #7{f8}], integer_to_bigint(#8{n}))) // { arity: 12, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?, integer?)" }
  2138. ReadIndex on=m3 m3_primary_idx=[*** full scan ***] // { arity: 11, types: "(integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer?, integer list?)" }
  2139. Used Indexes:
  2140. - materialize.public.m3_primary_idx (*** full scan ***)
  2141. Target cluster: quickstart
  2142. EOF
  2143. query I rowsort
  2144. SELECT LIST[[[f1, f2], [f3, f4]], [[f5, f6], [f7, f8]]] [n][2][2] from m3
  2145. ----
  2146. 4
  2147. NULL
  2148. # Reducing ListIndex when a literal index is out of bounds
  2149. query T multiline
  2150. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT LIST[f1, f2, f3, f4, f5][6] from m3
  2151. ----
  2152. Explained Query (fast path):
  2153. Project (#11)
  2154. Map (null)
  2155. ReadIndex on=materialize.public.m3 m3_primary_idx=[*** full scan ***]
  2156. Used Indexes:
  2157. - materialize.public.m3_primary_idx (*** full scan ***)
  2158. Target cluster: quickstart
  2159. EOF
  2160. query T multiline
  2161. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT LIST[f1, f2, f3, f4, f5][0] from m3
  2162. ----
  2163. Explained Query (fast path):
  2164. Project (#11)
  2165. Map (null)
  2166. ReadIndex on=materialize.public.m3 m3_primary_idx=[*** full scan ***]
  2167. Used Indexes:
  2168. - materialize.public.m3_primary_idx (*** full scan ***)
  2169. Target cluster: quickstart
  2170. EOF
  2171. query T multiline
  2172. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT LIST[f1, f2, f3, f4, f5][-1] from m3
  2173. ----
  2174. Explained Query (fast path):
  2175. Project (#11)
  2176. Map (null)
  2177. ReadIndex on=materialize.public.m3 m3_primary_idx=[*** full scan ***]
  2178. Used Indexes:
  2179. - materialize.public.m3_primary_idx (*** full scan ***)
  2180. Target cluster: quickstart
  2181. EOF
  2182. query T
  2183. SELECT LIST[f1, f2, f3, f4, f5][6] from m3
  2184. ----
  2185. NULL
  2186. NULL
  2187. # Reducing multidimensional ListIndex when a literal index is out of bounds.
  2188. # Also, one of the indexes is `1+1`, which must be evaluated to make it a literal, and then the reduction can take place.
  2189. query T multiline
  2190. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f3, f4]], [l, [f7, f8]]] [1+1][-1][2] from m3;
  2191. ----
  2192. Explained Query (fast path):
  2193. Project (#11)
  2194. Map (null)
  2195. ReadIndex on=materialize.public.m3 m3_primary_idx=[*** full scan ***]
  2196. Used Indexes:
  2197. - materialize.public.m3_primary_idx (*** full scan ***)
  2198. Target cluster: quickstart
  2199. EOF
  2200. # Reducing multidimensional ListIndex when the list doesn't have enough complete layers,
  2201. # but has a NULL instead of a ListCreate.
  2202. query T multiline
  2203. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f3, f4]], [NULL, [f7, f8]]] [1+1][1][2] from m3
  2204. ----
  2205. Explained Query (fast path):
  2206. Project (#11)
  2207. Map (null)
  2208. ReadIndex on=materialize.public.m3 m3_primary_idx=[*** full scan ***]
  2209. Used Indexes:
  2210. - materialize.public.m3_primary_idx (*** full scan ***)
  2211. Target cluster: quickstart
  2212. EOF
  2213. # Reducing multidimensional ListIndex when the list doesn't have enough complete layers,
  2214. # but has a column reference instead of a ListCreate.
  2215. query T multiline
  2216. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT LIST[[[f1, f2], [f3, f4]], [l, [f7, f8]]] [1+1][1][2] from m3
  2217. ----
  2218. Explained Query (fast path):
  2219. Project (#11)
  2220. Map (list_index(#10{l}, 2))
  2221. ReadIndex on=materialize.public.m3 m3_primary_idx=[*** full scan ***]
  2222. Used Indexes:
  2223. - materialize.public.m3_primary_idx (*** full scan ***)
  2224. Target cluster: quickstart
  2225. EOF
  2226. query I rowsort
  2227. SELECT LIST[[[f1, f2], [f3, f4]], [l, [f7, f8]]] [1+1][1][2] from m3
  2228. ----
  2229. 43
  2230. 83
  2231. # Reducing ListIndex(ListCreate, literal) when this pattern appears after some other optimization (reduce_elision)
  2232. # already took place.
  2233. query T multiline
  2234. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT row_number() over () from (select f1 from m3 limit 1)
  2235. ----
  2236. Explained Query:
  2237. Project (#2) // { arity: 1 }
  2238. Map (record_get[0](#1)) // { arity: 3 }
  2239. FlatMap unnest_list(#0) // { arity: 2 }
  2240. Project (#1) // { arity: 1 }
  2241. Map (list[row(1, row(#0{f1}))]) // { arity: 2 }
  2242. TopK limit=1 // { arity: 1 }
  2243. Project (#0{f1}) // { arity: 1 }
  2244. ReadIndex on=m3 m3_primary_idx=[*** full scan ***] // { arity: 11 }
  2245. Used Indexes:
  2246. - materialize.public.m3_primary_idx (*** full scan ***)
  2247. Target cluster: quickstart
  2248. EOF
  2249. query T
  2250. SELECT LIST[1,4,3] @> LIST[3,1] AS contains
  2251. ----
  2252. true
  2253. query T
  2254. SELECT LIST[1,4,3] <@ LIST[3,1] AS contains
  2255. ----
  2256. false
  2257. # array containment in Postgres does NOT account for duplicates
  2258. query T
  2259. SELECT LIST[1,4,3] @> LIST[3,1,1,1,1,1,1,1,1,1,1,1,3,3,1,3,3,3,3,3,1,1,3,3,3] AS contains
  2260. ----
  2261. true
  2262. query T
  2263. SELECT LIST[1,4,3] @> LIST[]::INT LIST AS contains
  2264. ----
  2265. true
  2266. query T
  2267. SELECT LIST[2,7] <@ LIST[1,7,4,2,6] AS is_contained_by
  2268. ----
  2269. true
  2270. query T
  2271. SELECT LIST[2,7] @> LIST[1,7,4,2,6] AS is_contained_by
  2272. ----
  2273. false
  2274. query T
  2275. SELECT '{}'::numeric list @> '{}'::numeric list;
  2276. ----
  2277. true
  2278. query T
  2279. SELECT '{1,2}'::numeric list @> '{}'::numeric list;
  2280. ----
  2281. true
  2282. query T
  2283. SELECT '{}'::numeric list @> '{1,2}'::numeric list;
  2284. ----
  2285. false
  2286. query T
  2287. SELECT '{NULL}'::numeric list @> '{NULL}'::numeric list;
  2288. ----
  2289. false
  2290. query T
  2291. SELECT '{NULL, 1}'::numeric list @> '{1}'::numeric list;
  2292. ----
  2293. true
  2294. query T
  2295. SELECT '{1}'::numeric list @> '{1, NULL}'::numeric list;
  2296. ----
  2297. false
  2298. query T
  2299. SELECT '{1, 2, 3, NULL}'::numeric list @> '{1, NULL}'::numeric list;
  2300. ----
  2301. false
  2302. query T
  2303. SELECT LIST[1,3,7,NULL] @> LIST[1,3,7,NULL] AS contains;
  2304. ----
  2305. false
  2306. # Make sure we can index into a CAST-ed list.
  2307. statement ok
  2308. CREATE TABLE jsons (payload jsonb, random_index int, random_id uuid);
  2309. statement ok
  2310. CREATE MATERIALIZED VIEW json_mv AS (
  2311. SELECT * FROM jsons WHERE random_id = CAST(payload->>'my_field' AS uuid list)[random_index]
  2312. )