arrays.out 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436
  1. --
  2. -- ARRAYS
  3. --
  4. CREATE TABLE arrtest (
  5. a int2[],
  6. b int4[][][],
  7. c name[],
  8. d text[][],
  9. e float8[],
  10. f char(5)[],
  11. g varchar(5)[]
  12. );
  13. --
  14. -- only the 'e' array is 0-based, the others are 1-based.
  15. --
  16. INSERT INTO arrtest (a[1:5], b[1:1][1:2][1:2], c, d, f, g)
  17. VALUES ('{1,2,3,4,5}', '{{{0,0},{1,2}}}', '{}', '{}', '{}', '{}');
  18. UPDATE arrtest SET e[0] = '1.1';
  19. UPDATE arrtest SET e[1] = '2.2';
  20. INSERT INTO arrtest (f)
  21. VALUES ('{"too long"}');
  22. ERROR: value too long for type character(5)
  23. INSERT INTO arrtest (a, b[1:2][1:2], c, d, e, f, g)
  24. VALUES ('{11,12,23}', '{{3,4},{4,5}}', '{"foobar"}',
  25. '{{"elt1", "elt2"}}', '{"3.4", "6.7"}',
  26. '{"abc","abcde"}', '{"abc","abcde"}');
  27. INSERT INTO arrtest (a, b[1:2], c, d[1:2])
  28. VALUES ('{}', '{3,4}', '{foo,bar}', '{bar,foo}');
  29. INSERT INTO arrtest (b[2]) VALUES(now()); -- error, type mismatch
  30. ERROR: subscripted assignment to "b" requires type integer but expression is of type timestamp with time zone
  31. LINE 1: INSERT INTO arrtest (b[2]) VALUES(now());
  32. ^
  33. HINT: You will need to rewrite or cast the expression.
  34. INSERT INTO arrtest (b[1:2]) VALUES(now()); -- error, type mismatch
  35. ERROR: subscripted assignment to "b" requires type integer[] but expression is of type timestamp with time zone
  36. LINE 1: INSERT INTO arrtest (b[1:2]) VALUES(now());
  37. ^
  38. HINT: You will need to rewrite or cast the expression.
  39. SELECT * FROM arrtest;
  40. a | b | c | d | e | f | g
  41. -------------+-----------------+-----------+---------------+-----------------+-----------------+-------------
  42. {1,2,3,4,5} | {{{0,0},{1,2}}} | {} | {} | [0:1]={1.1,2.2} | {} | {}
  43. {11,12,23} | {{3,4},{4,5}} | {foobar} | {{elt1,elt2}} | {3.4,6.7} | {"abc ",abcde} | {abc,abcde}
  44. {} | {3,4} | {foo,bar} | {bar,foo} | | |
  45. (3 rows)
  46. SELECT arrtest.a[1],
  47. arrtest.b[1][1][1],
  48. arrtest.c[1],
  49. arrtest.d[1][1],
  50. arrtest.e[0]
  51. FROM arrtest;
  52. a | b | c | d | e
  53. ----+---+--------+------+-----
  54. 1 | 0 | | | 1.1
  55. 11 | | foobar | elt1 |
  56. | | foo | |
  57. (3 rows)
  58. SELECT a[1], b[1][1][1], c[1], d[1][1], e[0]
  59. FROM arrtest;
  60. a | b | c | d | e
  61. ----+---+--------+------+-----
  62. 1 | 0 | | | 1.1
  63. 11 | | foobar | elt1 |
  64. | | foo | |
  65. (3 rows)
  66. SELECT a[1:3],
  67. b[1:1][1:2][1:2],
  68. c[1:2],
  69. d[1:1][1:2]
  70. FROM arrtest;
  71. a | b | c | d
  72. ------------+-----------------+-----------+---------------
  73. {1,2,3} | {{{0,0},{1,2}}} | {} | {}
  74. {11,12,23} | {} | {foobar} | {{elt1,elt2}}
  75. {} | {} | {foo,bar} | {}
  76. (3 rows)
  77. SELECT array_ndims(a) AS a,array_ndims(b) AS b,array_ndims(c) AS c
  78. FROM arrtest;
  79. a | b | c
  80. ---+---+---
  81. 1 | 3 |
  82. 1 | 2 | 1
  83. | 1 | 1
  84. (3 rows)
  85. SELECT array_dims(a) AS a,array_dims(b) AS b,array_dims(c) AS c
  86. FROM arrtest;
  87. a | b | c
  88. -------+-----------------+-------
  89. [1:5] | [1:1][1:2][1:2] |
  90. [1:3] | [1:2][1:2] | [1:1]
  91. | [1:2] | [1:2]
  92. (3 rows)
  93. -- returns nothing
  94. SELECT *
  95. FROM arrtest
  96. WHERE a[1] < 5 and
  97. c = '{"foobar"}'::_name;
  98. a | b | c | d | e | f | g
  99. ---+---+---+---+---+---+---
  100. (0 rows)
  101. UPDATE arrtest
  102. SET a[1:2] = '{16,25}'
  103. WHERE NOT a = '{}'::_int2;
  104. UPDATE arrtest
  105. SET b[1:1][1:1][1:2] = '{113, 117}',
  106. b[1:1][1:2][2:2] = '{142, 147}'
  107. WHERE array_dims(b) = '[1:1][1:2][1:2]';
  108. UPDATE arrtest
  109. SET c[2:2] = '{"new_word"}'
  110. WHERE array_dims(c) is not null;
  111. SELECT a,b,c FROM arrtest;
  112. a | b | c
  113. ---------------+-----------------------+-------------------
  114. {16,25,3,4,5} | {{{113,142},{1,147}}} | {}
  115. {} | {3,4} | {foo,new_word}
  116. {16,25,23} | {{3,4},{4,5}} | {foobar,new_word}
  117. (3 rows)
  118. SELECT a[1:3],
  119. b[1:1][1:2][1:2],
  120. c[1:2],
  121. d[1:1][2:2]
  122. FROM arrtest;
  123. a | b | c | d
  124. ------------+-----------------------+-------------------+----------
  125. {16,25,3} | {{{113,142},{1,147}}} | {} | {}
  126. {} | {} | {foo,new_word} | {}
  127. {16,25,23} | {} | {foobar,new_word} | {{elt2}}
  128. (3 rows)
  129. SELECT b[1:1][2][2],
  130. d[1:1][2]
  131. FROM arrtest;
  132. b | d
  133. -----------------------+---------------
  134. {{{113,142},{1,147}}} | {}
  135. {} | {}
  136. {} | {{elt1,elt2}}
  137. (3 rows)
  138. INSERT INTO arrtest(a) VALUES('{1,null,3}');
  139. SELECT a FROM arrtest;
  140. a
  141. ---------------
  142. {16,25,3,4,5}
  143. {}
  144. {16,25,23}
  145. {1,NULL,3}
  146. (4 rows)
  147. UPDATE arrtest SET a[4] = NULL WHERE a[2] IS NULL;
  148. SELECT a FROM arrtest WHERE a[2] IS NULL;
  149. a
  150. -----------------
  151. [4:4]={NULL}
  152. {1,NULL,3,NULL}
  153. (2 rows)
  154. DELETE FROM arrtest WHERE a[2] IS NULL AND b IS NULL;
  155. SELECT a,b,c FROM arrtest;
  156. a | b | c
  157. ---------------+-----------------------+-------------------
  158. {16,25,3,4,5} | {{{113,142},{1,147}}} | {}
  159. {16,25,23} | {{3,4},{4,5}} | {foobar,new_word}
  160. [4:4]={NULL} | {3,4} | {foo,new_word}
  161. (3 rows)
  162. -- test mixed slice/scalar subscripting
  163. select '{{1,2,3},{4,5,6},{7,8,9}}'::int[];
  164. int4
  165. ---------------------------
  166. {{1,2,3},{4,5,6},{7,8,9}}
  167. (1 row)
  168. select ('{{1,2,3},{4,5,6},{7,8,9}}'::int[])[1:2][2];
  169. int4
  170. ---------------
  171. {{1,2},{4,5}}
  172. (1 row)
  173. select '[0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}'::int[];
  174. int4
  175. --------------------------------------
  176. [0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}
  177. (1 row)
  178. select ('[0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}'::int[])[1:2][2];
  179. int4
  180. ---------------
  181. {{5,6},{8,9}}
  182. (1 row)
  183. --
  184. -- check subscription corner cases
  185. --
  186. -- More subscripts than MAXDIM (6)
  187. SELECT ('{}'::int[])[1][2][3][4][5][6][7];
  188. ERROR: number of array dimensions (7) exceeds the maximum allowed (6)
  189. -- NULL index yields NULL when selecting
  190. SELECT ('{{{1},{2},{3}},{{4},{5},{6}}}'::int[])[1][NULL][1];
  191. int4
  192. ------
  193. (1 row)
  194. SELECT ('{{{1},{2},{3}},{{4},{5},{6}}}'::int[])[1][NULL:1][1];
  195. int4
  196. ------
  197. (1 row)
  198. SELECT ('{{{1},{2},{3}},{{4},{5},{6}}}'::int[])[1][1:NULL][1];
  199. int4
  200. ------
  201. (1 row)
  202. -- NULL index in assignment is an error
  203. UPDATE arrtest
  204. SET c[NULL] = '{"can''t assign"}'
  205. WHERE array_dims(c) is not null;
  206. ERROR: array subscript in assignment must not be null
  207. UPDATE arrtest
  208. SET c[NULL:1] = '{"can''t assign"}'
  209. WHERE array_dims(c) is not null;
  210. ERROR: array subscript in assignment must not be null
  211. UPDATE arrtest
  212. SET c[1:NULL] = '{"can''t assign"}'
  213. WHERE array_dims(c) is not null;
  214. ERROR: array subscript in assignment must not be null
  215. -- Un-subscriptable type
  216. SELECT (now())[1];
  217. ERROR: cannot subscript type timestamp with time zone because it does not support subscripting
  218. LINE 1: SELECT (now())[1];
  219. ^
  220. -- test slices with empty lower and/or upper index
  221. CREATE TEMP TABLE arrtest_s (
  222. a int2[],
  223. b int2[][]
  224. );
  225. INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
  226. INSERT INTO arrtest_s VALUES ('[0:4]={1,2,3,4,5}', '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}');
  227. SELECT * FROM arrtest_s;
  228. a | b
  229. -------------------+--------------------------------------
  230. {1,2,3,4,5} | {{1,2,3},{4,5,6},{7,8,9}}
  231. [0:4]={1,2,3,4,5} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}
  232. (2 rows)
  233. SELECT a[:3], b[:2][:2] FROM arrtest_s;
  234. a | b
  235. -----------+---------------------------
  236. {1,2,3} | {{1,2},{4,5}}
  237. {1,2,3,4} | {{1,2,3},{4,5,6},{7,8,9}}
  238. (2 rows)
  239. SELECT a[2:], b[2:][2:] FROM arrtest_s;
  240. a | b
  241. -----------+---------------
  242. {2,3,4,5} | {{5,6},{8,9}}
  243. {3,4,5} | {{9}}
  244. (2 rows)
  245. SELECT a[:], b[:] FROM arrtest_s;
  246. a | b
  247. -------------+---------------------------
  248. {1,2,3,4,5} | {{1,2,3},{4,5,6},{7,8,9}}
  249. {1,2,3,4,5} | {{1,2,3},{4,5,6},{7,8,9}}
  250. (2 rows)
  251. -- updates
  252. UPDATE arrtest_s SET a[:3] = '{11, 12, 13}', b[:2][:2] = '{{11,12}, {14,15}}'
  253. WHERE array_lower(a,1) = 1;
  254. SELECT * FROM arrtest_s;
  255. a | b
  256. -------------------+--------------------------------------
  257. [0:4]={1,2,3,4,5} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}
  258. {11,12,13,4,5} | {{11,12,3},{14,15,6},{7,8,9}}
  259. (2 rows)
  260. UPDATE arrtest_s SET a[3:] = '{23, 24, 25}', b[2:][2:] = '{{25,26}, {28,29}}';
  261. SELECT * FROM arrtest_s;
  262. a | b
  263. ---------------------+---------------------------------------
  264. [0:4]={1,2,3,23,24} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,25}}
  265. {11,12,23,24,25} | {{11,12,3},{14,25,26},{7,28,29}}
  266. (2 rows)
  267. UPDATE arrtest_s SET a[:] = '{11, 12, 13, 14, 15}';
  268. SELECT * FROM arrtest_s;
  269. a | b
  270. ------------------------+---------------------------------------
  271. [0:4]={11,12,13,14,15} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,25}}
  272. {11,12,13,14,15} | {{11,12,3},{14,25,26},{7,28,29}}
  273. (2 rows)
  274. UPDATE arrtest_s SET a[:] = '{23, 24, 25}'; -- fail, too small
  275. ERROR: source array too small
  276. INSERT INTO arrtest_s VALUES(NULL, NULL);
  277. UPDATE arrtest_s SET a[:] = '{11, 12, 13, 14, 15}'; -- fail, no good with null
  278. ERROR: array slice subscript must provide both boundaries
  279. DETAIL: When assigning to a slice of an empty array value, slice boundaries must be fully specified.
  280. -- check with fixed-length-array type, such as point
  281. SELECT f1[0:1] FROM POINT_TBL;
  282. ERROR: slices of fixed-length arrays not implemented
  283. SELECT f1[0:] FROM POINT_TBL;
  284. ERROR: slices of fixed-length arrays not implemented
  285. SELECT f1[:1] FROM POINT_TBL;
  286. ERROR: slices of fixed-length arrays not implemented
  287. SELECT f1[:] FROM POINT_TBL;
  288. ERROR: slices of fixed-length arrays not implemented
  289. -- subscript assignments to fixed-width result in NULL if previous value is NULL
  290. UPDATE point_tbl SET f1[0] = 10 WHERE f1 IS NULL RETURNING *;
  291. f1
  292. ----
  293. (1 row)
  294. INSERT INTO point_tbl(f1[0]) VALUES(0) RETURNING *;
  295. f1
  296. ----
  297. (1 row)
  298. -- NULL assignments get ignored
  299. UPDATE point_tbl SET f1[0] = NULL WHERE f1::text = '(10,10)'::point::text RETURNING *;
  300. f1
  301. ---------
  302. (10,10)
  303. (1 row)
  304. -- but non-NULL subscript assignments work
  305. UPDATE point_tbl SET f1[0] = -10, f1[1] = -10 WHERE f1::text = '(10,10)'::point::text RETURNING *;
  306. f1
  307. -----------
  308. (-10,-10)
  309. (1 row)
  310. -- but not to expand the range
  311. UPDATE point_tbl SET f1[3] = 10 WHERE f1::text = '(-10,-10)'::point::text RETURNING *;
  312. ERROR: array subscript out of range
  313. --
  314. -- test array extension
  315. --
  316. CREATE TEMP TABLE arrtest1 (i int[], t text[]);
  317. insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
  318. select * from arrtest1;
  319. i | t
  320. --------------+---------------------
  321. {1,2,NULL,4} | {one,two,NULL,four}
  322. (1 row)
  323. update arrtest1 set i[2] = 22, t[2] = 'twenty-two';
  324. select * from arrtest1;
  325. i | t
  326. ---------------+----------------------------
  327. {1,22,NULL,4} | {one,twenty-two,NULL,four}
  328. (1 row)
  329. update arrtest1 set i[5] = 5, t[5] = 'five';
  330. select * from arrtest1;
  331. i | t
  332. -----------------+---------------------------------
  333. {1,22,NULL,4,5} | {one,twenty-two,NULL,four,five}
  334. (1 row)
  335. update arrtest1 set i[8] = 8, t[8] = 'eight';
  336. select * from arrtest1;
  337. i | t
  338. -----------------------------+-------------------------------------------------
  339. {1,22,NULL,4,5,NULL,NULL,8} | {one,twenty-two,NULL,four,five,NULL,NULL,eight}
  340. (1 row)
  341. update arrtest1 set i[0] = 0, t[0] = 'zero';
  342. select * from arrtest1;
  343. i | t
  344. -------------------------------------+------------------------------------------------------------
  345. [0:8]={0,1,22,NULL,4,5,NULL,NULL,8} | [0:8]={zero,one,twenty-two,NULL,four,five,NULL,NULL,eight}
  346. (1 row)
  347. update arrtest1 set i[-3] = -3, t[-3] = 'minus-three';
  348. select * from arrtest1;
  349. i | t
  350. ---------------------------------------------------+-----------------------------------------------------------------------------------
  351. [-3:8]={-3,NULL,NULL,0,1,22,NULL,4,5,NULL,NULL,8} | [-3:8]={minus-three,NULL,NULL,zero,one,twenty-two,NULL,four,five,NULL,NULL,eight}
  352. (1 row)
  353. update arrtest1 set i[0:2] = array[10,11,12], t[0:2] = array['ten','eleven','twelve'];
  354. select * from arrtest1;
  355. i | t
  356. -----------------------------------------------------+---------------------------------------------------------------------------------
  357. [-3:8]={-3,NULL,NULL,10,11,12,NULL,4,5,NULL,NULL,8} | [-3:8]={minus-three,NULL,NULL,ten,eleven,twelve,NULL,four,five,NULL,NULL,eight}
  358. (1 row)
  359. update arrtest1 set i[8:10] = array[18,null,20], t[8:10] = array['p18',null,'p20'];
  360. select * from arrtest1;
  361. i | t
  362. ---------------------------------------------------------------+-----------------------------------------------------------------------------------------
  363. [-3:10]={-3,NULL,NULL,10,11,12,NULL,4,5,NULL,NULL,18,NULL,20} | [-3:10]={minus-three,NULL,NULL,ten,eleven,twelve,NULL,four,five,NULL,NULL,p18,NULL,p20}
  364. (1 row)
  365. update arrtest1 set i[11:12] = array[null,22], t[11:12] = array[null,'p22'];
  366. select * from arrtest1;
  367. i | t
  368. -----------------------------------------------------------------------+--------------------------------------------------------------------------------------------------
  369. [-3:12]={-3,NULL,NULL,10,11,12,NULL,4,5,NULL,NULL,18,NULL,20,NULL,22} | [-3:12]={minus-three,NULL,NULL,ten,eleven,twelve,NULL,four,five,NULL,NULL,p18,NULL,p20,NULL,p22}
  370. (1 row)
  371. update arrtest1 set i[15:16] = array[null,26], t[15:16] = array[null,'p26'];
  372. select * from arrtest1;
  373. i | t
  374. -----------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------
  375. [-3:16]={-3,NULL,NULL,10,11,12,NULL,4,5,NULL,NULL,18,NULL,20,NULL,22,NULL,NULL,NULL,26} | [-3:16]={minus-three,NULL,NULL,ten,eleven,twelve,NULL,four,five,NULL,NULL,p18,NULL,p20,NULL,p22,NULL,NULL,NULL,p26}
  376. (1 row)
  377. update arrtest1 set i[-5:-3] = array[-15,-14,-13], t[-5:-3] = array['m15','m14','m13'];
  378. select * from arrtest1;
  379. i | t
  380. --------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------
  381. [-5:16]={-15,-14,-13,NULL,NULL,10,11,12,NULL,4,5,NULL,NULL,18,NULL,20,NULL,22,NULL,NULL,NULL,26} | [-5:16]={m15,m14,m13,NULL,NULL,ten,eleven,twelve,NULL,four,five,NULL,NULL,p18,NULL,p20,NULL,p22,NULL,NULL,NULL,p26}
  382. (1 row)
  383. update arrtest1 set i[-7:-6] = array[-17,null], t[-7:-6] = array['m17',null];
  384. select * from arrtest1;
  385. i | t
  386. -----------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------
  387. [-7:16]={-17,NULL,-15,-14,-13,NULL,NULL,10,11,12,NULL,4,5,NULL,NULL,18,NULL,20,NULL,22,NULL,NULL,NULL,26} | [-7:16]={m17,NULL,m15,m14,m13,NULL,NULL,ten,eleven,twelve,NULL,four,five,NULL,NULL,p18,NULL,p20,NULL,p22,NULL,NULL,NULL,p26}
  388. (1 row)
  389. update arrtest1 set i[-12:-10] = array[-22,null,-20], t[-12:-10] = array['m22',null,'m20'];
  390. select * from arrtest1;
  391. i | t
  392. -----------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------
  393. [-12:16]={-22,NULL,-20,NULL,NULL,-17,NULL,-15,-14,-13,NULL,NULL,10,11,12,NULL,4,5,NULL,NULL,18,NULL,20,NULL,22,NULL,NULL,NULL,26} | [-12:16]={m22,NULL,m20,NULL,NULL,m17,NULL,m15,m14,m13,NULL,NULL,ten,eleven,twelve,NULL,four,five,NULL,NULL,p18,NULL,p20,NULL,p22,NULL,NULL,NULL,p26}
  394. (1 row)
  395. delete from arrtest1;
  396. insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
  397. select * from arrtest1;
  398. i | t
  399. --------------+---------------------
  400. {1,2,NULL,4} | {one,two,NULL,four}
  401. (1 row)
  402. update arrtest1 set i[0:5] = array[0,1,2,null,4,5], t[0:5] = array['z','p1','p2',null,'p4','p5'];
  403. select * from arrtest1;
  404. i | t
  405. ------------------------+----------------------------
  406. [0:5]={0,1,2,NULL,4,5} | [0:5]={z,p1,p2,NULL,p4,p5}
  407. (1 row)
  408. --
  409. -- array expressions and operators
  410. --
  411. -- table creation and INSERTs
  412. CREATE TEMP TABLE arrtest2 (i integer ARRAY[4], f float8[], n numeric[], t text[], d timestamp[]);
  413. INSERT INTO arrtest2 VALUES(
  414. ARRAY[[[113,142],[1,147]]],
  415. ARRAY[1.1,1.2,1.3]::float8[],
  416. ARRAY[1.1,1.2,1.3],
  417. ARRAY[[['aaa','aab'],['aba','abb'],['aca','acb']],[['baa','bab'],['bba','bbb'],['bca','bcb']]],
  418. ARRAY['19620326','19931223','19970117']::timestamp[]
  419. );
  420. -- some more test data
  421. CREATE TEMP TABLE arrtest_f (f0 int, f1 text, f2 float8);
  422. insert into arrtest_f values(1,'cat1',1.21);
  423. insert into arrtest_f values(2,'cat1',1.24);
  424. insert into arrtest_f values(3,'cat1',1.18);
  425. insert into arrtest_f values(4,'cat1',1.26);
  426. insert into arrtest_f values(5,'cat1',1.15);
  427. insert into arrtest_f values(6,'cat2',1.15);
  428. insert into arrtest_f values(7,'cat2',1.26);
  429. insert into arrtest_f values(8,'cat2',1.32);
  430. insert into arrtest_f values(9,'cat2',1.30);
  431. CREATE TEMP TABLE arrtest_i (f0 int, f1 text, f2 int);
  432. insert into arrtest_i values(1,'cat1',21);
  433. insert into arrtest_i values(2,'cat1',24);
  434. insert into arrtest_i values(3,'cat1',18);
  435. insert into arrtest_i values(4,'cat1',26);
  436. insert into arrtest_i values(5,'cat1',15);
  437. insert into arrtest_i values(6,'cat2',15);
  438. insert into arrtest_i values(7,'cat2',26);
  439. insert into arrtest_i values(8,'cat2',32);
  440. insert into arrtest_i values(9,'cat2',30);
  441. -- expressions
  442. SELECT t.f[1][3][1] AS "131", t.f[2][2][1] AS "221" FROM (
  443. SELECT ARRAY[[[111,112],[121,122],[131,132]],[[211,212],[221,122],[231,232]]] AS f
  444. ) AS t;
  445. 131 | 221
  446. -----+-----
  447. 131 | 221
  448. (1 row)
  449. SELECT ARRAY[[[[[['hello'],['world']]]]]];
  450. array
  451. ---------------------------
  452. {{{{{{hello},{world}}}}}}
  453. (1 row)
  454. SELECT ARRAY[ARRAY['hello'],ARRAY['world']];
  455. array
  456. -------------------
  457. {{hello},{world}}
  458. (1 row)
  459. SELECT ARRAY(select f2 from arrtest_f order by f2) AS "ARRAY";
  460. ARRAY
  461. -----------------------------------------------
  462. {1.15,1.15,1.18,1.21,1.24,1.26,1.26,1.3,1.32}
  463. (1 row)
  464. -- with nulls
  465. SELECT '{1,null,3}'::int[];
  466. int4
  467. ------------
  468. {1,NULL,3}
  469. (1 row)
  470. SELECT ARRAY[1,NULL,3];
  471. array
  472. ------------
  473. {1,NULL,3}
  474. (1 row)
  475. -- functions
  476. SELECT array_append(array[42], 6) AS "{42,6}";
  477. {42,6}
  478. --------
  479. {42,6}
  480. (1 row)
  481. SELECT array_prepend(6, array[42]) AS "{6,42}";
  482. {6,42}
  483. --------
  484. {6,42}
  485. (1 row)
  486. SELECT array_cat(ARRAY[1,2], ARRAY[3,4]) AS "{1,2,3,4}";
  487. {1,2,3,4}
  488. -----------
  489. {1,2,3,4}
  490. (1 row)
  491. SELECT array_cat(ARRAY[1,2], ARRAY[[3,4],[5,6]]) AS "{{1,2},{3,4},{5,6}}";
  492. {{1,2},{3,4},{5,6}}
  493. ---------------------
  494. {{1,2},{3,4},{5,6}}
  495. (1 row)
  496. SELECT array_cat(ARRAY[[3,4],[5,6]], ARRAY[1,2]) AS "{{3,4},{5,6},{1,2}}";
  497. {{3,4},{5,6},{1,2}}
  498. ---------------------
  499. {{3,4},{5,6},{1,2}}
  500. (1 row)
  501. SELECT array_position(ARRAY[1,2,3,4,5], 4);
  502. array_position
  503. ----------------
  504. 4
  505. (1 row)
  506. SELECT array_position(ARRAY[5,3,4,2,1], 4);
  507. array_position
  508. ----------------
  509. 3
  510. (1 row)
  511. SELECT array_position(ARRAY[[1,2],[3,4]], 3);
  512. ERROR: searching for elements in multidimensional arrays is not supported
  513. SELECT array_position(ARRAY['sun','mon','tue','wed','thu','fri','sat'], 'mon');
  514. array_position
  515. ----------------
  516. 2
  517. (1 row)
  518. SELECT array_position(ARRAY['sun','mon','tue','wed','thu','fri','sat'], 'sat');
  519. array_position
  520. ----------------
  521. 7
  522. (1 row)
  523. SELECT array_position(ARRAY['sun','mon','tue','wed','thu','fri','sat'], NULL);
  524. array_position
  525. ----------------
  526. (1 row)
  527. SELECT array_position(ARRAY['sun','mon','tue','wed','thu',NULL,'fri','sat'], NULL);
  528. array_position
  529. ----------------
  530. 6
  531. (1 row)
  532. SELECT array_position(ARRAY['sun','mon','tue','wed','thu',NULL,'fri','sat'], 'sat');
  533. array_position
  534. ----------------
  535. 8
  536. (1 row)
  537. SELECT array_positions(NULL, 10);
  538. array_positions
  539. -----------------
  540. (1 row)
  541. SELECT array_positions(NULL, NULL::int);
  542. array_positions
  543. -----------------
  544. (1 row)
  545. SELECT array_positions(ARRAY[1,2,3,4,5,6,1,2,3,4,5,6], 4);
  546. array_positions
  547. -----------------
  548. {4,10}
  549. (1 row)
  550. SELECT array_positions(ARRAY[[1,2],[3,4]], 4);
  551. ERROR: searching for elements in multidimensional arrays is not supported
  552. SELECT array_positions(ARRAY[1,2,3,4,5,6,1,2,3,4,5,6], NULL);
  553. array_positions
  554. -----------------
  555. {}
  556. (1 row)
  557. SELECT array_positions(ARRAY[1,2,3,NULL,5,6,1,2,3,NULL,5,6], NULL);
  558. array_positions
  559. -----------------
  560. {4,10}
  561. (1 row)
  562. SELECT array_length(array_positions(ARRAY(SELECT 'AAAAAAAAAAAAAAAAAAAAAAAAA'::text || i % 10
  563. FROM generate_series(1,100) g(i)),
  564. 'AAAAAAAAAAAAAAAAAAAAAAAAA5'), 1);
  565. array_length
  566. --------------
  567. 10
  568. (1 row)
  569. DO $$
  570. DECLARE
  571. o int;
  572. a int[] := ARRAY[1,2,3,2,3,1,2];
  573. BEGIN
  574. o := array_position(a, 2);
  575. WHILE o IS NOT NULL
  576. LOOP
  577. RAISE NOTICE '%', o;
  578. o := array_position(a, 2, o + 1);
  579. END LOOP;
  580. END
  581. $$ LANGUAGE plpgsql;
  582. NOTICE: 2
  583. NOTICE: 4
  584. NOTICE: 7
  585. SELECT array_position('[2:4]={1,2,3}'::int[], 1);
  586. array_position
  587. ----------------
  588. 2
  589. (1 row)
  590. SELECT array_positions('[2:4]={1,2,3}'::int[], 1);
  591. array_positions
  592. -----------------
  593. {2}
  594. (1 row)
  595. SELECT
  596. array_position(ids, (1, 1)),
  597. array_positions(ids, (1, 1))
  598. FROM
  599. (VALUES
  600. (ARRAY[(0, 0), (1, 1)]),
  601. (ARRAY[(1, 1)])
  602. ) AS f (ids);
  603. array_position | array_positions
  604. ----------------+-----------------
  605. 2 | {2}
  606. 1 | {1}
  607. (2 rows)
  608. -- operators
  609. SELECT a FROM arrtest WHERE b = ARRAY[[[113,142],[1,147]]];
  610. a
  611. ---------------
  612. {16,25,3,4,5}
  613. (1 row)
  614. SELECT NOT ARRAY[1.1,1.2,1.3] = ARRAY[1.1,1.2,1.3] AS "FALSE";
  615. FALSE
  616. -------
  617. f
  618. (1 row)
  619. SELECT ARRAY[1,2] || 3 AS "{1,2,3}";
  620. {1,2,3}
  621. ---------
  622. {1,2,3}
  623. (1 row)
  624. SELECT 0 || ARRAY[1,2] AS "{0,1,2}";
  625. {0,1,2}
  626. ---------
  627. {0,1,2}
  628. (1 row)
  629. SELECT ARRAY[1,2] || ARRAY[3,4] AS "{1,2,3,4}";
  630. {1,2,3,4}
  631. -----------
  632. {1,2,3,4}
  633. (1 row)
  634. SELECT ARRAY[[['hello','world']]] || ARRAY[[['happy','birthday']]] AS "ARRAY";
  635. ARRAY
  636. --------------------------------------
  637. {{{hello,world}},{{happy,birthday}}}
  638. (1 row)
  639. SELECT ARRAY[[1,2],[3,4]] || ARRAY[5,6] AS "{{1,2},{3,4},{5,6}}";
  640. {{1,2},{3,4},{5,6}}
  641. ---------------------
  642. {{1,2},{3,4},{5,6}}
  643. (1 row)
  644. SELECT ARRAY[0,0] || ARRAY[1,1] || ARRAY[2,2] AS "{0,0,1,1,2,2}";
  645. {0,0,1,1,2,2}
  646. ---------------
  647. {0,0,1,1,2,2}
  648. (1 row)
  649. SELECT 0 || ARRAY[1,2] || 3 AS "{0,1,2,3}";
  650. {0,1,2,3}
  651. -----------
  652. {0,1,2,3}
  653. (1 row)
  654. SELECT ARRAY[1.1] || ARRAY[2,3,4];
  655. ?column?
  656. -------------
  657. {1.1,2,3,4}
  658. (1 row)
  659. SELECT array_agg(x) || array_agg(x) FROM (VALUES (ROW(1,2)), (ROW(3,4))) v(x);
  660. ?column?
  661. -----------------------------------
  662. {"(1,2)","(3,4)","(1,2)","(3,4)"}
  663. (1 row)
  664. SELECT ROW(1,2) || array_agg(x) FROM (VALUES (ROW(3,4)), (ROW(5,6))) v(x);
  665. ?column?
  666. ---------------------------
  667. {"(1,2)","(3,4)","(5,6)"}
  668. (1 row)
  669. SELECT * FROM array_op_test WHERE i @> '{32}' ORDER BY seqno;
  670. seqno | i | t
  671. -------+---------------------------------+------------------------------------------------------------------------------------------------------------------------------------
  672. 6 | {39,35,5,94,17,92,60,32} | {AAAAAAAAAAAAAAA35875,AAAAAAAAAAAAAAAA23657}
  673. 74 | {32} | {AAAAAAAAAAAAAAAA1729,AAAAAAAAAAAAA22860,AAAAAA99807,AAAAA17383,AAAAAAAAAAAAAAA67062,AAAAAAAAAAA15165,AAAAAAAAAAA50956}
  674. 77 | {97,15,32,17,55,59,18,37,50,39} | {AAAAAAAAAAAA67946,AAAAAA54032,AAAAAAAA81587,55847,AAAAAAAAAAAAAA28620,AAAAAAAAAAAAAAAAA43052,AAAAAA75463,AAAA49534,AAAAAAAA44066}
  675. 89 | {40,32,17,6,30,88} | {AA44673,AAAAAAAAAAA6119,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAAAAAAAA47955,AAAAAAAAAAAAAAAA33598,AAAAAAAAAAA33576,AA44673}
  676. 98 | {38,34,32,89} | {AAAAAAAAAAAAAAAAAA71621,AAAA8857,AAAAAAAAAAAAAAAAAAA65037,AAAAAAAAAAAAAAAA31334,AAAAAAAAAA48845}
  677. 100 | {85,32,57,39,49,84,32,3,30} | {AAAAAAA80240,AAAAAAAAAAAAAAAA1729,AAAAA60038,AAAAAAAAAAA92631,AAAAAAAA9523}
  678. (6 rows)
  679. SELECT * FROM array_op_test WHERE i && '{32}' ORDER BY seqno;
  680. seqno | i | t
  681. -------+---------------------------------+------------------------------------------------------------------------------------------------------------------------------------
  682. 6 | {39,35,5,94,17,92,60,32} | {AAAAAAAAAAAAAAA35875,AAAAAAAAAAAAAAAA23657}
  683. 74 | {32} | {AAAAAAAAAAAAAAAA1729,AAAAAAAAAAAAA22860,AAAAAA99807,AAAAA17383,AAAAAAAAAAAAAAA67062,AAAAAAAAAAA15165,AAAAAAAAAAA50956}
  684. 77 | {97,15,32,17,55,59,18,37,50,39} | {AAAAAAAAAAAA67946,AAAAAA54032,AAAAAAAA81587,55847,AAAAAAAAAAAAAA28620,AAAAAAAAAAAAAAAAA43052,AAAAAA75463,AAAA49534,AAAAAAAA44066}
  685. 89 | {40,32,17,6,30,88} | {AA44673,AAAAAAAAAAA6119,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAAAAAAAA47955,AAAAAAAAAAAAAAAA33598,AAAAAAAAAAA33576,AA44673}
  686. 98 | {38,34,32,89} | {AAAAAAAAAAAAAAAAAA71621,AAAA8857,AAAAAAAAAAAAAAAAAAA65037,AAAAAAAAAAAAAAAA31334,AAAAAAAAAA48845}
  687. 100 | {85,32,57,39,49,84,32,3,30} | {AAAAAAA80240,AAAAAAAAAAAAAAAA1729,AAAAA60038,AAAAAAAAAAA92631,AAAAAAAA9523}
  688. (6 rows)
  689. SELECT * FROM array_op_test WHERE i @> '{17}' ORDER BY seqno;
  690. seqno | i | t
  691. -------+---------------------------------+------------------------------------------------------------------------------------------------------------------------------------
  692. 6 | {39,35,5,94,17,92,60,32} | {AAAAAAAAAAAAAAA35875,AAAAAAAAAAAAAAAA23657}
  693. 12 | {17,99,18,52,91,72,0,43,96,23} | {AAAAA33250,AAAAAAAAAAAAAAAAAAA85420,AAAAAAAAAAA33576}
  694. 15 | {17,14,16,63,67} | {AA6416,AAAAAAAAAA646,AAAAA95309}
  695. 19 | {52,82,17,74,23,46,69,51,75} | {AAAAAAAAAAAAA73084,AAAAA75968,AAAAAAAAAAAAAAAA14047,AAAAAAA80240,AAAAAAAAAAAAAAAAAAA1205,A68938}
  696. 53 | {38,17} | {AAAAAAAAAAA21658}
  697. 65 | {61,5,76,59,17} | {AAAAAA99807,AAAAA64741,AAAAAAAAAAA53908,AA21643,AAAAAAAAA10012}
  698. 77 | {97,15,32,17,55,59,18,37,50,39} | {AAAAAAAAAAAA67946,AAAAAA54032,AAAAAAAA81587,55847,AAAAAAAAAAAAAA28620,AAAAAAAAAAAAAAAAA43052,AAAAAA75463,AAAA49534,AAAAAAAA44066}
  699. 89 | {40,32,17,6,30,88} | {AA44673,AAAAAAAAAAA6119,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAAAAAAAA47955,AAAAAAAAAAAAAAAA33598,AAAAAAAAAAA33576,AA44673}
  700. (8 rows)
  701. SELECT * FROM array_op_test WHERE i && '{17}' ORDER BY seqno;
  702. seqno | i | t
  703. -------+---------------------------------+------------------------------------------------------------------------------------------------------------------------------------
  704. 6 | {39,35,5,94,17,92,60,32} | {AAAAAAAAAAAAAAA35875,AAAAAAAAAAAAAAAA23657}
  705. 12 | {17,99,18,52,91,72,0,43,96,23} | {AAAAA33250,AAAAAAAAAAAAAAAAAAA85420,AAAAAAAAAAA33576}
  706. 15 | {17,14,16,63,67} | {AA6416,AAAAAAAAAA646,AAAAA95309}
  707. 19 | {52,82,17,74,23,46,69,51,75} | {AAAAAAAAAAAAA73084,AAAAA75968,AAAAAAAAAAAAAAAA14047,AAAAAAA80240,AAAAAAAAAAAAAAAAAAA1205,A68938}
  708. 53 | {38,17} | {AAAAAAAAAAA21658}
  709. 65 | {61,5,76,59,17} | {AAAAAA99807,AAAAA64741,AAAAAAAAAAA53908,AA21643,AAAAAAAAA10012}
  710. 77 | {97,15,32,17,55,59,18,37,50,39} | {AAAAAAAAAAAA67946,AAAAAA54032,AAAAAAAA81587,55847,AAAAAAAAAAAAAA28620,AAAAAAAAAAAAAAAAA43052,AAAAAA75463,AAAA49534,AAAAAAAA44066}
  711. 89 | {40,32,17,6,30,88} | {AA44673,AAAAAAAAAAA6119,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAAAAAAAA47955,AAAAAAAAAAAAAAAA33598,AAAAAAAAAAA33576,AA44673}
  712. (8 rows)
  713. SELECT * FROM array_op_test WHERE i @> '{32,17}' ORDER BY seqno;
  714. seqno | i | t
  715. -------+---------------------------------+------------------------------------------------------------------------------------------------------------------------------------
  716. 6 | {39,35,5,94,17,92,60,32} | {AAAAAAAAAAAAAAA35875,AAAAAAAAAAAAAAAA23657}
  717. 77 | {97,15,32,17,55,59,18,37,50,39} | {AAAAAAAAAAAA67946,AAAAAA54032,AAAAAAAA81587,55847,AAAAAAAAAAAAAA28620,AAAAAAAAAAAAAAAAA43052,AAAAAA75463,AAAA49534,AAAAAAAA44066}
  718. 89 | {40,32,17,6,30,88} | {AA44673,AAAAAAAAAAA6119,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAAAAAAAA47955,AAAAAAAAAAAAAAAA33598,AAAAAAAAAAA33576,AA44673}
  719. (3 rows)
  720. SELECT * FROM array_op_test WHERE i && '{32,17}' ORDER BY seqno;
  721. seqno | i | t
  722. -------+---------------------------------+------------------------------------------------------------------------------------------------------------------------------------
  723. 6 | {39,35,5,94,17,92,60,32} | {AAAAAAAAAAAAAAA35875,AAAAAAAAAAAAAAAA23657}
  724. 12 | {17,99,18,52,91,72,0,43,96,23} | {AAAAA33250,AAAAAAAAAAAAAAAAAAA85420,AAAAAAAAAAA33576}
  725. 15 | {17,14,16,63,67} | {AA6416,AAAAAAAAAA646,AAAAA95309}
  726. 19 | {52,82,17,74,23,46,69,51,75} | {AAAAAAAAAAAAA73084,AAAAA75968,AAAAAAAAAAAAAAAA14047,AAAAAAA80240,AAAAAAAAAAAAAAAAAAA1205,A68938}
  727. 53 | {38,17} | {AAAAAAAAAAA21658}
  728. 65 | {61,5,76,59,17} | {AAAAAA99807,AAAAA64741,AAAAAAAAAAA53908,AA21643,AAAAAAAAA10012}
  729. 74 | {32} | {AAAAAAAAAAAAAAAA1729,AAAAAAAAAAAAA22860,AAAAAA99807,AAAAA17383,AAAAAAAAAAAAAAA67062,AAAAAAAAAAA15165,AAAAAAAAAAA50956}
  730. 77 | {97,15,32,17,55,59,18,37,50,39} | {AAAAAAAAAAAA67946,AAAAAA54032,AAAAAAAA81587,55847,AAAAAAAAAAAAAA28620,AAAAAAAAAAAAAAAAA43052,AAAAAA75463,AAAA49534,AAAAAAAA44066}
  731. 89 | {40,32,17,6,30,88} | {AA44673,AAAAAAAAAAA6119,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAAAAAAAA47955,AAAAAAAAAAAAAAAA33598,AAAAAAAAAAA33576,AA44673}
  732. 98 | {38,34,32,89} | {AAAAAAAAAAAAAAAAAA71621,AAAA8857,AAAAAAAAAAAAAAAAAAA65037,AAAAAAAAAAAAAAAA31334,AAAAAAAAAA48845}
  733. 100 | {85,32,57,39,49,84,32,3,30} | {AAAAAAA80240,AAAAAAAAAAAAAAAA1729,AAAAA60038,AAAAAAAAAAA92631,AAAAAAAA9523}
  734. (11 rows)
  735. SELECT * FROM array_op_test WHERE i <@ '{38,34,32,89}' ORDER BY seqno;
  736. seqno | i | t
  737. -------+---------------+----------------------------------------------------------------------------------------------------------------------------
  738. 40 | {34} | {AAAAAAAAAAAAAA10611,AAAAAAAAAAAAAAAAAAA1205,AAAAAAAAAAA50956,AAAAAAAAAAAAAAAA31334,AAAAA70466,AAAAAAAA81587,AAAAAAA74623}
  739. 74 | {32} | {AAAAAAAAAAAAAAAA1729,AAAAAAAAAAAAA22860,AAAAAA99807,AAAAA17383,AAAAAAAAAAAAAAA67062,AAAAAAAAAAA15165,AAAAAAAAAAA50956}
  740. 98 | {38,34,32,89} | {AAAAAAAAAAAAAAAAAA71621,AAAA8857,AAAAAAAAAAAAAAAAAAA65037,AAAAAAAAAAAAAAAA31334,AAAAAAAAAA48845}
  741. 101 | {} | {}
  742. (4 rows)
  743. SELECT * FROM array_op_test WHERE i = '{}' ORDER BY seqno;
  744. seqno | i | t
  745. -------+----+----
  746. 101 | {} | {}
  747. (1 row)
  748. SELECT * FROM array_op_test WHERE i @> '{}' ORDER BY seqno;
  749. seqno | i | t
  750. -------+---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  751. 1 | {92,75,71,52,64,83} | {AAAAAAAA44066,AAAAAA1059,AAAAAAAAAAA176,AAAAAAA48038}
  752. 2 | {3,6} | {AAAAAA98232,AAAAAAAA79710,AAAAAAAAAAAAAAAAA69675,AAAAAAAAAAAAAAAA55798,AAAAAAAAA12793}
  753. 3 | {37,64,95,43,3,41,13,30,11,43} | {AAAAAAAAAA48845,AAAAA75968,AAAAA95309,AAA54451,AAAAAAAAAA22292,AAAAAAA99836,A96617,AA17009,AAAAAAAAAAAAAA95246}
  754. 4 | {71,39,99,55,33,75,45} | {AAAAAAAAA53663,AAAAAAAAAAAAAAA67062,AAAAAAAAAA64777,AAA99043,AAAAAAAAAAAAAAAAAAA91804,39557}
  755. 5 | {50,42,77,50,4} | {AAAAAAAAAAAAAAAAA26540,AAAAAAA79710,AAAAAAAAAAAAAAAAAAA1205,AAAAAAAAAAA176,AAAAA95309,AAAAAAAAAAA46154,AAAAAA66777,AAAAAAAAA27249,AAAAAAAAAA64777,AAAAAAAAAAAAAAAAAAA70104}
  756. 6 | {39,35,5,94,17,92,60,32} | {AAAAAAAAAAAAAAA35875,AAAAAAAAAAAAAAAA23657}
  757. 7 | {12,51,88,64,8} | {AAAAAAAAAAAAAAAAAA12591,AAAAAAAAAAAAAAAAA50407,AAAAAAAAAAAA67946}
  758. 8 | {60,84} | {AAAAAAA81898,AAAAAA1059,AAAAAAAAAAAA81511,AAAAA961,AAAAAAAAAAAAAAAA31334,AAAAA64741,AA6416,AAAAAAAAAAAAAAAAAA32918,AAAAAAAAAAAAAAAAA50407}
  759. 9 | {56,52,35,27,80,44,81,22} | {AAAAAAAAAAAAAAA73034,AAAAAAAAAAAAA7929,AAAAAAA66161,AA88409,39557,A27153,AAAAAAAA9523,AAAAAAAAAAA99000}
  760. 10 | {71,5,45} | {AAAAAAAAAAA21658,AAAAAAAAAAAA21089,AAA54451,AAAAAAAAAAAAAAAAAA54141,AAAAAAAAAAAAAA28620,AAAAAAAAAAA21658,AAAAAAAAAAA74076,AAAAAAAAA27249}
  761. 11 | {41,86,74,48,22,74,47,50} | {AAAAAAAA9523,AAAAAAAAAAAA37562,AAAAAAAAAAAAAAAA14047,AAAAAAAAAAA46154,AAAA41702,AAAAAAAAAAAAAAAAA764,AAAAA62737,39557}
  762. 12 | {17,99,18,52,91,72,0,43,96,23} | {AAAAA33250,AAAAAAAAAAAAAAAAAAA85420,AAAAAAAAAAA33576}
  763. 13 | {3,52,34,23} | {AAAAAA98232,AAAA49534,AAAAAAAAAAA21658}
  764. 14 | {78,57,19} | {AAAA8857,AAAAAAAAAAAAAAA73034,AAAAAAAA81587,AAAAAAAAAAAAAAA68526,AAAAA75968,AAAAAAAAAAAAAA65909,AAAAAAAAA10012,AAAAAAAAAAAAAA65909}
  765. 15 | {17,14,16,63,67} | {AA6416,AAAAAAAAAA646,AAAAA95309}
  766. 16 | {14,63,85,11} | {AAAAAA66777}
  767. 17 | {7,10,81,85} | {AAAAAA43678,AAAAAAA12144,AAAAAAAAAAA50956,AAAAAAAAAAAAAAAAAAA15356}
  768. 18 | {1} | {AAAAAAAAAAA33576,AAAAA95309,64261,AAA59323,AAAAAAAAAAAAAA95246,55847,AAAAAAAAAAAA67946,AAAAAAAAAAAAAAAAAA64374}
  769. 19 | {52,82,17,74,23,46,69,51,75} | {AAAAAAAAAAAAA73084,AAAAA75968,AAAAAAAAAAAAAAAA14047,AAAAAAA80240,AAAAAAAAAAAAAAAAAAA1205,A68938}
  770. 20 | {72,89,70,51,54,37,8,49,79} | {AAAAAA58494}
  771. 21 | {2,8,65,10,5,79,43} | {AAAAAAAAAAAAAAAAA88852,AAAAAAAAAAAAAAAAAAA91804,AAAAA64669,AAAAAAAAAAAAAAAA1443,AAAAAAAAAAAAAAAA23657,AAAAA12179,AAAAAAAAAAAAAAAAA88852,AAAAAAAAAAAAAAAA31334,AAAAAAAAAAAAAAAA41303,AAAAAAAAAAAAAAAAAAA85420}
  772. 22 | {11,6,56,62,53,30} | {AAAAAAAA72908}
  773. 23 | {40,90,5,38,72,40,30,10,43,55} | {A6053,AAAAAAAAAAA6119,AA44673,AAAAAAAAAAAAAAAAA764,AA17009,AAAAA17383,AAAAA70514,AAAAA33250,AAAAA95309,AAAAAAAAAAAA37562}
  774. 24 | {94,61,99,35,48} | {AAAAAAAAAAA50956,AAAAAAAAAAA15165,AAAA85070,AAAAAAAAAAAAAAA36627,AAAAA961,AAAAAAAAAA55219}
  775. 25 | {31,1,10,11,27,79,38} | {AAAAAAAAAAAAAAAAAA59334,45449}
  776. 26 | {71,10,9,69,75} | {47735,AAAAAAA21462,AAAAAAAAAAAAAAAAA6897,AAAAAAAAAAAAAAAAAAA91804,AAAAAAAAA72121,AAAAAAAAAAAAAAAAAAA1205,AAAAA41597,AAAA8857,AAAAAAAAAAAAAAAAAAA15356,AA17009}
  777. 27 | {94} | {AA6416,A6053,AAAAAAA21462,AAAAAAA57334,AAAAAAAAAAAAAAAAAA12591,AA88409,AAAAAAAAAAAAA70254}
  778. 28 | {14,33,6,34,14} | {AAAAAAAAAAAAAAA13198,AAAAAAAA69452,AAAAAAAAAAA82945,AAAAAAA12144,AAAAAAAAA72121,AAAAAAAAAA18601}
  779. 29 | {39,21} | {AAAAAAAAAAAAAAAAA6897,AAAAAAAAAAAAAAAAAAA38885,AAAA85070,AAAAAAAAAAAAAAAAAAA70104,AAAAA66674,AAAAAAAAAAAAA62007,AAAAAAAA69452,AAAAAAA1242,AAAAAAAAAAAAAAAA1729,AAAA35194}
  780. 30 | {26,81,47,91,34} | {AAAAAAAAAAAAAAAAAAA70104,AAAAAAA80240}
  781. 31 | {80,24,18,21,54} | {AAAAAAAAAAAAAAA13198,AAAAAAAAAAAAAAAAAAA70415,A27153,AAAAAAAAA53663,AAAAAAAAAAAAAAAAA50407,A68938}
  782. 32 | {58,79,82,80,67,75,98,10,41} | {AAAAAAAAAAAAAAAAAA61286,AAA54451,AAAAAAAAAAAAAAAAAAA87527,A96617,51533}
  783. 33 | {74,73} | {A85417,AAAAAAA56483,AAAAA17383,AAAAAAAAAAAAA62159,AAAAAAAAAAAA52814,AAAAAAAAAAAAA85723,AAAAAAAAAAAAAAAAAA55796}
  784. 34 | {70,45} | {AAAAAAAAAAAAAAAAAA71621,AAAAAAAAAAAAAA28620,AAAAAAAAAA55219,AAAAAAAA23648,AAAAAAAAAA22292,AAAAAAA1242}
  785. 35 | {23,40} | {AAAAAAAAAAAA52814,AAAA48949,AAAAAAAAA34727,AAAA8857,AAAAAAAAAAAAAAAAAAA62179,AAAAAAAAAAAAAAA68526,AAAAAAA99836,AAAAAAAA50094,AAAA91194,AAAAAAAAAAAAA73084}
  786. 36 | {79,82,14,52,30,5,79} | {AAAAAAAAA53663,AAAAAAAAAAAAAAAA55798,AAAAAAAAAAAAAAAAAAA89194,AA88409,AAAAAAAAAAAAAAA81326,AAAAAAAAAAAAAAAAA63050,AAAAAAAAAAAAAAAA33598}
  787. 37 | {53,11,81,39,3,78,58,64,74} | {AAAAAAAAAAAAAAAAAAA17075,AAAAAAA66161,AAAAAAAA23648,AAAAAAAAAAAAAA10611}
  788. 38 | {59,5,4,95,28} | {AAAAAAAAAAA82945,A96617,47735,AAAAA12179,AAAAA64669,AAAAAA99807,AA74433,AAAAAAAAAAAAAAAAA59387}
  789. 39 | {82,43,99,16,74} | {AAAAAAAAAAAAAAA67062,AAAAAAA57334,AAAAAAAAAAAAAA65909,A27153,AAAAAAAAAAAAAAAAAAA17075,AAAAAAAAAAAAAAAAA43052,AAAAAAAAAA64777,AAAAAAAAAAAA81511,AAAAAAAAAAAAAA65909,AAAAAAAAAAAAAA28620}
  790. 40 | {34} | {AAAAAAAAAAAAAA10611,AAAAAAAAAAAAAAAAAAA1205,AAAAAAAAAAA50956,AAAAAAAAAAAAAAAA31334,AAAAA70466,AAAAAAAA81587,AAAAAAA74623}
  791. 41 | {19,26,63,12,93,73,27,94} | {AAAAAAA79710,AAAAAAAAAA55219,AAAA41702,AAAAAAAAAAAAAAAAAAA17075,AAAAAAAAAAAAAAAAAA71621,AAAAAAAAAAAAAAAAA63050,AAAAAAA99836,AAAAAAAAAAAAAA8666}
  792. 42 | {15,76,82,75,8,91} | {AAAAAAAAAAA176,AAAAAA38063,45449,AAAAAA54032,AAAAAAA81898,AA6416,AAAAAAAAAAAAAAAAAAA62179,45449,AAAAA60038,AAAAAAAA81587}
  793. 43 | {39,87,91,97,79,28} | {AAAAAAAAAAA74076,A96617,AAAAAAAAAAAAAAAAAAA89194,AAAAAAAAAAAAAAAAAA55796,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAA67946}
  794. 44 | {40,58,68,29,54} | {AAAAAAA81898,AAAAAA66777,AAAAAA98232}
  795. 45 | {99,45} | {AAAAAAAA72908,AAAAAAAAAAAAAAAAAAA17075,AA88409,AAAAAAAAAAAAAAAAAA36842,AAAAAAA48038,AAAAAAAAAAAAAA10611}
  796. 46 | {53,24} | {AAAAAAAAAAA53908,AAAAAA54032,AAAAA17383,AAAA48949,AAAAAAAAAA18601,AAAAA64669,45449,AAAAAAAAAAA98051,AAAAAAAAAAAAAAAAAA71621}
  797. 47 | {98,23,64,12,75,61} | {AAA59323,AAAAA95309,AAAAAAAAAAAAAAAA31334,AAAAAAAAA27249,AAAAA17383,AAAAAAAAAAAA37562,AAAAAA1059,A84822,55847,AAAAA70466}
  798. 48 | {76,14} | {AAAAAAAAAAAAA59671,AAAAAAAAAAAAAAAAAAA91804,AAAAAA66777,AAAAAAAAAAAAAAAAAAA89194,AAAAAAAAAAAAAAA36627,AAAAAAAAAAAAAAAAAAA17075,AAAAAAAAAAAAA73084,AAAAAAA79710,AAAAAAAAAAAAAAA40402,AAAAAAAAAAAAAAAAAAA65037}
  799. 49 | {56,5,54,37,49} | {AA21643,AAAAAAAAAAA92631,AAAAAAAA81587}
  800. 50 | {20,12,37,64,93} | {AAAAAAAAAA5483,AAAAAAAAAAAAAAAAAAA1205,AA6416,AAAAAAAAAAAAAAAAA63050,AAAAAAAAAAAAAAAAAA47955}
  801. 51 | {47} | {AAAAAAAAAAAAAA96505,AAAAAAAAAAAAAAAAAA36842,AAAAA95309,AAAAAAAA81587,AA6416,AAAA91194,AAAAAA58494,AAAAAA1059,AAAAAAAA69452}
  802. 52 | {89,0} | {AAAAAAAAAAAAAAAAAA47955,AAAAAAA48038,AAAAAAAAAAAAAAAAA43052,AAAAAAAAAAAAA73084,AAAAA70466,AAAAAAAAAAAAAAAAA764,AAAAAAAAAAA46154,AA66862}
  803. 53 | {38,17} | {AAAAAAAAAAA21658}
  804. 54 | {70,47} | {AAAAAAAAAAAAAAAAAA54141,AAAAA40681,AAAAAAA48038,AAAAAAAAAAAAAAAA29150,AAAAA41597,AAAAAAAAAAAAAAAAAA59334,AA15322}
  805. 55 | {47,79,47,64,72,25,71,24,93} | {AAAAAAAAAAAAAAAAAA55796,AAAAA62737}
  806. 56 | {33,7,60,54,93,90,77,85,39} | {AAAAAAAAAAAAAAAAAA32918,AA42406}
  807. 57 | {23,45,10,42,36,21,9,96} | {AAAAAAAAAAAAAAAAAAA70415}
  808. 58 | {92} | {AAAAAAAAAAAAAAAA98414,AAAAAAAA23648,AAAAAAAAAAAAAAAAAA55796,AA25381,AAAAAAAAAAA6119}
  809. 59 | {9,69,46,77} | {39557,AAAAAAA89932,AAAAAAAAAAAAAAAAA43052,AAAAAAAAAAAAAAAAA26540,AAA20874,AA6416,AAAAAAAAAAAAAAAAAA47955}
  810. 60 | {62,2,59,38,89} | {AAAAAAA89932,AAAAAAAAAAAAAAAAAAA15356,AA99927,AA17009,AAAAAAAAAAAAAAA35875}
  811. 61 | {72,2,44,95,54,54,13} | {AAAAAAAAAAAAAAAAAAA91804}
  812. 62 | {83,72,29,73} | {AAAAAAAAAAAAA15097,AAAA8857,AAAAAAAAAAAA35809,AAAAAAAAAAAA52814,AAAAAAAAAAAAAAAAAAA38885,AAAAAAAAAAAAAAAAAA24183,AAAAAA43678,A96617}
  813. 63 | {11,4,61,87} | {AAAAAAAAA27249,AAAAAAAAAAAAAAAAAA32918,AAAAAAAAAAAAAAA13198,AAA20874,39557,51533,AAAAAAAAAAA53908,AAAAAAAAAAAAAA96505,AAAAAAAA78938}
  814. 64 | {26,19,34,24,81,78} | {A96617,AAAAAAAAAAAAAAAAAAA70104,A68938,AAAAAAAAAAA53908,AAAAAAAAAAAAAAA453,AA17009,AAAAAAA80240}
  815. 65 | {61,5,76,59,17} | {AAAAAA99807,AAAAA64741,AAAAAAAAAAA53908,AA21643,AAAAAAAAA10012}
  816. 66 | {31,23,70,52,4,33,48,25} | {AAAAAAAAAAAAAAAAA69675,AAAAAAAA50094,AAAAAAAAAAA92631,AAAA35194,39557,AAAAAAA99836}
  817. 67 | {31,94,7,10} | {AAAAAA38063,A96617,AAAA35194,AAAAAAAAAAAA67946}
  818. 68 | {90,43,38} | {AA75092,AAAAAAAAAAAAAAAAA69675,AAAAAAAAAAA92631,AAAAAAAAA10012,AAAAAAAAAAAAA7929,AA21643}
  819. 69 | {67,35,99,85,72,86,44} | {AAAAAAAAAAAAAAAAAAA1205,AAAAAAAA50094,AAAAAAAAAAAAAAAA1729,AAAAAAAAAAAAAAAAAA47955}
  820. 70 | {56,70,83} | {AAAA41702,AAAAAAAAAAA82945,AA21643,AAAAAAAAAAA99000,A27153,AA25381,AAAAAAAAAAAAAA96505,AAAAAAA1242}
  821. 71 | {74,26} | {AAAAAAAAAAA50956,AA74433,AAAAAAA21462,AAAAAAAAAAAAAAAAAAA17075,AAAAAAAAAAAAAAA36627,AAAAAAAAAAAAA70254,AAAAAAAAAA43419,39557}
  822. 72 | {22,1,16,78,20,91,83} | {47735,AAAAAAA56483,AAAAAAAAAAAAA93788,AA42406,AAAAAAAAAAAAA73084,AAAAAAAA72908,AAAAAAAAAAAAAAAAAA61286,AAAAA66674,AAAAAAAAAAAAAAAAA50407}
  823. 73 | {88,25,96,78,65,15,29,19} | {AAA54451,AAAAAAAAA27249,AAAAAAA9228,AAAAAAAAAAAAAAA67062,AAAAAAAAAAAAAAAAAAA70415,AAAAA17383,AAAAAAAAAAAAAAAA33598}
  824. 74 | {32} | {AAAAAAAAAAAAAAAA1729,AAAAAAAAAAAAA22860,AAAAAA99807,AAAAA17383,AAAAAAAAAAAAAAA67062,AAAAAAAAAAA15165,AAAAAAAAAAA50956}
  825. 75 | {12,96,83,24,71,89,55} | {AAAA48949,AAAAAAAA29716,AAAAAAAAAAAAAAAAAAA1205,AAAAAAAAAAAA67946,AAAAAAAAAAAAAAAA29150,AAA28075,AAAAAAAAAAAAAAAAA43052}
  826. 76 | {92,55,10,7} | {AAAAAAAAAAAAAAA67062}
  827. 77 | {97,15,32,17,55,59,18,37,50,39} | {AAAAAAAAAAAA67946,AAAAAA54032,AAAAAAAA81587,55847,AAAAAAAAAAAAAA28620,AAAAAAAAAAAAAAAAA43052,AAAAAA75463,AAAA49534,AAAAAAAA44066}
  828. 78 | {55,89,44,84,34} | {AAAAAAAAAAA6119,AAAAAAAAAAAAAA8666,AA99927,AA42406,AAAAAAA81898,AAAAAAA9228,AAAAAAAAAAA92631,AA21643,AAAAAAAAAAAAAA28620}
  829. 79 | {45} | {AAAAAAAAAA646,AAAAAAAAAAAAAAAAAAA70415,AAAAAA43678,AAAAAAAA72908}
  830. 80 | {74,89,44,80,0} | {AAAA35194,AAAAAAAA79710,AAA20874,AAAAAAAAAAAAAAAAAAA70104,AAAAAAAAAAAAA73084,AAAAAAA57334,AAAAAAA9228,AAAAAAAAAAAAA62007}
  831. 81 | {63,77,54,48,61,53,97} | {AAAAAAAAAAAAAAA81326,AAAAAAAAAA22292,AA25381,AAAAAAAAAAA74076,AAAAAAA81898,AAAAAAAAA72121}
  832. 82 | {34,60,4,79,78,16,86,89,42,50} | {AAAAA40681,AAAAAAAAAAAAAAAAAA12591,AAAAAAA80240,AAAAAAAAAAAAAAAA55798,AAAAAAAAAAAAAAAAAAA70104}
  833. 83 | {14,10} | {AAAAAAAAAA22292,AAAAAAAAAAAAA70254,AAAAAAAAAAA6119}
  834. 84 | {11,83,35,13,96,94} | {AAAAA95309,AAAAAAAAAAAAAAAAAA32918,AAAAAAAAAAAAAAAAAA24183}
  835. 85 | {39,60} | {AAAAAAAAAAAAAAAA55798,AAAAAAAAAA22292,AAAAAAA66161,AAAAAAA21462,AAAAAAAAAAAAAAAAAA12591,55847,AAAAAA98232,AAAAAAAAAAA46154}
  836. 86 | {33,81,72,74,45,36,82} | {AAAAAAAA81587,AAAAAAAAAAAAAA96505,45449,AAAA80176}
  837. 87 | {57,27,50,12,97,68} | {AAAAAAAAAAAAAAAAA26540,AAAAAAAAA10012,AAAAAAAAAAAA35809,AAAAAAAAAAAAAAAA29150,AAAAAAAAAAA82945,AAAAAA66777,31228,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAAAA28620,AAAAAAAAAAAAAA96505}
  838. 88 | {41,90,77,24,6,24} | {AAAA35194,AAAA35194,AAAAAAA80240,AAAAAAAAAAA46154,AAAAAA58494,AAAAAAAAAAAAAAAAAAA17075,AAAAAAAAAAAAAAAAAA59334,AAAAAAAAAAAAAAAAAAA91804,AA74433}
  839. 89 | {40,32,17,6,30,88} | {AA44673,AAAAAAAAAAA6119,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAAAAAAAA47955,AAAAAAAAAAAAAAAA33598,AAAAAAAAAAA33576,AA44673}
  840. 90 | {88,75} | {AAAAA60038,AAAAAAAA23648,AAAAAAAAAAA99000,AAAA41702,AAAAAAAAAAAAA22860,AAAAAAAAAAAAAAA68526}
  841. 91 | {78} | {AAAAAAAAAAAAA62007,AAA99043}
  842. 92 | {85,63,49,45} | {AAAAAAA89932,AAAAAAAAAAAAA22860,AAAAAAAAAAAAAAAAAAA1205,AAAAAAAAAAAA21089}
  843. 93 | {11} | {AAAAAAAAAAA176,AAAAAAAAAAAAAA8666,AAAAAAAAAAAAAAA453,AAAAAAAAAAAAA85723,A68938,AAAAAAAAAAAAA9821,AAAAAAA48038,AAAAAAAAAAAAAAAAA59387,AA99927,AAAAA17383}
  844. 94 | {98,9,85,62,88,91,60,61,38,86} | {AAAAAAAA81587,AAAAA17383,AAAAAAAA81587}
  845. 95 | {47,77} | {AAAAAAAAAAAAAAAAA764,AAAAAAAAAAA74076,AAAAAAAAAA18107,AAAAA40681,AAAAAAAAAAAAAAA35875,AAAAA60038,AAAAAAA56483}
  846. 96 | {23,97,43} | {AAAAAAAAAA646,A87088}
  847. 97 | {54,2,86,65} | {47735,AAAAAAA99836,AAAAAAAAAAAAAAAAA6897,AAAAAAAAAAAAAAAA29150,AAAAAAA80240,AAAAAAAAAAAAAAAA98414,AAAAAAA56483,AAAAAAAAAAAAAAAA29150,AAAAAAA39692,AA21643}
  848. 98 | {38,34,32,89} | {AAAAAAAAAAAAAAAAAA71621,AAAA8857,AAAAAAAAAAAAAAAAAAA65037,AAAAAAAAAAAAAAAA31334,AAAAAAAAAA48845}
  849. 99 | {37,86} | {AAAAAAAAAAAAAAAAAA32918,AAAAA70514,AAAAAAAAA10012,AAAAAAAAAAAAAAAAA59387,AAAAAAAAAA64777,AAAAAAAAAAAAAAAAAAA15356}
  850. 100 | {85,32,57,39,49,84,32,3,30} | {AAAAAAA80240,AAAAAAAAAAAAAAAA1729,AAAAA60038,AAAAAAAAAAA92631,AAAAAAAA9523}
  851. 101 | {} | {}
  852. 102 | {NULL} | {NULL}
  853. (102 rows)
  854. SELECT * FROM array_op_test WHERE i && '{}' ORDER BY seqno;
  855. seqno | i | t
  856. -------+---+---
  857. (0 rows)
  858. SELECT * FROM array_op_test WHERE i <@ '{}' ORDER BY seqno;
  859. seqno | i | t
  860. -------+----+----
  861. 101 | {} | {}
  862. (1 row)
  863. SELECT * FROM array_op_test WHERE i = '{NULL}' ORDER BY seqno;
  864. seqno | i | t
  865. -------+--------+--------
  866. 102 | {NULL} | {NULL}
  867. (1 row)
  868. SELECT * FROM array_op_test WHERE i @> '{NULL}' ORDER BY seqno;
  869. seqno | i | t
  870. -------+---+---
  871. (0 rows)
  872. SELECT * FROM array_op_test WHERE i && '{NULL}' ORDER BY seqno;
  873. seqno | i | t
  874. -------+---+---
  875. (0 rows)
  876. SELECT * FROM array_op_test WHERE i <@ '{NULL}' ORDER BY seqno;
  877. seqno | i | t
  878. -------+----+----
  879. 101 | {} | {}
  880. (1 row)
  881. SELECT * FROM array_op_test WHERE t @> '{AAAAAAAA72908}' ORDER BY seqno;
  882. seqno | i | t
  883. -------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------
  884. 22 | {11,6,56,62,53,30} | {AAAAAAAA72908}
  885. 45 | {99,45} | {AAAAAAAA72908,AAAAAAAAAAAAAAAAAAA17075,AA88409,AAAAAAAAAAAAAAAAAA36842,AAAAAAA48038,AAAAAAAAAAAAAA10611}
  886. 72 | {22,1,16,78,20,91,83} | {47735,AAAAAAA56483,AAAAAAAAAAAAA93788,AA42406,AAAAAAAAAAAAA73084,AAAAAAAA72908,AAAAAAAAAAAAAAAAAA61286,AAAAA66674,AAAAAAAAAAAAAAAAA50407}
  887. 79 | {45} | {AAAAAAAAAA646,AAAAAAAAAAAAAAAAAAA70415,AAAAAA43678,AAAAAAAA72908}
  888. (4 rows)
  889. SELECT * FROM array_op_test WHERE t && '{AAAAAAAA72908}' ORDER BY seqno;
  890. seqno | i | t
  891. -------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------
  892. 22 | {11,6,56,62,53,30} | {AAAAAAAA72908}
  893. 45 | {99,45} | {AAAAAAAA72908,AAAAAAAAAAAAAAAAAAA17075,AA88409,AAAAAAAAAAAAAAAAAA36842,AAAAAAA48038,AAAAAAAAAAAAAA10611}
  894. 72 | {22,1,16,78,20,91,83} | {47735,AAAAAAA56483,AAAAAAAAAAAAA93788,AA42406,AAAAAAAAAAAAA73084,AAAAAAAA72908,AAAAAAAAAAAAAAAAAA61286,AAAAA66674,AAAAAAAAAAAAAAAAA50407}
  895. 79 | {45} | {AAAAAAAAAA646,AAAAAAAAAAAAAAAAAAA70415,AAAAAA43678,AAAAAAAA72908}
  896. (4 rows)
  897. SELECT * FROM array_op_test WHERE t @> '{AAAAAAAAAA646}' ORDER BY seqno;
  898. seqno | i | t
  899. -------+------------------+--------------------------------------------------------------------
  900. 15 | {17,14,16,63,67} | {AA6416,AAAAAAAAAA646,AAAAA95309}
  901. 79 | {45} | {AAAAAAAAAA646,AAAAAAAAAAAAAAAAAAA70415,AAAAAA43678,AAAAAAAA72908}
  902. 96 | {23,97,43} | {AAAAAAAAAA646,A87088}
  903. (3 rows)
  904. SELECT * FROM array_op_test WHERE t && '{AAAAAAAAAA646}' ORDER BY seqno;
  905. seqno | i | t
  906. -------+------------------+--------------------------------------------------------------------
  907. 15 | {17,14,16,63,67} | {AA6416,AAAAAAAAAA646,AAAAA95309}
  908. 79 | {45} | {AAAAAAAAAA646,AAAAAAAAAAAAAAAAAAA70415,AAAAAA43678,AAAAAAAA72908}
  909. 96 | {23,97,43} | {AAAAAAAAAA646,A87088}
  910. (3 rows)
  911. SELECT * FROM array_op_test WHERE t @> '{AAAAAAAA72908,AAAAAAAAAA646}' ORDER BY seqno;
  912. seqno | i | t
  913. -------+------+--------------------------------------------------------------------
  914. 79 | {45} | {AAAAAAAAAA646,AAAAAAAAAAAAAAAAAAA70415,AAAAAA43678,AAAAAAAA72908}
  915. (1 row)
  916. SELECT * FROM array_op_test WHERE t && '{AAAAAAAA72908,AAAAAAAAAA646}' ORDER BY seqno;
  917. seqno | i | t
  918. -------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------
  919. 15 | {17,14,16,63,67} | {AA6416,AAAAAAAAAA646,AAAAA95309}
  920. 22 | {11,6,56,62,53,30} | {AAAAAAAA72908}
  921. 45 | {99,45} | {AAAAAAAA72908,AAAAAAAAAAAAAAAAAAA17075,AA88409,AAAAAAAAAAAAAAAAAA36842,AAAAAAA48038,AAAAAAAAAAAAAA10611}
  922. 72 | {22,1,16,78,20,91,83} | {47735,AAAAAAA56483,AAAAAAAAAAAAA93788,AA42406,AAAAAAAAAAAAA73084,AAAAAAAA72908,AAAAAAAAAAAAAAAAAA61286,AAAAA66674,AAAAAAAAAAAAAAAAA50407}
  923. 79 | {45} | {AAAAAAAAAA646,AAAAAAAAAAAAAAAAAAA70415,AAAAAA43678,AAAAAAAA72908}
  924. 96 | {23,97,43} | {AAAAAAAAAA646,A87088}
  925. (6 rows)
  926. SELECT * FROM array_op_test WHERE t <@ '{AAAAAAAA72908,AAAAAAAAAAAAAAAAAAA17075,AA88409,AAAAAAAAAAAAAAAAAA36842,AAAAAAA48038,AAAAAAAAAAAAAA10611}' ORDER BY seqno;
  927. seqno | i | t
  928. -------+--------------------+-----------------------------------------------------------------------------------------------------------
  929. 22 | {11,6,56,62,53,30} | {AAAAAAAA72908}
  930. 45 | {99,45} | {AAAAAAAA72908,AAAAAAAAAAAAAAAAAAA17075,AA88409,AAAAAAAAAAAAAAAAAA36842,AAAAAAA48038,AAAAAAAAAAAAAA10611}
  931. 101 | {} | {}
  932. (3 rows)
  933. SELECT * FROM array_op_test WHERE t = '{}' ORDER BY seqno;
  934. seqno | i | t
  935. -------+----+----
  936. 101 | {} | {}
  937. (1 row)
  938. SELECT * FROM array_op_test WHERE t @> '{}' ORDER BY seqno;
  939. seqno | i | t
  940. -------+---------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  941. 1 | {92,75,71,52,64,83} | {AAAAAAAA44066,AAAAAA1059,AAAAAAAAAAA176,AAAAAAA48038}
  942. 2 | {3,6} | {AAAAAA98232,AAAAAAAA79710,AAAAAAAAAAAAAAAAA69675,AAAAAAAAAAAAAAAA55798,AAAAAAAAA12793}
  943. 3 | {37,64,95,43,3,41,13,30,11,43} | {AAAAAAAAAA48845,AAAAA75968,AAAAA95309,AAA54451,AAAAAAAAAA22292,AAAAAAA99836,A96617,AA17009,AAAAAAAAAAAAAA95246}
  944. 4 | {71,39,99,55,33,75,45} | {AAAAAAAAA53663,AAAAAAAAAAAAAAA67062,AAAAAAAAAA64777,AAA99043,AAAAAAAAAAAAAAAAAAA91804,39557}
  945. 5 | {50,42,77,50,4} | {AAAAAAAAAAAAAAAAA26540,AAAAAAA79710,AAAAAAAAAAAAAAAAAAA1205,AAAAAAAAAAA176,AAAAA95309,AAAAAAAAAAA46154,AAAAAA66777,AAAAAAAAA27249,AAAAAAAAAA64777,AAAAAAAAAAAAAAAAAAA70104}
  946. 6 | {39,35,5,94,17,92,60,32} | {AAAAAAAAAAAAAAA35875,AAAAAAAAAAAAAAAA23657}
  947. 7 | {12,51,88,64,8} | {AAAAAAAAAAAAAAAAAA12591,AAAAAAAAAAAAAAAAA50407,AAAAAAAAAAAA67946}
  948. 8 | {60,84} | {AAAAAAA81898,AAAAAA1059,AAAAAAAAAAAA81511,AAAAA961,AAAAAAAAAAAAAAAA31334,AAAAA64741,AA6416,AAAAAAAAAAAAAAAAAA32918,AAAAAAAAAAAAAAAAA50407}
  949. 9 | {56,52,35,27,80,44,81,22} | {AAAAAAAAAAAAAAA73034,AAAAAAAAAAAAA7929,AAAAAAA66161,AA88409,39557,A27153,AAAAAAAA9523,AAAAAAAAAAA99000}
  950. 10 | {71,5,45} | {AAAAAAAAAAA21658,AAAAAAAAAAAA21089,AAA54451,AAAAAAAAAAAAAAAAAA54141,AAAAAAAAAAAAAA28620,AAAAAAAAAAA21658,AAAAAAAAAAA74076,AAAAAAAAA27249}
  951. 11 | {41,86,74,48,22,74,47,50} | {AAAAAAAA9523,AAAAAAAAAAAA37562,AAAAAAAAAAAAAAAA14047,AAAAAAAAAAA46154,AAAA41702,AAAAAAAAAAAAAAAAA764,AAAAA62737,39557}
  952. 12 | {17,99,18,52,91,72,0,43,96,23} | {AAAAA33250,AAAAAAAAAAAAAAAAAAA85420,AAAAAAAAAAA33576}
  953. 13 | {3,52,34,23} | {AAAAAA98232,AAAA49534,AAAAAAAAAAA21658}
  954. 14 | {78,57,19} | {AAAA8857,AAAAAAAAAAAAAAA73034,AAAAAAAA81587,AAAAAAAAAAAAAAA68526,AAAAA75968,AAAAAAAAAAAAAA65909,AAAAAAAAA10012,AAAAAAAAAAAAAA65909}
  955. 15 | {17,14,16,63,67} | {AA6416,AAAAAAAAAA646,AAAAA95309}
  956. 16 | {14,63,85,11} | {AAAAAA66777}
  957. 17 | {7,10,81,85} | {AAAAAA43678,AAAAAAA12144,AAAAAAAAAAA50956,AAAAAAAAAAAAAAAAAAA15356}
  958. 18 | {1} | {AAAAAAAAAAA33576,AAAAA95309,64261,AAA59323,AAAAAAAAAAAAAA95246,55847,AAAAAAAAAAAA67946,AAAAAAAAAAAAAAAAAA64374}
  959. 19 | {52,82,17,74,23,46,69,51,75} | {AAAAAAAAAAAAA73084,AAAAA75968,AAAAAAAAAAAAAAAA14047,AAAAAAA80240,AAAAAAAAAAAAAAAAAAA1205,A68938}
  960. 20 | {72,89,70,51,54,37,8,49,79} | {AAAAAA58494}
  961. 21 | {2,8,65,10,5,79,43} | {AAAAAAAAAAAAAAAAA88852,AAAAAAAAAAAAAAAAAAA91804,AAAAA64669,AAAAAAAAAAAAAAAA1443,AAAAAAAAAAAAAAAA23657,AAAAA12179,AAAAAAAAAAAAAAAAA88852,AAAAAAAAAAAAAAAA31334,AAAAAAAAAAAAAAAA41303,AAAAAAAAAAAAAAAAAAA85420}
  962. 22 | {11,6,56,62,53,30} | {AAAAAAAA72908}
  963. 23 | {40,90,5,38,72,40,30,10,43,55} | {A6053,AAAAAAAAAAA6119,AA44673,AAAAAAAAAAAAAAAAA764,AA17009,AAAAA17383,AAAAA70514,AAAAA33250,AAAAA95309,AAAAAAAAAAAA37562}
  964. 24 | {94,61,99,35,48} | {AAAAAAAAAAA50956,AAAAAAAAAAA15165,AAAA85070,AAAAAAAAAAAAAAA36627,AAAAA961,AAAAAAAAAA55219}
  965. 25 | {31,1,10,11,27,79,38} | {AAAAAAAAAAAAAAAAAA59334,45449}
  966. 26 | {71,10,9,69,75} | {47735,AAAAAAA21462,AAAAAAAAAAAAAAAAA6897,AAAAAAAAAAAAAAAAAAA91804,AAAAAAAAA72121,AAAAAAAAAAAAAAAAAAA1205,AAAAA41597,AAAA8857,AAAAAAAAAAAAAAAAAAA15356,AA17009}
  967. 27 | {94} | {AA6416,A6053,AAAAAAA21462,AAAAAAA57334,AAAAAAAAAAAAAAAAAA12591,AA88409,AAAAAAAAAAAAA70254}
  968. 28 | {14,33,6,34,14} | {AAAAAAAAAAAAAAA13198,AAAAAAAA69452,AAAAAAAAAAA82945,AAAAAAA12144,AAAAAAAAA72121,AAAAAAAAAA18601}
  969. 29 | {39,21} | {AAAAAAAAAAAAAAAAA6897,AAAAAAAAAAAAAAAAAAA38885,AAAA85070,AAAAAAAAAAAAAAAAAAA70104,AAAAA66674,AAAAAAAAAAAAA62007,AAAAAAAA69452,AAAAAAA1242,AAAAAAAAAAAAAAAA1729,AAAA35194}
  970. 30 | {26,81,47,91,34} | {AAAAAAAAAAAAAAAAAAA70104,AAAAAAA80240}
  971. 31 | {80,24,18,21,54} | {AAAAAAAAAAAAAAA13198,AAAAAAAAAAAAAAAAAAA70415,A27153,AAAAAAAAA53663,AAAAAAAAAAAAAAAAA50407,A68938}
  972. 32 | {58,79,82,80,67,75,98,10,41} | {AAAAAAAAAAAAAAAAAA61286,AAA54451,AAAAAAAAAAAAAAAAAAA87527,A96617,51533}
  973. 33 | {74,73} | {A85417,AAAAAAA56483,AAAAA17383,AAAAAAAAAAAAA62159,AAAAAAAAAAAA52814,AAAAAAAAAAAAA85723,AAAAAAAAAAAAAAAAAA55796}
  974. 34 | {70,45} | {AAAAAAAAAAAAAAAAAA71621,AAAAAAAAAAAAAA28620,AAAAAAAAAA55219,AAAAAAAA23648,AAAAAAAAAA22292,AAAAAAA1242}
  975. 35 | {23,40} | {AAAAAAAAAAAA52814,AAAA48949,AAAAAAAAA34727,AAAA8857,AAAAAAAAAAAAAAAAAAA62179,AAAAAAAAAAAAAAA68526,AAAAAAA99836,AAAAAAAA50094,AAAA91194,AAAAAAAAAAAAA73084}
  976. 36 | {79,82,14,52,30,5,79} | {AAAAAAAAA53663,AAAAAAAAAAAAAAAA55798,AAAAAAAAAAAAAAAAAAA89194,AA88409,AAAAAAAAAAAAAAA81326,AAAAAAAAAAAAAAAAA63050,AAAAAAAAAAAAAAAA33598}
  977. 37 | {53,11,81,39,3,78,58,64,74} | {AAAAAAAAAAAAAAAAAAA17075,AAAAAAA66161,AAAAAAAA23648,AAAAAAAAAAAAAA10611}
  978. 38 | {59,5,4,95,28} | {AAAAAAAAAAA82945,A96617,47735,AAAAA12179,AAAAA64669,AAAAAA99807,AA74433,AAAAAAAAAAAAAAAAA59387}
  979. 39 | {82,43,99,16,74} | {AAAAAAAAAAAAAAA67062,AAAAAAA57334,AAAAAAAAAAAAAA65909,A27153,AAAAAAAAAAAAAAAAAAA17075,AAAAAAAAAAAAAAAAA43052,AAAAAAAAAA64777,AAAAAAAAAAAA81511,AAAAAAAAAAAAAA65909,AAAAAAAAAAAAAA28620}
  980. 40 | {34} | {AAAAAAAAAAAAAA10611,AAAAAAAAAAAAAAAAAAA1205,AAAAAAAAAAA50956,AAAAAAAAAAAAAAAA31334,AAAAA70466,AAAAAAAA81587,AAAAAAA74623}
  981. 41 | {19,26,63,12,93,73,27,94} | {AAAAAAA79710,AAAAAAAAAA55219,AAAA41702,AAAAAAAAAAAAAAAAAAA17075,AAAAAAAAAAAAAAAAAA71621,AAAAAAAAAAAAAAAAA63050,AAAAAAA99836,AAAAAAAAAAAAAA8666}
  982. 42 | {15,76,82,75,8,91} | {AAAAAAAAAAA176,AAAAAA38063,45449,AAAAAA54032,AAAAAAA81898,AA6416,AAAAAAAAAAAAAAAAAAA62179,45449,AAAAA60038,AAAAAAAA81587}
  983. 43 | {39,87,91,97,79,28} | {AAAAAAAAAAA74076,A96617,AAAAAAAAAAAAAAAAAAA89194,AAAAAAAAAAAAAAAAAA55796,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAA67946}
  984. 44 | {40,58,68,29,54} | {AAAAAAA81898,AAAAAA66777,AAAAAA98232}
  985. 45 | {99,45} | {AAAAAAAA72908,AAAAAAAAAAAAAAAAAAA17075,AA88409,AAAAAAAAAAAAAAAAAA36842,AAAAAAA48038,AAAAAAAAAAAAAA10611}
  986. 46 | {53,24} | {AAAAAAAAAAA53908,AAAAAA54032,AAAAA17383,AAAA48949,AAAAAAAAAA18601,AAAAA64669,45449,AAAAAAAAAAA98051,AAAAAAAAAAAAAAAAAA71621}
  987. 47 | {98,23,64,12,75,61} | {AAA59323,AAAAA95309,AAAAAAAAAAAAAAAA31334,AAAAAAAAA27249,AAAAA17383,AAAAAAAAAAAA37562,AAAAAA1059,A84822,55847,AAAAA70466}
  988. 48 | {76,14} | {AAAAAAAAAAAAA59671,AAAAAAAAAAAAAAAAAAA91804,AAAAAA66777,AAAAAAAAAAAAAAAAAAA89194,AAAAAAAAAAAAAAA36627,AAAAAAAAAAAAAAAAAAA17075,AAAAAAAAAAAAA73084,AAAAAAA79710,AAAAAAAAAAAAAAA40402,AAAAAAAAAAAAAAAAAAA65037}
  989. 49 | {56,5,54,37,49} | {AA21643,AAAAAAAAAAA92631,AAAAAAAA81587}
  990. 50 | {20,12,37,64,93} | {AAAAAAAAAA5483,AAAAAAAAAAAAAAAAAAA1205,AA6416,AAAAAAAAAAAAAAAAA63050,AAAAAAAAAAAAAAAAAA47955}
  991. 51 | {47} | {AAAAAAAAAAAAAA96505,AAAAAAAAAAAAAAAAAA36842,AAAAA95309,AAAAAAAA81587,AA6416,AAAA91194,AAAAAA58494,AAAAAA1059,AAAAAAAA69452}
  992. 52 | {89,0} | {AAAAAAAAAAAAAAAAAA47955,AAAAAAA48038,AAAAAAAAAAAAAAAAA43052,AAAAAAAAAAAAA73084,AAAAA70466,AAAAAAAAAAAAAAAAA764,AAAAAAAAAAA46154,AA66862}
  993. 53 | {38,17} | {AAAAAAAAAAA21658}
  994. 54 | {70,47} | {AAAAAAAAAAAAAAAAAA54141,AAAAA40681,AAAAAAA48038,AAAAAAAAAAAAAAAA29150,AAAAA41597,AAAAAAAAAAAAAAAAAA59334,AA15322}
  995. 55 | {47,79,47,64,72,25,71,24,93} | {AAAAAAAAAAAAAAAAAA55796,AAAAA62737}
  996. 56 | {33,7,60,54,93,90,77,85,39} | {AAAAAAAAAAAAAAAAAA32918,AA42406}
  997. 57 | {23,45,10,42,36,21,9,96} | {AAAAAAAAAAAAAAAAAAA70415}
  998. 58 | {92} | {AAAAAAAAAAAAAAAA98414,AAAAAAAA23648,AAAAAAAAAAAAAAAAAA55796,AA25381,AAAAAAAAAAA6119}
  999. 59 | {9,69,46,77} | {39557,AAAAAAA89932,AAAAAAAAAAAAAAAAA43052,AAAAAAAAAAAAAAAAA26540,AAA20874,AA6416,AAAAAAAAAAAAAAAAAA47955}
  1000. 60 | {62,2,59,38,89} | {AAAAAAA89932,AAAAAAAAAAAAAAAAAAA15356,AA99927,AA17009,AAAAAAAAAAAAAAA35875}
  1001. 61 | {72,2,44,95,54,54,13} | {AAAAAAAAAAAAAAAAAAA91804}
  1002. 62 | {83,72,29,73} | {AAAAAAAAAAAAA15097,AAAA8857,AAAAAAAAAAAA35809,AAAAAAAAAAAA52814,AAAAAAAAAAAAAAAAAAA38885,AAAAAAAAAAAAAAAAAA24183,AAAAAA43678,A96617}
  1003. 63 | {11,4,61,87} | {AAAAAAAAA27249,AAAAAAAAAAAAAAAAAA32918,AAAAAAAAAAAAAAA13198,AAA20874,39557,51533,AAAAAAAAAAA53908,AAAAAAAAAAAAAA96505,AAAAAAAA78938}
  1004. 64 | {26,19,34,24,81,78} | {A96617,AAAAAAAAAAAAAAAAAAA70104,A68938,AAAAAAAAAAA53908,AAAAAAAAAAAAAAA453,AA17009,AAAAAAA80240}
  1005. 65 | {61,5,76,59,17} | {AAAAAA99807,AAAAA64741,AAAAAAAAAAA53908,AA21643,AAAAAAAAA10012}
  1006. 66 | {31,23,70,52,4,33,48,25} | {AAAAAAAAAAAAAAAAA69675,AAAAAAAA50094,AAAAAAAAAAA92631,AAAA35194,39557,AAAAAAA99836}
  1007. 67 | {31,94,7,10} | {AAAAAA38063,A96617,AAAA35194,AAAAAAAAAAAA67946}
  1008. 68 | {90,43,38} | {AA75092,AAAAAAAAAAAAAAAAA69675,AAAAAAAAAAA92631,AAAAAAAAA10012,AAAAAAAAAAAAA7929,AA21643}
  1009. 69 | {67,35,99,85,72,86,44} | {AAAAAAAAAAAAAAAAAAA1205,AAAAAAAA50094,AAAAAAAAAAAAAAAA1729,AAAAAAAAAAAAAAAAAA47955}
  1010. 70 | {56,70,83} | {AAAA41702,AAAAAAAAAAA82945,AA21643,AAAAAAAAAAA99000,A27153,AA25381,AAAAAAAAAAAAAA96505,AAAAAAA1242}
  1011. 71 | {74,26} | {AAAAAAAAAAA50956,AA74433,AAAAAAA21462,AAAAAAAAAAAAAAAAAAA17075,AAAAAAAAAAAAAAA36627,AAAAAAAAAAAAA70254,AAAAAAAAAA43419,39557}
  1012. 72 | {22,1,16,78,20,91,83} | {47735,AAAAAAA56483,AAAAAAAAAAAAA93788,AA42406,AAAAAAAAAAAAA73084,AAAAAAAA72908,AAAAAAAAAAAAAAAAAA61286,AAAAA66674,AAAAAAAAAAAAAAAAA50407}
  1013. 73 | {88,25,96,78,65,15,29,19} | {AAA54451,AAAAAAAAA27249,AAAAAAA9228,AAAAAAAAAAAAAAA67062,AAAAAAAAAAAAAAAAAAA70415,AAAAA17383,AAAAAAAAAAAAAAAA33598}
  1014. 74 | {32} | {AAAAAAAAAAAAAAAA1729,AAAAAAAAAAAAA22860,AAAAAA99807,AAAAA17383,AAAAAAAAAAAAAAA67062,AAAAAAAAAAA15165,AAAAAAAAAAA50956}
  1015. 75 | {12,96,83,24,71,89,55} | {AAAA48949,AAAAAAAA29716,AAAAAAAAAAAAAAAAAAA1205,AAAAAAAAAAAA67946,AAAAAAAAAAAAAAAA29150,AAA28075,AAAAAAAAAAAAAAAAA43052}
  1016. 76 | {92,55,10,7} | {AAAAAAAAAAAAAAA67062}
  1017. 77 | {97,15,32,17,55,59,18,37,50,39} | {AAAAAAAAAAAA67946,AAAAAA54032,AAAAAAAA81587,55847,AAAAAAAAAAAAAA28620,AAAAAAAAAAAAAAAAA43052,AAAAAA75463,AAAA49534,AAAAAAAA44066}
  1018. 78 | {55,89,44,84,34} | {AAAAAAAAAAA6119,AAAAAAAAAAAAAA8666,AA99927,AA42406,AAAAAAA81898,AAAAAAA9228,AAAAAAAAAAA92631,AA21643,AAAAAAAAAAAAAA28620}
  1019. 79 | {45} | {AAAAAAAAAA646,AAAAAAAAAAAAAAAAAAA70415,AAAAAA43678,AAAAAAAA72908}
  1020. 80 | {74,89,44,80,0} | {AAAA35194,AAAAAAAA79710,AAA20874,AAAAAAAAAAAAAAAAAAA70104,AAAAAAAAAAAAA73084,AAAAAAA57334,AAAAAAA9228,AAAAAAAAAAAAA62007}
  1021. 81 | {63,77,54,48,61,53,97} | {AAAAAAAAAAAAAAA81326,AAAAAAAAAA22292,AA25381,AAAAAAAAAAA74076,AAAAAAA81898,AAAAAAAAA72121}
  1022. 82 | {34,60,4,79,78,16,86,89,42,50} | {AAAAA40681,AAAAAAAAAAAAAAAAAA12591,AAAAAAA80240,AAAAAAAAAAAAAAAA55798,AAAAAAAAAAAAAAAAAAA70104}
  1023. 83 | {14,10} | {AAAAAAAAAA22292,AAAAAAAAAAAAA70254,AAAAAAAAAAA6119}
  1024. 84 | {11,83,35,13,96,94} | {AAAAA95309,AAAAAAAAAAAAAAAAAA32918,AAAAAAAAAAAAAAAAAA24183}
  1025. 85 | {39,60} | {AAAAAAAAAAAAAAAA55798,AAAAAAAAAA22292,AAAAAAA66161,AAAAAAA21462,AAAAAAAAAAAAAAAAAA12591,55847,AAAAAA98232,AAAAAAAAAAA46154}
  1026. 86 | {33,81,72,74,45,36,82} | {AAAAAAAA81587,AAAAAAAAAAAAAA96505,45449,AAAA80176}
  1027. 87 | {57,27,50,12,97,68} | {AAAAAAAAAAAAAAAAA26540,AAAAAAAAA10012,AAAAAAAAAAAA35809,AAAAAAAAAAAAAAAA29150,AAAAAAAAAAA82945,AAAAAA66777,31228,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAAAA28620,AAAAAAAAAAAAAA96505}
  1028. 88 | {41,90,77,24,6,24} | {AAAA35194,AAAA35194,AAAAAAA80240,AAAAAAAAAAA46154,AAAAAA58494,AAAAAAAAAAAAAAAAAAA17075,AAAAAAAAAAAAAAAAAA59334,AAAAAAAAAAAAAAAAAAA91804,AA74433}
  1029. 89 | {40,32,17,6,30,88} | {AA44673,AAAAAAAAAAA6119,AAAAAAAAAAAAAAAA23657,AAAAAAAAAAAAAAAAAA47955,AAAAAAAAAAAAAAAA33598,AAAAAAAAAAA33576,AA44673}
  1030. 90 | {88,75} | {AAAAA60038,AAAAAAAA23648,AAAAAAAAAAA99000,AAAA41702,AAAAAAAAAAAAA22860,AAAAAAAAAAAAAAA68526}
  1031. 91 | {78} | {AAAAAAAAAAAAA62007,AAA99043}
  1032. 92 | {85,63,49,45} | {AAAAAAA89932,AAAAAAAAAAAAA22860,AAAAAAAAAAAAAAAAAAA1205,AAAAAAAAAAAA21089}
  1033. 93 | {11} | {AAAAAAAAAAA176,AAAAAAAAAAAAAA8666,AAAAAAAAAAAAAAA453,AAAAAAAAAAAAA85723,A68938,AAAAAAAAAAAAA9821,AAAAAAA48038,AAAAAAAAAAAAAAAAA59387,AA99927,AAAAA17383}
  1034. 94 | {98,9,85,62,88,91,60,61,38,86} | {AAAAAAAA81587,AAAAA17383,AAAAAAAA81587}
  1035. 95 | {47,77} | {AAAAAAAAAAAAAAAAA764,AAAAAAAAAAA74076,AAAAAAAAAA18107,AAAAA40681,AAAAAAAAAAAAAAA35875,AAAAA60038,AAAAAAA56483}
  1036. 96 | {23,97,43} | {AAAAAAAAAA646,A87088}
  1037. 97 | {54,2,86,65} | {47735,AAAAAAA99836,AAAAAAAAAAAAAAAAA6897,AAAAAAAAAAAAAAAA29150,AAAAAAA80240,AAAAAAAAAAAAAAAA98414,AAAAAAA56483,AAAAAAAAAAAAAAAA29150,AAAAAAA39692,AA21643}
  1038. 98 | {38,34,32,89} | {AAAAAAAAAAAAAAAAAA71621,AAAA8857,AAAAAAAAAAAAAAAAAAA65037,AAAAAAAAAAAAAAAA31334,AAAAAAAAAA48845}
  1039. 99 | {37,86} | {AAAAAAAAAAAAAAAAAA32918,AAAAA70514,AAAAAAAAA10012,AAAAAAAAAAAAAAAAA59387,AAAAAAAAAA64777,AAAAAAAAAAAAAAAAAAA15356}
  1040. 100 | {85,32,57,39,49,84,32,3,30} | {AAAAAAA80240,AAAAAAAAAAAAAAAA1729,AAAAA60038,AAAAAAAAAAA92631,AAAAAAAA9523}
  1041. 101 | {} | {}
  1042. 102 | {NULL} | {NULL}
  1043. (102 rows)
  1044. SELECT * FROM array_op_test WHERE t && '{}' ORDER BY seqno;
  1045. seqno | i | t
  1046. -------+---+---
  1047. (0 rows)
  1048. SELECT * FROM array_op_test WHERE t <@ '{}' ORDER BY seqno;
  1049. seqno | i | t
  1050. -------+----+----
  1051. 101 | {} | {}
  1052. (1 row)
  1053. -- array casts
  1054. SELECT ARRAY[1,2,3]::text[]::int[]::float8[] AS "{1,2,3}";
  1055. {1,2,3}
  1056. ---------
  1057. {1,2,3}
  1058. (1 row)
  1059. SELECT pg_typeof(ARRAY[1,2,3]::text[]::int[]::float8[]) AS "double precision[]";
  1060. double precision[]
  1061. --------------------
  1062. double precision[]
  1063. (1 row)
  1064. SELECT ARRAY[['a','bc'],['def','hijk']]::text[]::varchar[] AS "{{a,bc},{def,hijk}}";
  1065. {{a,bc},{def,hijk}}
  1066. ---------------------
  1067. {{a,bc},{def,hijk}}
  1068. (1 row)
  1069. SELECT pg_typeof(ARRAY[['a','bc'],['def','hijk']]::text[]::varchar[]) AS "character varying[]";
  1070. character varying[]
  1071. ---------------------
  1072. character varying[]
  1073. (1 row)
  1074. SELECT CAST(ARRAY[[[[[['a','bb','ccc']]]]]] as text[]) as "{{{{{{a,bb,ccc}}}}}}";
  1075. {{{{{{a,bb,ccc}}}}}}
  1076. ----------------------
  1077. {{{{{{a,bb,ccc}}}}}}
  1078. (1 row)
  1079. SELECT NULL::text[]::int[] AS "NULL";
  1080. NULL
  1081. ------
  1082. (1 row)
  1083. -- scalar op any/all (array)
  1084. select 33 = any ('{1,2,3}');
  1085. ?column?
  1086. ----------
  1087. f
  1088. (1 row)
  1089. select 33 = any ('{1,2,33}');
  1090. ?column?
  1091. ----------
  1092. t
  1093. (1 row)
  1094. select 33 = all ('{1,2,33}');
  1095. ?column?
  1096. ----------
  1097. f
  1098. (1 row)
  1099. select 33 >= all ('{1,2,33}');
  1100. ?column?
  1101. ----------
  1102. t
  1103. (1 row)
  1104. -- boundary cases
  1105. select null::int >= all ('{1,2,33}');
  1106. ?column?
  1107. ----------
  1108. (1 row)
  1109. select null::int >= all ('{}');
  1110. ?column?
  1111. ----------
  1112. t
  1113. (1 row)
  1114. select null::int >= any ('{}');
  1115. ?column?
  1116. ----------
  1117. f
  1118. (1 row)
  1119. -- cross-datatype
  1120. select 33.4 = any (array[1,2,3]);
  1121. ?column?
  1122. ----------
  1123. f
  1124. (1 row)
  1125. select 33.4 > all (array[1,2,3]);
  1126. ?column?
  1127. ----------
  1128. t
  1129. (1 row)
  1130. -- errors
  1131. select 33 * any ('{1,2,3}');
  1132. ERROR: op ANY/ALL (array) requires operator to yield boolean
  1133. LINE 1: select 33 * any ('{1,2,3}');
  1134. ^
  1135. select 33 * any (44);
  1136. ERROR: op ANY/ALL (array) requires array on right side
  1137. LINE 1: select 33 * any (44);
  1138. ^
  1139. -- nulls
  1140. select 33 = any (null::int[]);
  1141. ?column?
  1142. ----------
  1143. (1 row)
  1144. select null::int = any ('{1,2,3}');
  1145. ?column?
  1146. ----------
  1147. (1 row)
  1148. select 33 = any ('{1,null,3}');
  1149. ?column?
  1150. ----------
  1151. (1 row)
  1152. select 33 = any ('{1,null,33}');
  1153. ?column?
  1154. ----------
  1155. t
  1156. (1 row)
  1157. select 33 = all (null::int[]);
  1158. ?column?
  1159. ----------
  1160. (1 row)
  1161. select null::int = all ('{1,2,3}');
  1162. ?column?
  1163. ----------
  1164. (1 row)
  1165. select 33 = all ('{1,null,3}');
  1166. ?column?
  1167. ----------
  1168. f
  1169. (1 row)
  1170. select 33 = all ('{33,null,33}');
  1171. ?column?
  1172. ----------
  1173. (1 row)
  1174. -- nulls later in the bitmap
  1175. SELECT -1 != ALL(ARRAY(SELECT NULLIF(g.i, 900) FROM generate_series(1,1000) g(i)));
  1176. ?column?
  1177. ----------
  1178. (1 row)
  1179. -- test indexes on arrays
  1180. create temp table arr_tbl (f1 int[] unique);
  1181. insert into arr_tbl values ('{1,2,3}');
  1182. insert into arr_tbl values ('{1,2}');
  1183. -- failure expected:
  1184. insert into arr_tbl values ('{1,2,3}');
  1185. ERROR: duplicate key value violates unique constraint "arr_tbl_f1_key"
  1186. DETAIL: Key (f1)=({1,2,3}) already exists.
  1187. insert into arr_tbl values ('{2,3,4}');
  1188. insert into arr_tbl values ('{1,5,3}');
  1189. insert into arr_tbl values ('{1,2,10}');
  1190. set enable_seqscan to off;
  1191. set enable_bitmapscan to off;
  1192. select * from arr_tbl where f1 > '{1,2,3}' and f1 <= '{1,5,3}';
  1193. f1
  1194. ----------
  1195. {1,2,10}
  1196. {1,5,3}
  1197. (2 rows)
  1198. select * from arr_tbl where f1 >= '{1,2,3}' and f1 < '{1,5,3}';
  1199. f1
  1200. ----------
  1201. {1,2,3}
  1202. {1,2,10}
  1203. (2 rows)
  1204. -- test ON CONFLICT DO UPDATE with arrays
  1205. create temp table arr_pk_tbl (pk int4 primary key, f1 int[]);
  1206. insert into arr_pk_tbl values (1, '{1,2,3}');
  1207. insert into arr_pk_tbl values (1, '{3,4,5}') on conflict (pk)
  1208. do update set f1[1] = excluded.f1[1], f1[3] = excluded.f1[3]
  1209. returning pk, f1;
  1210. pk | f1
  1211. ----+---------
  1212. 1 | {3,2,5}
  1213. (1 row)
  1214. insert into arr_pk_tbl(pk, f1[1:2]) values (1, '{6,7,8}') on conflict (pk)
  1215. do update set f1[1] = excluded.f1[1],
  1216. f1[2] = excluded.f1[2],
  1217. f1[3] = excluded.f1[3]
  1218. returning pk, f1;
  1219. pk | f1
  1220. ----+------------
  1221. 1 | {6,7,NULL}
  1222. (1 row)
  1223. -- note: if above selects don't produce the expected tuple order,
  1224. -- then you didn't get an indexscan plan, and something is busted.
  1225. reset enable_seqscan;
  1226. reset enable_bitmapscan;
  1227. -- test [not] (like|ilike) (any|all) (...)
  1228. select 'foo' like any (array['%a', '%o']); -- t
  1229. ?column?
  1230. ----------
  1231. t
  1232. (1 row)
  1233. select 'foo' like any (array['%a', '%b']); -- f
  1234. ?column?
  1235. ----------
  1236. f
  1237. (1 row)
  1238. select 'foo' like all (array['f%', '%o']); -- t
  1239. ?column?
  1240. ----------
  1241. t
  1242. (1 row)
  1243. select 'foo' like all (array['f%', '%b']); -- f
  1244. ?column?
  1245. ----------
  1246. f
  1247. (1 row)
  1248. select 'foo' not like any (array['%a', '%b']); -- t
  1249. ?column?
  1250. ----------
  1251. t
  1252. (1 row)
  1253. select 'foo' not like all (array['%a', '%o']); -- f
  1254. ?column?
  1255. ----------
  1256. f
  1257. (1 row)
  1258. select 'foo' ilike any (array['%A', '%O']); -- t
  1259. ?column?
  1260. ----------
  1261. t
  1262. (1 row)
  1263. select 'foo' ilike all (array['F%', '%O']); -- t
  1264. ?column?
  1265. ----------
  1266. t
  1267. (1 row)
  1268. --
  1269. -- General array parser tests
  1270. --
  1271. -- none of the following should be accepted
  1272. select '{{1,{2}},{2,3}}'::text[];
  1273. ERROR: malformed array literal: "{{1,{2}},{2,3}}"
  1274. LINE 1: select '{{1,{2}},{2,3}}'::text[];
  1275. ^
  1276. DETAIL: Unexpected "{" character.
  1277. select '{{},{}}'::text[];
  1278. ERROR: malformed array literal: "{{},{}}"
  1279. LINE 1: select '{{},{}}'::text[];
  1280. ^
  1281. DETAIL: Unexpected "}" character.
  1282. select E'{{1,2},\\{2,3}}'::text[];
  1283. ERROR: malformed array literal: "{{1,2},\{2,3}}"
  1284. LINE 1: select E'{{1,2},\\{2,3}}'::text[];
  1285. ^
  1286. DETAIL: Unexpected "\" character.
  1287. select '{{"1 2" x},{3}}'::text[];
  1288. ERROR: malformed array literal: "{{"1 2" x},{3}}"
  1289. LINE 1: select '{{"1 2" x},{3}}'::text[];
  1290. ^
  1291. DETAIL: Unexpected array element.
  1292. select '{}}'::text[];
  1293. ERROR: malformed array literal: "{}}"
  1294. LINE 1: select '{}}'::text[];
  1295. ^
  1296. DETAIL: Junk after closing right brace.
  1297. select '{ }}'::text[];
  1298. ERROR: malformed array literal: "{ }}"
  1299. LINE 1: select '{ }}'::text[];
  1300. ^
  1301. DETAIL: Junk after closing right brace.
  1302. select array[];
  1303. ERROR: cannot determine type of empty array
  1304. LINE 1: select array[];
  1305. ^
  1306. HINT: Explicitly cast to the desired type, for example ARRAY[]::integer[].
  1307. -- none of the above should be accepted
  1308. -- all of the following should be accepted
  1309. select '{}'::text[];
  1310. text
  1311. ------
  1312. {}
  1313. (1 row)
  1314. select '{{{1,2,3,4},{2,3,4,5}},{{3,4,5,6},{4,5,6,7}}}'::text[];
  1315. text
  1316. -----------------------------------------------
  1317. {{{1,2,3,4},{2,3,4,5}},{{3,4,5,6},{4,5,6,7}}}
  1318. (1 row)
  1319. select '{0 second ,0 second}'::interval[];
  1320. interval
  1321. ---------------
  1322. {"@ 0","@ 0"}
  1323. (1 row)
  1324. select '{ { "," } , { 3 } }'::text[];
  1325. text
  1326. -------------
  1327. {{","},{3}}
  1328. (1 row)
  1329. select ' { { " 0 second " , 0 second } }'::text[];
  1330. text
  1331. -------------------------------
  1332. {{" 0 second ","0 second"}}
  1333. (1 row)
  1334. select '{
  1335. 0 second,
  1336. @ 1 hour @ 42 minutes @ 20 seconds
  1337. }'::interval[];
  1338. interval
  1339. ------------------------------------
  1340. {"@ 0","@ 1 hour 42 mins 20 secs"}
  1341. (1 row)
  1342. select array[]::text[];
  1343. array
  1344. -------
  1345. {}
  1346. (1 row)
  1347. select '[0:1]={1.1,2.2}'::float8[];
  1348. float8
  1349. -----------------
  1350. [0:1]={1.1,2.2}
  1351. (1 row)
  1352. -- all of the above should be accepted
  1353. -- tests for array aggregates
  1354. CREATE TEMP TABLE arraggtest ( f1 INT[], f2 TEXT[][], f3 FLOAT[]);
  1355. INSERT INTO arraggtest (f1, f2, f3) VALUES
  1356. ('{1,2,3,4}','{{grey,red},{blue,blue}}','{1.6, 0.0}');
  1357. INSERT INTO arraggtest (f1, f2, f3) VALUES
  1358. ('{1,2,3}','{{grey,red},{grey,blue}}','{1.6}');
  1359. SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
  1360. max | min | max | min | max | min
  1361. -----------+---------+--------------------------+--------------------------+---------+-------
  1362. {1,2,3,4} | {1,2,3} | {{grey,red},{grey,blue}} | {{grey,red},{blue,blue}} | {1.6,0} | {1.6}
  1363. (1 row)
  1364. INSERT INTO arraggtest (f1, f2, f3) VALUES
  1365. ('{3,3,2,4,5,6}','{{white,yellow},{pink,orange}}','{2.1,3.3,1.8,1.7,1.6}');
  1366. SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
  1367. max | min | max | min | max | min
  1368. ---------------+---------+--------------------------------+--------------------------+-----------------------+-------
  1369. {3,3,2,4,5,6} | {1,2,3} | {{white,yellow},{pink,orange}} | {{grey,red},{blue,blue}} | {2.1,3.3,1.8,1.7,1.6} | {1.6}
  1370. (1 row)
  1371. INSERT INTO arraggtest (f1, f2, f3) VALUES
  1372. ('{2}','{{black,red},{green,orange}}','{1.6,2.2,2.6,0.4}');
  1373. SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
  1374. max | min | max | min | max | min
  1375. ---------------+---------+--------------------------------+------------------------------+-----------------------+-------
  1376. {3,3,2,4,5,6} | {1,2,3} | {{white,yellow},{pink,orange}} | {{black,red},{green,orange}} | {2.1,3.3,1.8,1.7,1.6} | {1.6}
  1377. (1 row)
  1378. INSERT INTO arraggtest (f1, f2, f3) VALUES
  1379. ('{4,2,6,7,8,1}','{{red},{black},{purple},{blue},{blue}}',NULL);
  1380. SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
  1381. max | min | max | min | max | min
  1382. ---------------+---------+--------------------------------+------------------------------+-----------------------+-------
  1383. {4,2,6,7,8,1} | {1,2,3} | {{white,yellow},{pink,orange}} | {{black,red},{green,orange}} | {2.1,3.3,1.8,1.7,1.6} | {1.6}
  1384. (1 row)
  1385. INSERT INTO arraggtest (f1, f2, f3) VALUES
  1386. ('{}','{{pink,white,blue,red,grey,orange}}','{2.1,1.87,1.4,2.2}');
  1387. SELECT max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) FROM arraggtest;
  1388. max | min | max | min | max | min
  1389. ---------------+-----+--------------------------------+------------------------------+-----------------------+-------
  1390. {4,2,6,7,8,1} | {} | {{white,yellow},{pink,orange}} | {{black,red},{green,orange}} | {2.1,3.3,1.8,1.7,1.6} | {1.6}
  1391. (1 row)
  1392. -- A few simple tests for arrays of composite types
  1393. create type comptype as (f1 int, f2 text);
  1394. create table comptable (c1 comptype, c2 comptype[]);
  1395. -- XXX would like to not have to specify row() construct types here ...
  1396. insert into comptable
  1397. values (row(1,'foo'), array[row(2,'bar')::comptype, row(3,'baz')::comptype]);
  1398. -- check that implicitly named array type _comptype isn't a problem
  1399. create type _comptype as enum('fooey');
  1400. select * from comptable;
  1401. c1 | c2
  1402. ---------+-----------------------
  1403. (1,foo) | {"(2,bar)","(3,baz)"}
  1404. (1 row)
  1405. select c2[2].f2 from comptable;
  1406. f2
  1407. -----
  1408. baz
  1409. (1 row)
  1410. drop type _comptype;
  1411. drop table comptable;
  1412. drop type comptype;
  1413. create or replace function unnest1(anyarray)
  1414. returns setof anyelement as $$
  1415. select $1[s] from generate_subscripts($1,1) g(s);
  1416. $$ language sql immutable;
  1417. create or replace function unnest2(anyarray)
  1418. returns setof anyelement as $$
  1419. select $1[s1][s2] from generate_subscripts($1,1) g1(s1),
  1420. generate_subscripts($1,2) g2(s2);
  1421. $$ language sql immutable;
  1422. select * from unnest1(array[1,2,3]);
  1423. unnest1
  1424. ---------
  1425. 1
  1426. 2
  1427. 3
  1428. (3 rows)
  1429. select * from unnest2(array[[1,2,3],[4,5,6]]);
  1430. unnest2
  1431. ---------
  1432. 1
  1433. 2
  1434. 3
  1435. 4
  1436. 5
  1437. 6
  1438. (6 rows)
  1439. drop function unnest1(anyarray);
  1440. drop function unnest2(anyarray);
  1441. select array_fill(null::integer, array[3,3],array[2,2]);
  1442. array_fill
  1443. -----------------------------------------------------------------
  1444. [2:4][2:4]={{NULL,NULL,NULL},{NULL,NULL,NULL},{NULL,NULL,NULL}}
  1445. (1 row)
  1446. select array_fill(null::integer, array[3,3]);
  1447. array_fill
  1448. ------------------------------------------------------
  1449. {{NULL,NULL,NULL},{NULL,NULL,NULL},{NULL,NULL,NULL}}
  1450. (1 row)
  1451. select array_fill(null::text, array[3,3],array[2,2]);
  1452. array_fill
  1453. -----------------------------------------------------------------
  1454. [2:4][2:4]={{NULL,NULL,NULL},{NULL,NULL,NULL},{NULL,NULL,NULL}}
  1455. (1 row)
  1456. select array_fill(null::text, array[3,3]);
  1457. array_fill
  1458. ------------------------------------------------------
  1459. {{NULL,NULL,NULL},{NULL,NULL,NULL},{NULL,NULL,NULL}}
  1460. (1 row)
  1461. select array_fill(7, array[3,3],array[2,2]);
  1462. array_fill
  1463. --------------------------------------
  1464. [2:4][2:4]={{7,7,7},{7,7,7},{7,7,7}}
  1465. (1 row)
  1466. select array_fill(7, array[3,3]);
  1467. array_fill
  1468. ---------------------------
  1469. {{7,7,7},{7,7,7},{7,7,7}}
  1470. (1 row)
  1471. select array_fill('juhu'::text, array[3,3],array[2,2]);
  1472. array_fill
  1473. -----------------------------------------------------------------
  1474. [2:4][2:4]={{juhu,juhu,juhu},{juhu,juhu,juhu},{juhu,juhu,juhu}}
  1475. (1 row)
  1476. select array_fill('juhu'::text, array[3,3]);
  1477. array_fill
  1478. ------------------------------------------------------
  1479. {{juhu,juhu,juhu},{juhu,juhu,juhu},{juhu,juhu,juhu}}
  1480. (1 row)
  1481. select a, a = '{}' as is_eq, array_dims(a)
  1482. from (select array_fill(42, array[0]) as a) ss;
  1483. a | is_eq | array_dims
  1484. ----+-------+------------
  1485. {} | t |
  1486. (1 row)
  1487. select a, a = '{}' as is_eq, array_dims(a)
  1488. from (select array_fill(42, '{}') as a) ss;
  1489. a | is_eq | array_dims
  1490. ----+-------+------------
  1491. {} | t |
  1492. (1 row)
  1493. select a, a = '{}' as is_eq, array_dims(a)
  1494. from (select array_fill(42, '{}', '{}') as a) ss;
  1495. a | is_eq | array_dims
  1496. ----+-------+------------
  1497. {} | t |
  1498. (1 row)
  1499. -- raise exception
  1500. select array_fill(1, null, array[2,2]);
  1501. ERROR: dimension array or low bound array cannot be null
  1502. select array_fill(1, array[2,2], null);
  1503. ERROR: dimension array or low bound array cannot be null
  1504. select array_fill(1, array[2,2], '{}');
  1505. ERROR: wrong number of array subscripts
  1506. DETAIL: Low bound array has different size than dimensions array.
  1507. select array_fill(1, array[3,3], array[1,1,1]);
  1508. ERROR: wrong number of array subscripts
  1509. DETAIL: Low bound array has different size than dimensions array.
  1510. select array_fill(1, array[1,2,null]);
  1511. ERROR: dimension values cannot be null
  1512. select array_fill(1, array[[1,2],[3,4]]);
  1513. ERROR: wrong number of array subscripts
  1514. DETAIL: Dimension array must be one dimensional.
  1515. select string_to_array('1|2|3', '|');
  1516. string_to_array
  1517. -----------------
  1518. {1,2,3}
  1519. (1 row)
  1520. select string_to_array('1|2|3|', '|');
  1521. string_to_array
  1522. -----------------
  1523. {1,2,3,""}
  1524. (1 row)
  1525. select string_to_array('1||2|3||', '||');
  1526. string_to_array
  1527. -----------------
  1528. {1,2|3,""}
  1529. (1 row)
  1530. select string_to_array('1|2|3', '');
  1531. string_to_array
  1532. -----------------
  1533. {1|2|3}
  1534. (1 row)
  1535. select string_to_array('', '|');
  1536. string_to_array
  1537. -----------------
  1538. {}
  1539. (1 row)
  1540. select string_to_array('1|2|3', NULL);
  1541. string_to_array
  1542. -----------------
  1543. {1,|,2,|,3}
  1544. (1 row)
  1545. select string_to_array(NULL, '|') IS NULL;
  1546. ?column?
  1547. ----------
  1548. t
  1549. (1 row)
  1550. select string_to_array('abc', '');
  1551. string_to_array
  1552. -----------------
  1553. {abc}
  1554. (1 row)
  1555. select string_to_array('abc', '', 'abc');
  1556. string_to_array
  1557. -----------------
  1558. {NULL}
  1559. (1 row)
  1560. select string_to_array('abc', ',');
  1561. string_to_array
  1562. -----------------
  1563. {abc}
  1564. (1 row)
  1565. select string_to_array('abc', ',', 'abc');
  1566. string_to_array
  1567. -----------------
  1568. {NULL}
  1569. (1 row)
  1570. select string_to_array('1,2,3,4,,6', ',');
  1571. string_to_array
  1572. -----------------
  1573. {1,2,3,4,"",6}
  1574. (1 row)
  1575. select string_to_array('1,2,3,4,,6', ',', '');
  1576. string_to_array
  1577. ------------------
  1578. {1,2,3,4,NULL,6}
  1579. (1 row)
  1580. select string_to_array('1,2,3,4,*,6', ',', '*');
  1581. string_to_array
  1582. ------------------
  1583. {1,2,3,4,NULL,6}
  1584. (1 row)
  1585. select v, v is null as "is null" from string_to_table('1|2|3', '|') g(v);
  1586. v | is null
  1587. ---+---------
  1588. 1 | f
  1589. 2 | f
  1590. 3 | f
  1591. (3 rows)
  1592. select v, v is null as "is null" from string_to_table('1|2|3|', '|') g(v);
  1593. v | is null
  1594. ---+---------
  1595. 1 | f
  1596. 2 | f
  1597. 3 | f
  1598. | f
  1599. (4 rows)
  1600. select v, v is null as "is null" from string_to_table('1||2|3||', '||') g(v);
  1601. v | is null
  1602. -----+---------
  1603. 1 | f
  1604. 2|3 | f
  1605. | f
  1606. (3 rows)
  1607. select v, v is null as "is null" from string_to_table('1|2|3', '') g(v);
  1608. v | is null
  1609. -------+---------
  1610. 1|2|3 | f
  1611. (1 row)
  1612. select v, v is null as "is null" from string_to_table('', '|') g(v);
  1613. v | is null
  1614. ---+---------
  1615. (0 rows)
  1616. select v, v is null as "is null" from string_to_table('1|2|3', NULL) g(v);
  1617. v | is null
  1618. ---+---------
  1619. 1 | f
  1620. | | f
  1621. 2 | f
  1622. | | f
  1623. 3 | f
  1624. (5 rows)
  1625. select v, v is null as "is null" from string_to_table(NULL, '|') g(v);
  1626. v | is null
  1627. ---+---------
  1628. (0 rows)
  1629. select v, v is null as "is null" from string_to_table('abc', '') g(v);
  1630. v | is null
  1631. -----+---------
  1632. abc | f
  1633. (1 row)
  1634. select v, v is null as "is null" from string_to_table('abc', '', 'abc') g(v);
  1635. v | is null
  1636. ---+---------
  1637. | t
  1638. (1 row)
  1639. select v, v is null as "is null" from string_to_table('abc', ',') g(v);
  1640. v | is null
  1641. -----+---------
  1642. abc | f
  1643. (1 row)
  1644. select v, v is null as "is null" from string_to_table('abc', ',', 'abc') g(v);
  1645. v | is null
  1646. ---+---------
  1647. | t
  1648. (1 row)
  1649. select v, v is null as "is null" from string_to_table('1,2,3,4,,6', ',') g(v);
  1650. v | is null
  1651. ---+---------
  1652. 1 | f
  1653. 2 | f
  1654. 3 | f
  1655. 4 | f
  1656. | f
  1657. 6 | f
  1658. (6 rows)
  1659. select v, v is null as "is null" from string_to_table('1,2,3,4,,6', ',', '') g(v);
  1660. v | is null
  1661. ---+---------
  1662. 1 | f
  1663. 2 | f
  1664. 3 | f
  1665. 4 | f
  1666. | t
  1667. 6 | f
  1668. (6 rows)
  1669. select v, v is null as "is null" from string_to_table('1,2,3,4,*,6', ',', '*') g(v);
  1670. v | is null
  1671. ---+---------
  1672. 1 | f
  1673. 2 | f
  1674. 3 | f
  1675. 4 | f
  1676. | t
  1677. 6 | f
  1678. (6 rows)
  1679. select array_to_string(NULL::int4[], ',') IS NULL;
  1680. ?column?
  1681. ----------
  1682. t
  1683. (1 row)
  1684. select array_to_string('{}'::int4[], ',');
  1685. array_to_string
  1686. -----------------
  1687. (1 row)
  1688. select array_to_string(array[1,2,3,4,NULL,6], ',');
  1689. array_to_string
  1690. -----------------
  1691. 1,2,3,4,6
  1692. (1 row)
  1693. select array_to_string(array[1,2,3,4,NULL,6], ',', '*');
  1694. array_to_string
  1695. -----------------
  1696. 1,2,3,4,*,6
  1697. (1 row)
  1698. select array_to_string(array[1,2,3,4,NULL,6], NULL);
  1699. array_to_string
  1700. -----------------
  1701. (1 row)
  1702. select array_to_string(array[1,2,3,4,NULL,6], ',', NULL);
  1703. array_to_string
  1704. -----------------
  1705. 1,2,3,4,6
  1706. (1 row)
  1707. select array_to_string(string_to_array('1|2|3', '|'), '|');
  1708. array_to_string
  1709. -----------------
  1710. 1|2|3
  1711. (1 row)
  1712. select array_length(array[1,2,3], 1);
  1713. array_length
  1714. --------------
  1715. 3
  1716. (1 row)
  1717. select array_length(array[[1,2,3], [4,5,6]], 0);
  1718. array_length
  1719. --------------
  1720. (1 row)
  1721. select array_length(array[[1,2,3], [4,5,6]], 1);
  1722. array_length
  1723. --------------
  1724. 2
  1725. (1 row)
  1726. select array_length(array[[1,2,3], [4,5,6]], 2);
  1727. array_length
  1728. --------------
  1729. 3
  1730. (1 row)
  1731. select array_length(array[[1,2,3], [4,5,6]], 3);
  1732. array_length
  1733. --------------
  1734. (1 row)
  1735. select cardinality(NULL::int[]);
  1736. cardinality
  1737. -------------
  1738. (1 row)
  1739. select cardinality('{}'::int[]);
  1740. cardinality
  1741. -------------
  1742. 0
  1743. (1 row)
  1744. select cardinality(array[1,2,3]);
  1745. cardinality
  1746. -------------
  1747. 3
  1748. (1 row)
  1749. select cardinality('[2:4]={5,6,7}'::int[]);
  1750. cardinality
  1751. -------------
  1752. 3
  1753. (1 row)
  1754. select cardinality('{{1,2}}'::int[]);
  1755. cardinality
  1756. -------------
  1757. 2
  1758. (1 row)
  1759. select cardinality('{{1,2},{3,4},{5,6}}'::int[]);
  1760. cardinality
  1761. -------------
  1762. 6
  1763. (1 row)
  1764. select cardinality('{{{1,9},{5,6}},{{2,3},{3,4}}}'::int[]);
  1765. cardinality
  1766. -------------
  1767. 8
  1768. (1 row)
  1769. -- array_agg(anynonarray)
  1770. select array_agg(unique1) from (select unique1 from tenk1 where unique1 < 15 order by unique1) ss;
  1771. array_agg
  1772. --------------------------------------
  1773. {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}
  1774. (1 row)
  1775. select array_agg(ten) from (select ten from tenk1 where unique1 < 15 order by unique1) ss;
  1776. array_agg
  1777. ---------------------------------
  1778. {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4}
  1779. (1 row)
  1780. select array_agg(nullif(ten, 4)) from (select ten from tenk1 where unique1 < 15 order by unique1) ss;
  1781. array_agg
  1782. ---------------------------------------
  1783. {0,1,2,3,NULL,5,6,7,8,9,0,1,2,3,NULL}
  1784. (1 row)
  1785. select array_agg(unique1) from tenk1 where unique1 < -15;
  1786. array_agg
  1787. -----------
  1788. (1 row)
  1789. -- array_agg(anyarray)
  1790. select array_agg(ar)
  1791. from (values ('{1,2}'::int[]), ('{3,4}'::int[])) v(ar);
  1792. array_agg
  1793. ---------------
  1794. {{1,2},{3,4}}
  1795. (1 row)
  1796. select array_agg(distinct ar order by ar desc)
  1797. from (select array[i / 2] from generate_series(1,10) a(i)) b(ar);
  1798. array_agg
  1799. ---------------------------
  1800. {{5},{4},{3},{2},{1},{0}}
  1801. (1 row)
  1802. select array_agg(ar)
  1803. from (select array_agg(array[i, i+1, i-1])
  1804. from generate_series(1,2) a(i)) b(ar);
  1805. array_agg
  1806. ---------------------
  1807. {{{1,2,0},{2,3,1}}}
  1808. (1 row)
  1809. select array_agg(array[i+1.2, i+1.3, i+1.4]) from generate_series(1,3) g(i);
  1810. array_agg
  1811. ---------------------------------------------
  1812. {{2.2,2.3,2.4},{3.2,3.3,3.4},{4.2,4.3,4.4}}
  1813. (1 row)
  1814. select array_agg(array['Hello', i::text]) from generate_series(9,11) g(i);
  1815. array_agg
  1816. -----------------------------------
  1817. {{Hello,9},{Hello,10},{Hello,11}}
  1818. (1 row)
  1819. select array_agg(array[i, nullif(i, 3), i+1]) from generate_series(1,4) g(i);
  1820. array_agg
  1821. --------------------------------------
  1822. {{1,1,2},{2,2,3},{3,NULL,4},{4,4,5}}
  1823. (1 row)
  1824. -- errors
  1825. select array_agg('{}'::int[]) from generate_series(1,2);
  1826. ERROR: cannot accumulate empty arrays
  1827. select array_agg(null::int[]) from generate_series(1,2);
  1828. ERROR: cannot accumulate null arrays
  1829. select array_agg(ar)
  1830. from (values ('{1,2}'::int[]), ('{3}'::int[])) v(ar);
  1831. ERROR: cannot accumulate arrays of different dimensionality
  1832. select unnest(array[1,2,3]);
  1833. unnest
  1834. --------
  1835. 1
  1836. 2
  1837. 3
  1838. (3 rows)
  1839. select * from unnest(array[1,2,3]);
  1840. unnest
  1841. --------
  1842. 1
  1843. 2
  1844. 3
  1845. (3 rows)
  1846. select unnest(array[1,2,3,4.5]::float8[]);
  1847. unnest
  1848. --------
  1849. 1
  1850. 2
  1851. 3
  1852. 4.5
  1853. (4 rows)
  1854. select unnest(array[1,2,3,4.5]::numeric[]);
  1855. unnest
  1856. --------
  1857. 1
  1858. 2
  1859. 3
  1860. 4.5
  1861. (4 rows)
  1862. select unnest(array[1,2,3,null,4,null,null,5,6]);
  1863. unnest
  1864. --------
  1865. 1
  1866. 2
  1867. 3
  1868. 4
  1869. 5
  1870. 6
  1871. (9 rows)
  1872. select unnest(array[1,2,3,null,4,null,null,5,6]::text[]);
  1873. unnest
  1874. --------
  1875. 1
  1876. 2
  1877. 3
  1878. 4
  1879. 5
  1880. 6
  1881. (9 rows)
  1882. select abs(unnest(array[1,2,null,-3]));
  1883. abs
  1884. -----
  1885. 1
  1886. 2
  1887. 3
  1888. (4 rows)
  1889. select array_remove(array[1,2,2,3], 2);
  1890. array_remove
  1891. --------------
  1892. {1,3}
  1893. (1 row)
  1894. select array_remove(array[1,2,2,3], 5);
  1895. array_remove
  1896. --------------
  1897. {1,2,2,3}
  1898. (1 row)
  1899. select array_remove(array[1,NULL,NULL,3], NULL);
  1900. array_remove
  1901. --------------
  1902. {1,3}
  1903. (1 row)
  1904. select array_remove(array['A','CC','D','C','RR'], 'RR');
  1905. array_remove
  1906. --------------
  1907. {A,CC,D,C}
  1908. (1 row)
  1909. select array_remove(array[1.0, 2.1, 3.3], 1);
  1910. array_remove
  1911. --------------
  1912. {2.1,3.3}
  1913. (1 row)
  1914. select array_remove('{{1,2,2},{1,4,3}}', 2); -- not allowed
  1915. ERROR: removing elements from multidimensional arrays is not supported
  1916. select array_remove(array['X','X','X'], 'X') = '{}';
  1917. ?column?
  1918. ----------
  1919. t
  1920. (1 row)
  1921. select array_replace(array[1,2,5,4],5,3);
  1922. array_replace
  1923. ---------------
  1924. {1,2,3,4}
  1925. (1 row)
  1926. select array_replace(array[1,2,5,4],5,NULL);
  1927. array_replace
  1928. ---------------
  1929. {1,2,NULL,4}
  1930. (1 row)
  1931. select array_replace(array[1,2,NULL,4,NULL],NULL,5);
  1932. array_replace
  1933. ---------------
  1934. {1,2,5,4,5}
  1935. (1 row)
  1936. select array_replace(array['A','B','DD','B'],'B','CC');
  1937. array_replace
  1938. ---------------
  1939. {A,CC,DD,CC}
  1940. (1 row)
  1941. select array_replace(array[1,NULL,3],NULL,NULL);
  1942. array_replace
  1943. ---------------
  1944. {1,NULL,3}
  1945. (1 row)
  1946. select array_replace(array['AB',NULL,'CDE'],NULL,'12');
  1947. array_replace
  1948. ---------------
  1949. {AB,12,CDE}
  1950. (1 row)
  1951. -- array(select array-value ...)
  1952. select array(select array[i,i/2] from generate_series(1,5) i);
  1953. array
  1954. ---------------------------------
  1955. {{1,0},{2,1},{3,1},{4,2},{5,2}}
  1956. (1 row)
  1957. select array(select array['Hello', i::text] from generate_series(9,11) i);
  1958. array
  1959. -----------------------------------
  1960. {{Hello,9},{Hello,10},{Hello,11}}
  1961. (1 row)
  1962. -- Insert/update on a column that is array of composite
  1963. create temp table t1 (f1 int8_tbl[]);
  1964. insert into t1 (f1[5].q1) values(42);
  1965. select * from t1;
  1966. f1
  1967. -----------------
  1968. [5:5]={"(42,)"}
  1969. (1 row)
  1970. update t1 set f1[5].q2 = 43;
  1971. select * from t1;
  1972. f1
  1973. -------------------
  1974. [5:5]={"(42,43)"}
  1975. (1 row)
  1976. -- Check that arrays of composites are safely detoasted when needed
  1977. create temp table src (f1 text);
  1978. insert into src
  1979. select string_agg(random()::text,'') from generate_series(1,10000);
  1980. create type textandtext as (c1 text, c2 text);
  1981. create temp table dest (f1 textandtext[]);
  1982. insert into dest select array[row(f1,f1)::textandtext] from src;
  1983. select length(md5((f1[1]).c2)) from dest;
  1984. length
  1985. --------
  1986. 32
  1987. (1 row)
  1988. delete from src;
  1989. select length(md5((f1[1]).c2)) from dest;
  1990. length
  1991. --------
  1992. 32
  1993. (1 row)
  1994. truncate table src;
  1995. drop table src;
  1996. select length(md5((f1[1]).c2)) from dest;
  1997. length
  1998. --------
  1999. 32
  2000. (1 row)
  2001. drop table dest;
  2002. drop type textandtext;
  2003. -- Tests for polymorphic-array form of width_bucket()
  2004. -- this exercises the varwidth and float8 code paths
  2005. SELECT
  2006. op,
  2007. width_bucket(op::numeric, ARRAY[1, 3, 5, 10.0]::numeric[]) AS wb_n1,
  2008. width_bucket(op::numeric, ARRAY[0, 5.5, 9.99]::numeric[]) AS wb_n2,
  2009. width_bucket(op::numeric, ARRAY[-6, -5, 2.0]::numeric[]) AS wb_n3,
  2010. width_bucket(op::float8, ARRAY[1, 3, 5, 10.0]::float8[]) AS wb_f1,
  2011. width_bucket(op::float8, ARRAY[0, 5.5, 9.99]::float8[]) AS wb_f2,
  2012. width_bucket(op::float8, ARRAY[-6, -5, 2.0]::float8[]) AS wb_f3
  2013. FROM (VALUES
  2014. (-5.2),
  2015. (-0.0000000001),
  2016. (0.000000000001),
  2017. (1),
  2018. (1.99999999999999),
  2019. (2),
  2020. (2.00000000000001),
  2021. (3),
  2022. (4),
  2023. (4.5),
  2024. (5),
  2025. (5.5),
  2026. (6),
  2027. (7),
  2028. (8),
  2029. (9),
  2030. (9.99999999999999),
  2031. (10),
  2032. (10.0000000000001)
  2033. ) v(op);
  2034. op | wb_n1 | wb_n2 | wb_n3 | wb_f1 | wb_f2 | wb_f3
  2035. ------------------+-------+-------+-------+-------+-------+-------
  2036. -5.2 | 0 | 0 | 1 | 0 | 0 | 1
  2037. -0.0000000001 | 0 | 0 | 2 | 0 | 0 | 2
  2038. 0.000000000001 | 0 | 1 | 2 | 0 | 1 | 2
  2039. 1 | 1 | 1 | 2 | 1 | 1 | 2
  2040. 1.99999999999999 | 1 | 1 | 2 | 1 | 1 | 2
  2041. 2 | 1 | 1 | 3 | 1 | 1 | 3
  2042. 2.00000000000001 | 1 | 1 | 3 | 1 | 1 | 3
  2043. 3 | 2 | 1 | 3 | 2 | 1 | 3
  2044. 4 | 2 | 1 | 3 | 2 | 1 | 3
  2045. 4.5 | 2 | 1 | 3 | 2 | 1 | 3
  2046. 5 | 3 | 1 | 3 | 3 | 1 | 3
  2047. 5.5 | 3 | 2 | 3 | 3 | 2 | 3
  2048. 6 | 3 | 2 | 3 | 3 | 2 | 3
  2049. 7 | 3 | 2 | 3 | 3 | 2 | 3
  2050. 8 | 3 | 2 | 3 | 3 | 2 | 3
  2051. 9 | 3 | 2 | 3 | 3 | 2 | 3
  2052. 9.99999999999999 | 3 | 3 | 3 | 3 | 3 | 3
  2053. 10 | 4 | 3 | 3 | 4 | 3 | 3
  2054. 10.0000000000001 | 4 | 3 | 3 | 4 | 3 | 3
  2055. (19 rows)
  2056. -- ensure float8 path handles NaN properly
  2057. SELECT
  2058. op,
  2059. width_bucket(op, ARRAY[1, 3, 9, 'NaN', 'NaN']::float8[]) AS wb
  2060. FROM (VALUES
  2061. (-5.2::float8),
  2062. (4::float8),
  2063. (77::float8),
  2064. ('NaN'::float8)
  2065. ) v(op);
  2066. op | wb
  2067. ------+----
  2068. -5.2 | 0
  2069. 4 | 2
  2070. 77 | 3
  2071. NaN | 5
  2072. (4 rows)
  2073. -- these exercise the generic fixed-width code path
  2074. SELECT
  2075. op,
  2076. width_bucket(op, ARRAY[1, 3, 5, 10]) AS wb_1
  2077. FROM generate_series(0,11) as op;
  2078. op | wb_1
  2079. ----+------
  2080. 0 | 0
  2081. 1 | 1
  2082. 2 | 1
  2083. 3 | 2
  2084. 4 | 2
  2085. 5 | 3
  2086. 6 | 3
  2087. 7 | 3
  2088. 8 | 3
  2089. 9 | 3
  2090. 10 | 4
  2091. 11 | 4
  2092. (12 rows)
  2093. SELECT width_bucket(now(),
  2094. array['yesterday', 'today', 'tomorrow']::timestamptz[]);
  2095. width_bucket
  2096. --------------
  2097. 2
  2098. (1 row)
  2099. -- corner cases
  2100. SELECT width_bucket(5, ARRAY[3]);
  2101. width_bucket
  2102. --------------
  2103. 1
  2104. (1 row)
  2105. SELECT width_bucket(5, '{}');
  2106. width_bucket
  2107. --------------
  2108. 0
  2109. (1 row)
  2110. -- error cases
  2111. SELECT width_bucket('5'::text, ARRAY[3, 4]::integer[]);
  2112. ERROR: function width_bucket(text, integer[]) does not exist
  2113. LINE 1: SELECT width_bucket('5'::text, ARRAY[3, 4]::integer[]);
  2114. ^
  2115. HINT: No function matches the given name and argument types. You might need to add explicit type casts.
  2116. SELECT width_bucket(5, ARRAY[3, 4, NULL]);
  2117. ERROR: thresholds array must not contain NULLs
  2118. SELECT width_bucket(5, ARRAY[ARRAY[1, 2], ARRAY[3, 4]]);
  2119. ERROR: thresholds must be one-dimensional array
  2120. -- trim_array
  2121. SELECT arr, trim_array(arr, 2)
  2122. FROM
  2123. (VALUES ('{1,2,3,4,5,6}'::bigint[]),
  2124. ('{1,2}'),
  2125. ('[10:16]={1,2,3,4,5,6,7}'),
  2126. ('[-15:-10]={1,2,3,4,5,6}'),
  2127. ('{{1,10},{2,20},{3,30},{4,40}}')) v(arr);
  2128. arr | trim_array
  2129. -------------------------------+-----------------
  2130. {1,2,3,4,5,6} | {1,2,3,4}
  2131. {1,2} | {}
  2132. [10:16]={1,2,3,4,5,6,7} | {1,2,3,4,5}
  2133. [-15:-10]={1,2,3,4,5,6} | {1,2,3,4}
  2134. {{1,10},{2,20},{3,30},{4,40}} | {{1,10},{2,20}}
  2135. (5 rows)
  2136. SELECT trim_array(ARRAY[1, 2, 3], -1); -- fail
  2137. ERROR: number of elements to trim must be between 0 and 3
  2138. SELECT trim_array(ARRAY[1, 2, 3], 10); -- fail
  2139. ERROR: number of elements to trim must be between 0 and 3
  2140. SELECT trim_array(ARRAY[]::int[], 1); -- fail
  2141. ERROR: number of elements to trim must be between 0 and 0