builtin_function.slt 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257
  1. # Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # This file is derived from the logic test suite in CockroachDB. The
  12. # original file was retrieved on June 10, 2019 from:
  13. #
  14. # https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/builtin_function
  15. #
  16. # The original source code is subject to the terms of the Apache
  17. # 2.0 license, a copy of which can be found in the LICENSE file at the
  18. # root of this repository.
  19. mode cockroach
  20. simple conn=mz_system,user=mz_system
  21. ALTER SYSTEM SET unsafe_enable_table_keys = true
  22. ----
  23. COMPLETE 0
  24. statement ok
  25. CREATE TABLE foo (a int)
  26. statement ok
  27. INSERT INTO foo (a) VALUES (1)
  28. query error unknown function: foo.bar
  29. SELECT foo.bar()
  30. query error unknown function: defaults
  31. SELECT defaults()
  32. query II colnames
  33. SELECT length('roach7'), length(b'roach77')
  34. ----
  35. length length
  36. 6 7
  37. query IIIIII
  38. SELECT length('Hello, 世界'), length(b'Hello, 世界'),
  39. char_length('Hello, 世界'), char_length(b'Hello, 世界'),
  40. character_length('Hello, 世界'), character_length(b'Hello, 世界')
  41. ----
  42. 9 13 9 13 9 13
  43. statement error unknown signature: length\(int\)
  44. SELECT length(23)
  45. query III
  46. SELECT octet_length('Hello'), octet_length('世界'), octet_length(b'世界')
  47. ----
  48. 5 6 6
  49. query III
  50. SELECT bit_length('Hello'), bit_length('世界'), bit_length(b'世界')
  51. ----
  52. 40 48 48
  53. query TTTTTTTT
  54. SELECT quote_ident('abc'), quote_ident('ab.c'), quote_ident('ab"c'), quote_ident('世界'),
  55. quote_ident('array'), -- reserved keyword
  56. quote_ident('family'), -- type/func name keyword
  57. quote_ident('bigint'), -- col name keyword
  58. quote_ident('alter') -- unreserved keyword
  59. ----
  60. abc "ab.c" "ab""c" 世界 "array" "family" "bigint" alter
  61. query TTTT
  62. SELECT quote_literal('abc'), quote_literal('ab''c'), quote_literal('ab"c'), quote_literal(e'ab\nc')
  63. ----
  64. 'abc' e'ab\'c' 'ab"c' e'ab\nc'
  65. query TTTTTTTT
  66. SELECT
  67. quote_literal(123::string), quote_nullable(123::string),
  68. quote_literal(123), quote_nullable(123),
  69. quote_literal(true), quote_nullable(true),
  70. quote_literal(123.3), quote_nullable(123.3)
  71. ----
  72. '123' '123' '123' '123' 'true' 'true' '123.3' '123.3'
  73. query TTTTTT
  74. SELECT
  75. quote_literal('1d'::interval), quote_nullable('1d'::interval),
  76. quote_literal('2018-06-11 12:13:14'::timestamp), quote_nullable('2018-06-11 12:13:14'::timestamp),
  77. quote_literal('2018-06-11'::date), quote_nullable('2018-06-11'::date)
  78. ----
  79. '1 day' '1 day' '2018-06-11 12:13:14+00:00' '2018-06-11 12:13:14+00:00' '2018-06-11' '2018-06-11'
  80. query TTBB
  81. SELECT
  82. quote_literal(null::int), quote_nullable(null::int),
  83. quote_literal(null::int) IS NULL, quote_nullable(null::int) IS NULL
  84. ----
  85. NULL NULL true false
  86. # Check that quote_literal is properly sensitive to bytea_output.
  87. query TT
  88. SELECT quote_literal(b'abc'), quote_nullable(b'abc')
  89. ----
  90. e'\\x616263' e'\\x616263'
  91. # TODO: Support bytea
  92. #statement ok
  93. #SET bytea_output = 'escape'
  94. #
  95. #query TT
  96. #SELECT quote_literal(b'abc'), quote_nullable(b'abc')
  97. #----
  98. #'abc' 'abc'
  99. #
  100. #statement ok
  101. #RESET bytea_output
  102. query T colnames
  103. SELECT upper('roacH7')
  104. ----
  105. upper
  106. ROACH7
  107. statement error unknown signature: upper\(decimal\)
  108. SELECT upper(2.2)
  109. query T colnames
  110. SELECT lower('RoacH7')
  111. ----
  112. lower
  113. roach7
  114. statement error unknown signature: lower\(int\)
  115. SELECT lower(32)
  116. # Multiplying by zero so the result is deterministic.
  117. query R
  118. SELECT random() * 0.0
  119. ----
  120. 0
  121. # Concatenating 'empty' because the empty string doesn't work in these tests.
  122. query T
  123. SELECT concat() || 'empty'
  124. ----
  125. empty
  126. query T
  127. SELECT concat('RoacH', NULL)
  128. ----
  129. RoacH
  130. statement error unknown signature: concat\(string, bool, decimal, bool\)
  131. SELECT concat('RoacH', false, 64.532, TRUE)
  132. query T
  133. SELECT substr('RoacH', 2, 3)
  134. ----
  135. oac
  136. query T
  137. SELECT substring('RoacH', 2, 3)
  138. ----
  139. oac
  140. query T
  141. SELECT substring('💩oacH', 2, 3)
  142. ----
  143. oac
  144. query T
  145. SELECT substring('RoacH' from 2 for 3)
  146. ----
  147. oac
  148. query T
  149. SELECT substring('RoacH' for 3 from 2)
  150. ----
  151. oac
  152. query T
  153. SELECT substr('RoacH', 2)
  154. ----
  155. oacH
  156. query T
  157. SELECT substr('💩oacH', 2)
  158. ----
  159. oacH
  160. query T
  161. SELECT substring('RoacH' from 2)
  162. ----
  163. oacH
  164. query T
  165. SELECT substr('RoacH', -2)
  166. ----
  167. RoacH
  168. query T
  169. SELECT substr('RoacH', -2, 4)
  170. ----
  171. R
  172. query T
  173. SELECT substr('12345', 2, 77)
  174. ----
  175. 2345
  176. query T
  177. SELECT substr('12345', -2, 77)
  178. ----
  179. 12345
  180. statement error substr\(\): negative substring length -1 not allowed
  181. SELECT substr('12345', 2, -1)
  182. query T
  183. SELECT substr('string', 4827075662841736053, 5123273972570225659) || 'empty'
  184. ----
  185. empty
  186. query T
  187. SELECT substring('12345' for 3)
  188. ----
  189. 123
  190. query T
  191. SELECT substring('foobar' from 'o.b')
  192. ----
  193. oob
  194. query T
  195. SELECT substring('f(oabaroob' from '\(o(.)b')
  196. ----
  197. a
  198. query T
  199. SELECT substring('f(oabaroob' from '+(o(.)b' for '+')
  200. ----
  201. a
  202. query error substring\(\): error parsing regexp: missing closing \): `\\\\\(o\(.\)b`
  203. SELECT substring('f(oabaroob' from '\(o(.)b' for '+')
  204. query error unknown signature: substring\(\)
  205. SELECT substring()
  206. query error unknown signature: concat_ws\(\)
  207. SELECT concat_ws()
  208. query T
  209. SELECT concat_ws(NULL::STRING, 'a', 'b')
  210. ----
  211. NULL
  212. query T
  213. SELECT concat_ws(',', 'abcde', NULL)
  214. ----
  215. abcde
  216. query T
  217. SELECT concat_ws(',', 'abcde', '2')
  218. ----
  219. abcde,2
  220. statement error unknown signature: concat_ws\(string, string, int, unknown, int\)
  221. SELECT concat_ws(',', 'abcde', 2, NULL, 22)
  222. query T
  223. SELECT split_part('abc~@~def~@~ghi', '~@~', 2)
  224. ----
  225. def
  226. query T
  227. SELECT repeat('Pg', 4)
  228. ----
  229. PgPgPgPg
  230. query T
  231. SELECT repeat('Pg', -1) || 'empty'
  232. ----
  233. empty
  234. statement error pq: repeat\(\): requested length too large
  235. SELECT repeat('s', 9223372036854775807)
  236. # Regression for database-issues#5638.
  237. statement error pq: repeat\(\): requested length too large
  238. SELECT repeat('1234567890'::string, 6978072892806141784::int)
  239. query I
  240. SELECT ascii('x')
  241. ----
  242. 120
  243. query I
  244. select ascii('禅')
  245. ----
  246. 31109
  247. query error ascii\(\): the input string must not be empty
  248. select ascii('')
  249. query T
  250. select chr(122)
  251. ----
  252. z
  253. query T
  254. select chr(ascii('Z'))
  255. ----
  256. Z
  257. query T
  258. select chr(31109)
  259. ----
  260. query error chr\(\): input value must be >= 0
  261. SELECT chr(-1)
  262. query T
  263. SELECT md5('abc')
  264. ----
  265. 900150983cd24fb0d6963f7d28e17f72
  266. query T
  267. SELECT sha1('abc')
  268. ----
  269. a9993e364706816aba3e25717850c26c9cd0d89d
  270. query T
  271. SELECT sha256('abc')
  272. ----
  273. ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
  274. query IIII
  275. SELECT fnv32('abc'), fnv32a('abc'), fnv64('abc'), fnv64a('abc')
  276. ----
  277. 1134309195 440920331 -2820157060406071861 -1792535898324117685
  278. query II
  279. SELECT crc32ieee('abc'), crc32c('abc')
  280. ----
  281. 891568578 910901175
  282. # Regression tests for materialize#29754
  283. query T
  284. SELECT md5(NULL::STRING)
  285. ----
  286. NULL
  287. query T
  288. SELECT md5('')
  289. ----
  290. d41d8cd98f00b204e9800998ecf8427e
  291. query T
  292. SELECT md5(NULL::STRING, NULL::STRING)
  293. ----
  294. NULL
  295. query T
  296. SELECT sha1(NULL::STRING)
  297. ----
  298. NULL
  299. query T
  300. SELECT sha256(NULL::STRING)
  301. ----
  302. NULL
  303. query T
  304. SELECT sha512(NULL::STRING, NULL::STRING)
  305. ----
  306. NULL
  307. query T
  308. SELECT fnv32(NULL::STRING)
  309. ----
  310. NULL
  311. query T
  312. SELECT to_hex(2147483647)
  313. ----
  314. 7fffffff
  315. query I
  316. SELECT strpos('high', 'a')
  317. ----
  318. 0
  319. query I
  320. SELECT strpos('high', 'ig')
  321. ----
  322. 2
  323. query I
  324. SELECT strpos('💩high', 'ig')
  325. ----
  326. 3
  327. query I
  328. SELECT position('ig' in 'high')
  329. ----
  330. 2
  331. query I
  332. SELECT position('a' in 'high')
  333. ----
  334. 0
  335. query error unknown signature: strpos\(\)
  336. SELECT position()
  337. query T
  338. SELECT overlay('123456789' placing 'xxxx' from 3)
  339. ----
  340. 12xxxx789
  341. query T
  342. SELECT overlay('123456789' placing 'xxxx' from 3 for 2)
  343. ----
  344. 12xxxx56789
  345. query T
  346. SELECT overlay('123456789' placing 'xxxx' from 3 for 6)
  347. ----
  348. 12xxxx9
  349. query T
  350. SELECT overlay('123456789' placing 'xxxx' from 15 for 6)
  351. ----
  352. 123456789xxxx
  353. query T
  354. SELECT overlay('123456789' placing 'xxxx' from 3 for 10)
  355. ----
  356. 12xxxx
  357. query T
  358. SELECT overlay('123456789' placing 'xxxx' from 3 for -1)
  359. ----
  360. 12xxxx23456789
  361. query T
  362. SELECT overlay('123456789' placing 'xxxx' from 3 for -8)
  363. ----
  364. 12xxxx123456789
  365. query T
  366. SELECT overlay('💩123456789' placing 'xxxxÂ' from 3 for 3)
  367. ----
  368. 💩1xxxxÂ56789
  369. query error non-positive substring length not allowed: -1
  370. SELECT overlay('123456789' placing 'xxxx' from -1 for 6)
  371. query T
  372. SELECT btrim('xyxtrimyyx', 'xy')
  373. ----
  374. trim
  375. query T
  376. SELECT trim('xy' from 'xyxtrimyyx')
  377. ----
  378. trim
  379. query T
  380. SELECT trim(both 'xy' from 'xyxtrimyyx')
  381. ----
  382. trim
  383. query T
  384. SELECT 'a' || btrim(' postgres ') || 'b'
  385. ----
  386. apostgresb
  387. query T
  388. SELECT ltrim('zzzytrimxyz', 'xyz')
  389. ----
  390. trimxyz
  391. query T
  392. SELECT trim(leading 'xyz' from 'zzzytrimxyz')
  393. ----
  394. trimxyz
  395. query T
  396. SELECT ltrim(' trimxyz')
  397. ----
  398. trimxyz
  399. query T
  400. SELECT trim(leading ' trimxyz')
  401. ----
  402. trimxyz
  403. query T
  404. SELECT trim(leading from ' trimxyz')
  405. ----
  406. trimxyz
  407. query T
  408. SELECT rtrim('xyzzzzytrimxyz', 'xyz')
  409. ----
  410. xyzzzzytrim
  411. query T
  412. SELECT trim(trailing 'xyz' from 'xyzzzzytrimxyz')
  413. ----
  414. xyzzzzytrim
  415. query T
  416. SELECT 'a' || rtrim(' zzzytrimxyz ')
  417. ----
  418. a zzzytrimxyz
  419. query T
  420. SELECT reverse('abcde')
  421. ----
  422. edcba
  423. query T
  424. SELECT reverse('世界')
  425. ----
  426. 界世
  427. query T
  428. SELECT replace('abcdefabcdef', 'cd', 'XX')
  429. ----
  430. abXXefabXXef
  431. query T
  432. SELECT replace(initcap('hi THOMAS'), ' ', '')
  433. ----
  434. HiThomas
  435. query T
  436. SELECT initcap('THOMAS')
  437. ----
  438. Thomas
  439. query T
  440. SELECT left('💩abcde'::bytes, 2)
  441. ----
  442. [240 159]
  443. query T
  444. SELECT right('abcde💩'::bytes, 2)
  445. ----
  446. [146 169]
  447. query T
  448. SELECT left('💩abcde', 2)
  449. ----
  450. 💩a
  451. query T
  452. SELECT right('abcde💩', 2)
  453. ----
  454. e💩
  455. query RRRIIR
  456. SELECT abs(-1.2::float), abs(1.2::float), abs(-0.0::float), abs(0), abs(1), abs(-1.2121::decimal)
  457. ----
  458. 1.2 1.2 0 0 1 1.2121
  459. query R
  460. SELECT abs(NULL)
  461. ----
  462. NULL
  463. query error abs\(\): abs of min integer value \(-9223372036854775808\) not defined
  464. SELECT abs(-9223372036854775808)
  465. query I
  466. SELECT abs(-9223372036854775807)
  467. ----
  468. 9223372036854775807
  469. query B
  470. SELECT abs(sin(pi())) < 1e-12
  471. ----
  472. true
  473. subtest standard_float_digits
  474. query RR
  475. SELECT acos(-0.5), round(acos(0.5), 15)
  476. ----
  477. 2.0943951023932 1.0471975511966
  478. query RR
  479. SELECT cot(-0.5), cot(0.5)
  480. ----
  481. -1.83048772171245 1.83048772171245
  482. query RRR
  483. SELECT asin(-0.5), asin(0.5), asin(1.5)
  484. ----
  485. -0.523598775598299 0.523598775598299 NaN
  486. query RR
  487. SELECT atan(-0.5), atan(0.5)
  488. ----
  489. -0.463647609000806 0.463647609000806
  490. query RR
  491. SELECT atan2(-10.0, 5.0), atan2(10.0, 5.0)
  492. ----
  493. -1.10714871779409 1.10714871779409
  494. query RRR
  495. SELECT cbrt(-1.0::float), round(cbrt(27.0::float), 15), cbrt(19.3::decimal)
  496. ----
  497. -1 3 2.6823725926296729544
  498. query RRRRR
  499. SELECT ceil(-0.5::float), ceil(0.5::float), ceiling(0.5::float), ceil(0.1::decimal), ceiling (-0.9::decimal)
  500. ----
  501. -0 1 1 1 0
  502. query RR
  503. SELECT cos(-0.5), cos(0.5)
  504. ----
  505. 0.877582561890373 0.877582561890373
  506. query RRR
  507. SELECT sin(-1.0), sin(0.0), sin(1.0)
  508. ----
  509. -0.841470984807897 0 0.841470984807897
  510. query RR
  511. SELECT degrees(-0.5), degrees(0.5)
  512. ----
  513. -28.6478897565412 28.6478897565412
  514. subtest extra_float_digits_3
  515. statement ok
  516. SET extra_float_digits = 3
  517. query RR
  518. SELECT acos(-0.5), round(acos(0.5), 15)
  519. ----
  520. 2.0943951023931957 1.047197551196598
  521. query RR
  522. SELECT cot(-0.5), cot(0.5)
  523. ----
  524. -1.830487721712452 1.830487721712452
  525. query RRR
  526. SELECT asin(-0.5), asin(0.5), asin(1.5)
  527. ----
  528. -0.5235987755982989 0.5235987755982989 NaN
  529. query RR
  530. SELECT atan(-0.5), atan(0.5)
  531. ----
  532. -0.4636476090008061 0.4636476090008061
  533. query RR
  534. SELECT atan2(-10.0, 5.0), atan2(10.0, 5.0)
  535. ----
  536. -1.1071487177940904 1.1071487177940904
  537. query RRR
  538. SELECT cbrt(-1.0::float), round(cbrt(27.0::float), 15), cbrt(19.3::decimal)
  539. ----
  540. -1 3 2.6823725926296729544
  541. query RRRRR
  542. SELECT ceil(-0.5::float), ceil(0.5::float), ceiling(0.5::float), ceil(0.1::decimal), ceiling(-0.9::decimal)
  543. ----
  544. -0 1 1 1 0
  545. query RR
  546. SELECT cos(-0.5), cos(0.5)
  547. ----
  548. 0.8775825618903728 0.8775825618903728
  549. query RRR
  550. SELECT sin(-1.0), sin(0.0), sin(1.0)
  551. ----
  552. -0.8414709848078965 0 0.8414709848078965
  553. query RR
  554. SELECT degrees(-0.5), degrees(0.5)
  555. ----
  556. -28.64788975654116 28.64788975654116
  557. statement ok
  558. SET extra_float_digits = 0
  559. subtest other_tests
  560. query IIII
  561. SELECT div(-1::int, 2::int), div(1::int, 2::int), div(9::int, 4::int), div(-9::int, 4::int)
  562. ----
  563. 0 0 2 -2
  564. query RRRRRR
  565. SELECT div(-1.0::float, 2.0), div(1.0::float, 2.0), div(9.0::float, 4.0), div(-9.0::float, 4.0), div(1.0::float, 0.0), div(1111.0::decimal, 9.44)
  566. ----
  567. -0 0 2 -2 +Inf 117
  568. query error div\(\): division by zero
  569. SELECT div(1.0::decimal, 0.0::decimal)
  570. query error div\(\): division by zero
  571. SELECT div(1::int, 0::int)
  572. # math.Exp(1.0) returns different results on amd64 vs arm64.
  573. # Round to make this test consistent across archs.
  574. # See https://github.com/golang/go/issues/20319.
  575. query RRR
  576. SELECT exp(-1.0::float), round(exp(1.0::float), 13), exp(2.0::decimal)
  577. ----
  578. 0.367879441171442 2.718281828459 7.3890560989306502272
  579. query error exp\(\): overflow
  580. SELECT exp(1e2000::decimal)
  581. query RRR
  582. SELECT floor(-1.5::float), floor(1.5::float), floor(9.123456789::decimal)
  583. ----
  584. -2 1 9
  585. query BBBBBB
  586. SELECT 1::FLOAT IS NAN, 1::FLOAT IS NOT NAN, isnan(1::FLOAT), 'NaN'::FLOAT IS NAN, 'NaN'::FLOAT IS NOT NAN, isnan('NaN'::FLOAT)
  587. ----
  588. false true false true false true
  589. query RRR
  590. SELECT ln(-2.0::float), ln(2.0::float), ln(2.5::decimal)
  591. ----
  592. NaN 0.693147180559945 0.91629073187415506518
  593. query error cannot take logarithm of a negative number
  594. SELECT ln(-100.000::decimal)
  595. query error cannot take logarithm of zero
  596. SELECT ln(0::decimal)
  597. query RR
  598. SELECT log(10.0::float), log(100.000::decimal)
  599. ----
  600. 1 2.0000000000000000000
  601. query error cannot take logarithm of a negative number
  602. SELECT log(-100.000::decimal)
  603. query error cannot take logarithm of zero
  604. SELECT log(0::decimal)
  605. query RRIR
  606. SELECT mod(5.0::float, 2.0), mod(1.0::float, 0.0), mod(5, 2), mod(19.3::decimal, 2)
  607. ----
  608. 1 NaN 1 1.3
  609. # mod returns the same results as PostgreSQL 9.4.4
  610. # in tests below (except for the error message).
  611. query error mod\(\): zero modulus
  612. SELECT mod(5, 0)
  613. query error mod\(\): zero modulus
  614. SELECT mod(5::decimal, 0::decimal)
  615. query II
  616. SELECT mod(-100, -8), mod(-100, 8)
  617. ----
  618. -4 -4
  619. query I
  620. SELECT mod(-9223372036854775808, 3)
  621. ----
  622. -2
  623. query I
  624. SELECT mod(-9223372036854775808, -1)
  625. ----
  626. 0
  627. query I
  628. SELECT mod(9223372036854775807, -1)
  629. ----
  630. 0
  631. query I
  632. SELECT mod(9223372036854775807, -2)
  633. ----
  634. 1
  635. query I
  636. SELECT mod(9223372036854775807, 1)
  637. ----
  638. 0
  639. query I
  640. SELECT mod(9223372036854775807, 2)
  641. ----
  642. 1
  643. query I
  644. SELECT mod(9223372036854775807, 4)
  645. ----
  646. 3
  647. # div and mod are a logical pair
  648. query R
  649. SELECT div(9.0::float, 2.0) * 2.0 + mod(9.0::float, 2.0)
  650. ----
  651. 9
  652. query R
  653. SELECT div(9.0::float, -2.0) * -2.0 + mod(9.0::float, -2.0)
  654. ----
  655. 9
  656. query R
  657. SELECT div(-9.0::float, 2.0) * 2.0 + mod(-9.0::float, 2.0)
  658. ----
  659. -9
  660. query R
  661. SELECT div(-9.0::float, -2.0) * -2.0 + mod(-9.0::float, -2.0)
  662. ----
  663. -9
  664. query R
  665. SELECT pi()
  666. ----
  667. 3.14159265358979
  668. query II
  669. SELECT pow(-2::int, 3::int), pow(2::int, 3::int)
  670. ----
  671. -8 8
  672. statement error integer out of range
  673. SELECT pow(2::int, -3::int)
  674. query III
  675. SELECT pow(0::int, 3::int), pow(3::int, 0::int), pow(-3::int, 0::int)
  676. ----
  677. 0 1 1
  678. statement error integer out of range
  679. SELECT pow(0::int, -3::int)
  680. # TODO(mjibson): This uses the decimal implementation internally, which
  681. # returns NaN, hence the below error. However postgres returns 1 for this,
  682. # which we should probably match.
  683. statement error integer out of range
  684. SELECT pow(0::int, 0::int)
  685. query RRR
  686. SELECT pow(-3.0::float, 2.0), power(3.0::float, 2.0), pow(5.0::decimal, 2.0)
  687. ----
  688. 9 9 25.00
  689. query R
  690. SELECT pow(CAST (pi() AS DECIMAL), DECIMAL '2.0')
  691. ----
  692. 9.8696044010893571205
  693. query R
  694. SELECT power(0::decimal, -1)
  695. ----
  696. Infinity
  697. # TODO(mjibson): Postgres returns an error for this.
  698. query R
  699. SELECT power(-1, -.1)
  700. ----
  701. NaN
  702. query RR
  703. SELECT radians(-45.0), radians(45.0)
  704. ----
  705. -0.785398163397448 0.785398163397448
  706. query R
  707. SELECT round(123.456::float, -2438602134409251682)
  708. ----
  709. NaN
  710. query RRR
  711. SELECT round(4.2::float, 0), round(4.2::float, 10), round(4.22222222::decimal, 3)
  712. ----
  713. 4 4.2 4.222
  714. query R
  715. SELECT round(1e-308::float, 324)
  716. ----
  717. 1e-308
  718. # round to nearest even
  719. query RRRR
  720. SELECT round(-2.5::float, 0), round(-1.5::float, 0), round(1.5::float, 0), round(2.5::float, 0)
  721. ----
  722. -2 -2 2 2
  723. query RRRRRR
  724. SELECT round(-2.5::float), round(-1.5::float), round(-0.0::float), round(0.0::float), round(1.5::float), round(2.5::float)
  725. ----
  726. -2 -2 -0 0 2 2
  727. # some edge cases: denormal, 0.5-epsilon, 0.5+epsilon, 1 bit fractions, 1 bit fraction rounding to 0 bit fraction, large integer
  728. query RRRRRRR
  729. SELECT round(1.390671161567e-309::float), round(0.49999999999999994::float), round(0.5000000000000001::float), round(2251799813685249.5::float), round(2251799813685250.5::float), round(4503599627370495.5::float), round(4503599627370497::float)
  730. ----
  731. 0 0 1 2.25179981368525e+15 2.25179981368525e+15 4.5035996273705e+15 4.5035996273705e+15
  732. # round up for decimals
  733. # These results are indeed different than floats. Compare with postgres.
  734. # Float rounding uses banker, decimal rounding uses half away from zero.
  735. query RRRR
  736. SELECT round(-2.5::decimal, 0), round(-1.5::decimal, 0), round(1.5::decimal, 0), round(2.5::decimal, 0)
  737. ----
  738. -3 -2 2 3
  739. query RRRRR
  740. SELECT round(-2.5::decimal, 3), round(-1.5::decimal, 3), round(0.0::decimal, 3), round(1.5::decimal, 3), round(2.5::decimal, 3)
  741. ----
  742. -2.500 -1.500 0.000 1.500 2.500
  743. query RRRRR
  744. SELECT round(-2.5::decimal), round(-1.5::decimal), round(0.0::decimal), round(1.5::decimal), round(2.5::decimal)
  745. ----
  746. -3 -2 0 2 3
  747. subtest round_max_prec
  748. # Test rounding to 14 digits, because the logic test itself
  749. # formats floats rounded to 15 digits behind the decimal point.
  750. statement ok
  751. SET extra_float_digits = 3
  752. query RRR
  753. SELECT round(-2.123456789, 5), round(2.123456789, 5), round(2.12345678901234567890, 14)
  754. ----
  755. -2.12346 2.12346 2.12345678901235
  756. query RR
  757. SELECT round(-1.7976931348623157e+308::float, 1), round(1.7976931348623157e+308::float, 1)
  758. ----
  759. -1.7976931348623157e+308 1.7976931348623157e+308
  760. query RR
  761. SELECT round(-1.7976931348623157e+308::float, -303), round(1.7976931348623157e+308::float, -303)
  762. ----
  763. -1.79769e+308 1.79769e+308
  764. query RR
  765. SELECT round(-1.23456789e+308::float, -308), round(1.23456789e+308::float, -308)
  766. ----
  767. -1e+308 1e+308
  768. query RRRR
  769. SELECT 1.234567890123456789::float, round(1.234567890123456789::float, 15), round(1.234567890123456789::float, 16), round(1.234567890123456789::float, 17)
  770. ----
  771. 1.2345678901234567 1.234567890123457 1.2345678901234567 1.2345678901234567
  772. statement ok
  773. SET extra_float_digits = 0
  774. subtest round_low_prec
  775. statement ok
  776. SET extra_float_digits = -6
  777. query RRR
  778. SELECT round(-2.123456789, 5), round(2.123456789, 5), round(2.12345678901234567890, 14)
  779. ----
  780. -2.12346 2.12346 2.12345678901235
  781. query RR
  782. SELECT round(-1.7976931348623157e+308::float, 1), round(1.7976931348623157e+308::float, 1)
  783. ----
  784. -1.79769313e+308 1.79769313e+308
  785. query RR
  786. SELECT round(-1.7976931348623157e+308::float, -303), round(1.7976931348623157e+308::float, -303)
  787. ----
  788. -1.79769e+308 1.79769e+308
  789. query RR
  790. SELECT round(-1.23456789e+308::float, -308), round(1.23456789e+308::float, -308)
  791. ----
  792. -1e+308 1e+308
  793. query RRRR
  794. SELECT 1.234567890123456789::float, round(1.234567890123456789::float, 15), round(1.234567890123456789::float, 16), round(1.234567890123456789::float, 17)
  795. ----
  796. 1.23456789 1.23456789 1.23456789 1.23456789
  797. statement ok
  798. SET extra_float_digits = 0
  799. subtest more_round_tests
  800. query RR
  801. SELECT round(-1.7976931348623157e-308::float, 1), round(1.7976931348623157e-308::float, 1)
  802. ----
  803. -0 0
  804. query RRR
  805. SELECT round(123.456::float, -1), round(123.456::float, -2), round(123.456::float, -3)
  806. ----
  807. 120 100 0
  808. query RRRR
  809. SELECT round(123.456::decimal, -1), round(123.456::decimal, -2), round(123.456::decimal, -3), round(123.456::decimal, -200)
  810. ----
  811. 1.2E+2 1E+2 0E+3 0E+200
  812. query RRRR
  813. SELECT round('nan'::decimal), round('nan'::decimal, 1), round('nan'::float), round('nan'::float, 1)
  814. ----
  815. NaN NaN NaN NaN
  816. # Match postgres float round for inf.
  817. query RRRR
  818. SELECT round('inf'::float), round('inf'::float, 1), round('-inf'::float), round('-inf'::float, 1)
  819. ----
  820. +Inf +Inf -Inf -Inf
  821. # But decimal round (which isn't supported at all in postgres because
  822. # postgres doesn't support NaN or Inf for its decimals) conforms to
  823. # the GDA spec.
  824. query R
  825. SELECT round('inf'::decimal)
  826. ----
  827. NaN
  828. query R
  829. SELECT round(1::decimal, 3000)
  830. ----
  831. NaN
  832. subtest more_tests
  833. query III
  834. SELECT sign(-2), sign(0), sign(2)
  835. ----
  836. -1 0 1
  837. query RRRR
  838. SELECT sign(-2.0), sign(-0.0), sign(0.0), sign(2.0)
  839. ----
  840. -1 0 0 1
  841. query RR
  842. SELECT sqrt(4.0::float), sqrt(9.0::decimal)
  843. ----
  844. 2 3
  845. query error cannot take square root of a negative number
  846. SELECT sqrt(-1.0::float)
  847. query error cannot take square root of a negative number
  848. SELECT sqrt(-1.0::decimal)
  849. query RRR
  850. SELECT round(tan(-5.0), 14), tan(0.0), round(tan(5.0), 14)
  851. ----
  852. 3.38051500624659 0 -3.38051500624659
  853. query RRRR
  854. SELECT trunc(-0.0), trunc(0.0), trunc(1.9), trunc(19.5678::decimal)
  855. ----
  856. 0 0 1 19
  857. query T
  858. SELECT translate('Techonthenet.com', 'e.to', '456')
  859. ----
  860. T4chn6h4n465cm
  861. query T
  862. SELECT translate('12345', '143', 'ax')
  863. ----
  864. a2x5
  865. query T
  866. SELECT translate('12345', 'abc', 'ax')
  867. ----
  868. 12345
  869. query T
  870. SELECT translate('a‰ÒÁ', 'aÒ', '∏p')
  871. ----
  872. ∏‰pÁ
  873. query T
  874. SELECT regexp_extract('foobar', 'o.b')
  875. ----
  876. oob
  877. query T
  878. SELECT regexp_extract('foobar', 'o(.)b')
  879. ----
  880. o
  881. query T
  882. SELECT regexp_extract('foobar', '(o(.)b)')
  883. ----
  884. oob
  885. query T
  886. SELECT regexp_extract('foabaroob', 'o(.)b')
  887. ----
  888. a
  889. query T
  890. SELECT regexp_extract('foobar', 'o.x')
  891. ----
  892. NULL
  893. query T
  894. SELECT regexp_replace('foobarbaz', 'b..', 'X')
  895. ----
  896. fooXbaz
  897. query T
  898. SELECT regexp_replace('foobarbaz', 'b..', 'X', 'g')
  899. ----
  900. fooXX
  901. query T
  902. SELECT regexp_replace('foobarbaz', 'b(..)', E'X\\1Y', 'g')
  903. ----
  904. fooXarYXazY
  905. query T
  906. SELECT regexp_replace('foobarbaz', 'b(.)(.)', E'X\\2\\1\\3Y', 'g')
  907. ----
  908. fooXraYXzaY
  909. query T
  910. SELECT regexp_replace(E'fooBa\nrbaz', 'b(..)', E'X\\&Y', 'gi')
  911. ----
  912. fooXBa
  913. YrXbazY
  914. query T
  915. SELECT regexp_replace(E'fooBa\nrbaz', 'b(..)', E'X\\&Y', 'gmi')
  916. ----
  917. fooBa
  918. rXbazY
  919. query T
  920. SELECT regexp_replace(E'fooBar\nbaz', 'b(..)$', E'X\\&Y', 'gpi')
  921. ----
  922. fooBar
  923. XbazY
  924. query T
  925. SELECT regexp_replace(E'fooBar\nbaz', 'b(..)$', E'X\\&Y', 'gwi')
  926. ----
  927. fooXBarY
  928. XbazY
  929. query T
  930. SELECT regexp_replace('foobarbaz', 'nope', 'NO')
  931. ----
  932. foobarbaz
  933. query error regexp_replace\(\): invalid regexp flag: 'z'
  934. SELECT regexp_replace(E'fooBar\nbaz', 'b(..)$', E'X\\&Y', 'z')
  935. query T
  936. SELECT regexp_replace(E'Foo\nFoo', '^(foo)', 'BAR', 'i')
  937. ----
  938. BAR
  939. Foo
  940. query T
  941. SELECT regexp_replace(e'DOGGIE\ndog \nDOG', '^d.+', 'CAT', 's')
  942. ----
  943. DOGGIE
  944. dog
  945. DOG
  946. query T
  947. SELECT regexp_replace(e'DOGGIE\ndog \nDOG', '^d.+', 'CAT', 'n');
  948. ----
  949. DOGGIE
  950. CAT
  951. DOG
  952. query T
  953. SELECT regexp_replace(e'DOGGIE\ndog \nDOG', '^D.+', 'CAT', 'p')
  954. ----
  955. CAT
  956. dog
  957. DOG
  958. query T
  959. SELECT regexp_replace(e'DOGGIE\ndog \nDOG', '^d.+', 'CAT', 'w')
  960. ----
  961. DOGGIE
  962. CAT
  963. query T
  964. SELECT regexp_replace('abc', 'b', e'\n', 'w')
  965. ----
  966. a
  967. c
  968. query T
  969. SELECT regexp_replace('abc\', 'b', 'a', 'w')
  970. ----
  971. aac\
  972. query T
  973. SELECT regexp_replace('abc', 'c', 'a\', 'w')
  974. ----
  975. aba\
  976. # database-issues#5644
  977. query T
  978. SELECT regexp_replace('ReRe','R(e)','1\\1','g');
  979. ----
  980. 1\11\1
  981. query B
  982. SELECT unique_rowid() < unique_rowid()
  983. ----
  984. true
  985. query BI
  986. SELECT uuid_v4() != uuid_v4(), length(uuid_v4())
  987. ----
  988. true 16
  989. query error syntax error at or near.*
  990. SELECT greatest()
  991. query error syntax error at or near.*
  992. SELECT least()
  993. query I
  994. SELECT greatest(4, 5, 7, 1, 2)
  995. ----
  996. 7
  997. query I
  998. SELECT least(4, 5, 7, 1, 2)
  999. ----
  1000. 1
  1001. query I
  1002. SELECT greatest(4, NULL, 7, 1, 2)
  1003. ----
  1004. 7
  1005. query I
  1006. SELECT greatest(NULL, NULL, 7, NULL, 2)
  1007. ----
  1008. 7
  1009. query I
  1010. SELECT greatest(NULL, NULL, NULL, NULL, 2)
  1011. ----
  1012. 2
  1013. query I
  1014. SELECT greatest(2, NULL, NULL, NULL, NULL)
  1015. ----
  1016. 2
  1017. query I
  1018. SELECT least(4, NULL, 7, 1, 2)
  1019. ----
  1020. 1
  1021. query I
  1022. SELECT greatest(NULL, NULL, NULL)
  1023. ----
  1024. NULL
  1025. query I
  1026. SELECT least(NULL, NULL, NULL)
  1027. ----
  1028. NULL
  1029. query I
  1030. SELECT greatest(2, '4')
  1031. ----
  1032. 4
  1033. query I
  1034. SELECT least(2, '4')
  1035. ----
  1036. 2
  1037. query T
  1038. SELECT greatest('foo', 'bar', 'foobar')
  1039. ----
  1040. foobar
  1041. query T
  1042. SELECT least('foo', 'bar', 'foobar')
  1043. ----
  1044. bar
  1045. query R
  1046. SELECT greatest(1, 1.2)
  1047. ----
  1048. 1.2
  1049. # Test homogenous functions that can't be constant folded.
  1050. query I
  1051. SELECT greatest(NULL, a, 5, NULL) FROM foo
  1052. ----
  1053. 5
  1054. query I
  1055. SELECT greatest(NULL, NULL, NULL, a, -1) FROM foo
  1056. ----
  1057. 1
  1058. query I
  1059. SELECT least(NULL, a, 5, NULL) FROM foo
  1060. ----
  1061. 1
  1062. query I
  1063. SELECT least(NULL, NULL, NULL, a, -1) FROM foo
  1064. ----
  1065. -1
  1066. # Test float and int comparison.
  1067. query BBBB
  1068. select 1 = 1.0::float, 1.0::float = 1, 1 = 2.0::float, 2.0::float = 1
  1069. ----
  1070. true true false false
  1071. query BBBB
  1072. select 1 < 2.0::float, 1.0::float < 2, 2.0::float < 1, 2 < 1.0::float
  1073. ----
  1074. true true false false
  1075. query BBBB
  1076. select 1 <= 1.0::float, 1.0::float <= 1, 2.0::float <= 1, 2 <= 1.0::float
  1077. ----
  1078. true true false false
  1079. query BBBB
  1080. select 2 > 1.0::float, 2.0::float > 1, 1 > 2.0::float, 1.0::float > 2
  1081. ----
  1082. true true false false
  1083. query BBBB
  1084. select 1 >= 1.0::float, 1.0::float >= 1, 1.0::float >= 2, 1 >= 2.0::float
  1085. ----
  1086. true true false false
  1087. # Test decimal and int comparison.
  1088. query BBBB
  1089. select 1 = 1.0::decimal, 1.0::decimal = 1, 1 = 2.0::decimal, 2.0::decimal = 1
  1090. ----
  1091. true true false false
  1092. query BBBB
  1093. select 1 < 2.0::decimal, 1.0::decimal < 2, 2.0::decimal < 1, 2 < 1.0::decimal
  1094. ----
  1095. true true false false
  1096. query BBBB
  1097. select 1 <= 1.0::decimal, 1.0::decimal <= 1, 2.0::decimal <= 1, 2 <= 1.0::decimal
  1098. ----
  1099. true true false false
  1100. query BBBB
  1101. select 2 > 1.0::decimal, 2.0::decimal > 1, 1 > 2.0::decimal, 1.0::decimal > 2
  1102. ----
  1103. true true false false
  1104. query BBBB
  1105. select 1 >= 1.0::decimal, 1.0::decimal >= 1, 1.0::decimal >= 2, 1 >= 2.0::decimal
  1106. ----
  1107. true true false false
  1108. # Test float and decimal comparison.
  1109. query BBBB
  1110. select 1::decimal = 1.0, 1.0 = 1::decimal, 1::decimal = 2.0, 2.0 = 1::decimal
  1111. ----
  1112. true true false false
  1113. query BBBB
  1114. select 1::decimal < 2.0, 1.0 < 2::decimal, 2.0 < 1::decimal, 2::decimal < 1.0
  1115. ----
  1116. true true false false
  1117. query BBBB
  1118. select 1::decimal <= 1.0, 1.0 <= 1::decimal, 2.0 <= 1::decimal, 2::decimal <= 1.0
  1119. ----
  1120. true true false false
  1121. query BBBB
  1122. select 2::decimal > 1.0, 2.0 > 1::decimal, 1::decimal > 2.0, 1.0 > 2::decimal
  1123. ----
  1124. true true false false
  1125. query BBBB
  1126. select 1::decimal >= 1.0, 1.0 >= 1::decimal, 1.0 >= 2::decimal, 1::decimal >= 2.0
  1127. ----
  1128. true true false false
  1129. query I
  1130. SELECT strpos(version(), 'CockroachDB')
  1131. ----
  1132. 1
  1133. # Don't panic during incorrect use of * (materialize#7727)
  1134. query error pq: cos\(\): cannot use "\*" in this context
  1135. SELECT cos(*) FROM system.namespace
  1136. # Don't panic with invalid names (database-issues#2461)
  1137. query error cannot use "nonexistent.\*" without a FROM clause
  1138. SELECT TRIM(TRAILING nonexistent.*[1])
  1139. query error rtrim\(\): cannot subscript type tuple
  1140. SELECT TRIM(TRAILING foo.*[1]) FROM (VALUES (1)) AS foo(x)
  1141. # Don't panic with invalid names (database-issues#2460)
  1142. query error cannot use "nonexistent.\*" without a FROM clause
  1143. SELECT OVERLAY(nonexistent.* PLACING 'string' FROM 'string')
  1144. query error unknown signature
  1145. SELECT OVERLAY(foo.* PLACING 'string' FROM 'string') FROM (VALUES (1)) AS foo(x)
  1146. # Don't panic with invalid names (database-issues#2455)
  1147. query error cannot use "nonexistent.\*" without a FROM clause
  1148. SELECT nonexistent.* IS NOT TRUE
  1149. query error unsupported comparison operator: <tuple\{int AS x\}> IS DISTINCT FROM <bool>
  1150. SELECT foo.* IS NOT TRUE FROM (VALUES (1)) AS foo(x)
  1151. query T
  1152. SELECT current_schemas(true)
  1153. ----
  1154. {pg_catalog,public}
  1155. query T
  1156. SELECT current_schemas(false)
  1157. ----
  1158. {public}
  1159. # Force the function to be evaluated at execution time and verify it doesn't
  1160. # break when distsql is on.
  1161. query T
  1162. SELECT current_schemas(x) FROM (VALUES (true), (false)) AS t(x);
  1163. ----
  1164. {pg_catalog,public}
  1165. {public}
  1166. statement ok
  1167. SET search_path=test,pg_catalog
  1168. query T
  1169. SELECT current_schemas(true)
  1170. ----
  1171. {pg_catalog}
  1172. query T
  1173. SELECT current_schemas(false)
  1174. ----
  1175. {pg_catalog}
  1176. statement ok
  1177. RESET search_path
  1178. query error pq: unknown signature: current_schemas()
  1179. SELECT current_schemas()
  1180. query T
  1181. SELECT current_schemas(NULL::bool)
  1182. ----
  1183. NULL
  1184. query B
  1185. SELECT 'public' = ANY (current_schemas(true))
  1186. ----
  1187. true
  1188. query B
  1189. SELECT 'not test' = ANY (current_schemas(true))
  1190. ----
  1191. false
  1192. query B
  1193. SELECT pg_catalog.pg_table_is_visible('foo'::regclass)
  1194. ----
  1195. true
  1196. statement ok
  1197. SET search_path = pg_catalog
  1198. query B
  1199. SELECT pg_catalog.pg_table_is_visible((SELECT oid FROM pg_class WHERE relname='foo'))
  1200. ----
  1201. false
  1202. statement ok
  1203. SET SEARCH_PATH = public, pg_catalog
  1204. query B
  1205. SELECT pg_catalog.pg_table_is_visible((SELECT oid FROM pg_class WHERE relname='foo'))
  1206. ----
  1207. true
  1208. statement ok
  1209. RESET search_path
  1210. query T
  1211. SELECT current_schema()
  1212. ----
  1213. public
  1214. query I
  1215. SELECT array_length(ARRAY['a', 'b'], 1)
  1216. ----
  1217. 2
  1218. query I
  1219. SELECT array_length(ARRAY['a'], 1)
  1220. ----
  1221. 1
  1222. query I
  1223. SELECT array_length(ARRAY['a'], 0)
  1224. ----
  1225. NULL
  1226. query I
  1227. SELECT array_length(ARRAY['a'], 2)
  1228. ----
  1229. NULL
  1230. query I
  1231. SELECT array_lower(ARRAY['a', 'b'], 1)
  1232. ----
  1233. 1
  1234. query I
  1235. SELECT array_lower(ARRAY['a'], 1)
  1236. ----
  1237. 1
  1238. query I
  1239. SELECT array_lower(ARRAY['a'], 0)
  1240. ----
  1241. NULL
  1242. query I
  1243. SELECT array_lower(ARRAY['a'], 2)
  1244. ----
  1245. NULL
  1246. query I
  1247. SELECT array_upper(ARRAY['a', 'b'], 1)
  1248. ----
  1249. 2
  1250. query I
  1251. SELECT array_upper(ARRAY['a'], 1)
  1252. ----
  1253. 1
  1254. query I
  1255. SELECT array_upper(ARRAY['a'], 0)
  1256. ----
  1257. NULL
  1258. query I
  1259. SELECT array_upper(ARRAY['a'], 2)
  1260. ----
  1261. NULL
  1262. query I
  1263. SELECT array_length(ARRAY[]:::int[], 1)
  1264. ----
  1265. NULL
  1266. query I
  1267. SELECT array_lower(ARRAY[]:::int[], 1)
  1268. ----
  1269. NULL
  1270. query I
  1271. SELECT array_upper(ARRAY[]:::int[], 1)
  1272. ----
  1273. NULL
  1274. query I
  1275. SELECT array_length(ARRAY[ARRAY[1, 2]], 2)
  1276. ----
  1277. 2
  1278. query I
  1279. SELECT array_lower(ARRAY[ARRAY[1, 2]], 2)
  1280. ----
  1281. 1
  1282. query I
  1283. SELECT array_upper(ARRAY[ARRAY[1, 2]], 2)
  1284. ----
  1285. 2
  1286. query T
  1287. SELECT encode('\xa7', 'hex')
  1288. ----
  1289. a7
  1290. query TT
  1291. SELECT encode('abc', 'hex'), decode('616263', 'hex')
  1292. ----
  1293. 616263 abc
  1294. query T
  1295. SELECT encode(e'123\000456', 'escape')
  1296. ----
  1297. 123\000456
  1298. query T
  1299. SELECT decode('123\000456', 'escape')::STRING
  1300. ----
  1301. \x31323300343536
  1302. query TT
  1303. SELECT encode('abc', 'base64'), decode('YWJj', 'base64')
  1304. ----
  1305. YWJj abc
  1306. query T
  1307. SELECT decode('padded==', 'base64')::STRING
  1308. ----
  1309. \xa5a75d79
  1310. query T
  1311. SELECT decode('padded1=', 'base64')::STRING
  1312. ----
  1313. \xa5a75d79dd
  1314. query error illegal base64 data at input byte 4
  1315. SELECT decode('invalid', 'base64')
  1316. query error only 'hex', 'escape', and 'base64' formats are supported for encode\(\)
  1317. SELECT encode('abc', 'fake')
  1318. query error only 'hex', 'escape', and 'base64' formats are supported for decode\(\)
  1319. SELECT decode('abc', 'fake')
  1320. query T
  1321. SELECT from_ip(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x01\x02\x03\x04')
  1322. ----
  1323. 1.2.3.4
  1324. query T
  1325. SELECT from_ip(to_ip('1.2.3.4'))
  1326. ----
  1327. 1.2.3.4
  1328. # net.IP.String() always gives us the most succinct form of ipv6
  1329. query T
  1330. select from_ip(to_ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334'))
  1331. ----
  1332. 2001:db8:85a3::8a2e:370:7334
  1333. query error pq: unknown signature: to_ip()
  1334. SELECT to_ip()
  1335. query error pq: from_ip\(\): zero length IP
  1336. SELECT from_ip(b'')
  1337. query error pq: to_ip\(\): invalid IP format: ''
  1338. SELECT to_ip('')
  1339. query error pq: to_ip\(\): invalid IP format: 'asdf'
  1340. select to_ip('asdf')
  1341. query R
  1342. select ln(4.0786335175292462e+34::decimal)
  1343. ----
  1344. 79.693655171940461633
  1345. query IB
  1346. SELECT length(gen_random_uuid()::BYTES), gen_random_uuid() = gen_random_uuid()
  1347. ----
  1348. 16 false
  1349. query TTTTTT
  1350. SELECT to_uuid('63616665-6630-3064-6465-616462656566'),
  1351. to_uuid('{63616665-6630-3064-6465-616462656566}'),
  1352. to_uuid('urn:uuid:63616665-6630-3064-6465-616462656566'),
  1353. from_uuid(b'cafef00ddeadbeef'),
  1354. to_uuid(from_uuid(b'cafef00ddeadbeef')),
  1355. from_uuid(to_uuid('63616665-6630-3064-6465-616462656566'))
  1356. ----
  1357. cafef00ddeadbeef
  1358. cafef00ddeadbeef
  1359. cafef00ddeadbeef
  1360. 63616665-6630-3064-6465-616462656566
  1361. cafef00ddeadbeef
  1362. 63616665-6630-3064-6465-616462656566
  1363. query error uuid: incorrect UUID length
  1364. SELECT to_uuid('63616665-6630-3064-6465')
  1365. query error uuid: incorrect UUID length
  1366. SELECT to_uuid('63616665-6630-3064-6465-616462656566-123')
  1367. query error uuid: incorrect UUID format
  1368. SELECT to_uuid('6361666512-6630-3064-6465-616462656566')
  1369. query error uuid: UUID must be exactly 16 bytes long, got 4 bytes
  1370. SELECT from_uuid(b'f00d')
  1371. query T
  1372. SELECT pg_catalog.pg_typeof(sign(1:::decimal))
  1373. ----
  1374. decimal
  1375. query T
  1376. VALUES (pg_typeof(1:::int)),
  1377. (pg_typeof('a':::string)),
  1378. (pg_typeof(true)),
  1379. (pg_typeof(NULL)),
  1380. (pg_typeof('3m':::interval)),
  1381. (pg_typeof('2016-11-12':::date)),
  1382. (pg_typeof(now():::timestamptz)),
  1383. (pg_typeof(b'a':::bytes)),
  1384. (pg_typeof(array[1,2,3]))
  1385. ----
  1386. int
  1387. string
  1388. bool
  1389. unknown
  1390. interval
  1391. date
  1392. timestamptz
  1393. bytes
  1394. int[]
  1395. # TODO(def-): Reenable after database-issues#6599 is fixed
  1396. # query T
  1397. # VALUES (format_type('anyelement'::regtype, -1)),
  1398. # (format_type('bit'::regtype, -1)),
  1399. # (format_type('bool'::regtype, -1)),
  1400. # (format_type('bytea'::regtype, -1)),
  1401. # (format_type('char'::regtype, -1)),
  1402. # (format_type('date'::regtype, -1)),
  1403. # (format_type('decimal'::regtype, -1)),
  1404. # (format_type('float'::regtype, -1)),
  1405. # (format_type('float4'::regtype, -1)),
  1406. # (format_type('interval'::regtype, -1)),
  1407. # (format_type('numeric'::regtype, -1)),
  1408. # (format_type('oid'::regtype, -1)),
  1409. # (format_type('oidvector'::regtype, -1)),
  1410. # (format_type('inet'::regtype, -1)),
  1411. # (format_type('int'::regtype, -1)),
  1412. # (format_type('int4'::regtype, -1)),
  1413. # (format_type('int2'::regtype, -1)),
  1414. # (format_type('int2vector'::regtype, -1)),
  1415. # (format_type('interval'::regtype, -1)),
  1416. # (format_type('json'::regtype, -1)),
  1417. # (format_type('name'::regtype, -1)),
  1418. # (format_type('regclass'::regtype, -1)),
  1419. # (format_type('regnamespace'::regtype, -1)),
  1420. # (format_type('regproc'::regtype, -1)),
  1421. # (format_type('regprocedure'::regtype, -1)),
  1422. # (format_type('regtype'::regtype, -1)),
  1423. # (format_type('string'::regtype, -1)),
  1424. # (format_type('time'::regtype, -1)),
  1425. # (format_type('timestamp'::regtype, -1)),
  1426. # (format_type('timestamptz'::regtype, -1)),
  1427. # (format_type('record'::regtype, -1)),
  1428. # (format_type('uuid'::regtype, -1)),
  1429. # (format_type('unknown'::regtype, -1)),
  1430. # (format_type('varbit'::regtype, -1)),
  1431. # (format_type('varchar'::regtype, -1)),
  1432. # (format_type('int[]'::regtype, -1)),
  1433. # (format_type('int2[]'::regtype, -1)),
  1434. # (format_type('string[]'::regtype, -1)),
  1435. # (format_type('varchar[]'::regtype, -1))
  1436. # ----
  1437. # anyelement
  1438. # bit
  1439. # boolean
  1440. # bytea
  1441. # character
  1442. # date
  1443. # numeric
  1444. # double precision
  1445. # real
  1446. # interval
  1447. # numeric
  1448. # oid
  1449. # oidvector
  1450. # inet
  1451. # bigint
  1452. # integer
  1453. # smallint
  1454. # int2vector
  1455. # interval
  1456. # jsonb
  1457. # name
  1458. # regclass
  1459. # regnamespace
  1460. # regproc
  1461. # regprocedure
  1462. # regtype
  1463. # text
  1464. # time without time zone
  1465. # timestamp without time zone
  1466. # timestamp with time zone
  1467. # record
  1468. # uuid
  1469. # unknown
  1470. # bit varying
  1471. # character varying
  1472. # bigint[]
  1473. # smallint[]
  1474. # text[]
  1475. # character varying[]
  1476. query T
  1477. VALUES (format_type('anyelement'::regtype, NULL)),
  1478. (format_type('bool'::regtype, NULL)),
  1479. (format_type('bytea'::regtype, NULL)),
  1480. (format_type('date'::regtype, NULL)),
  1481. (format_type('numeric'::regtype, NULL)),
  1482. (format_type('interval'::regtype, NULL)),
  1483. (format_type('timestamp'::regtype, NULL)),
  1484. (format_type('timestamptz'::regtype, NULL)),
  1485. (format_type('record'::regtype, NULL))
  1486. ----
  1487. anyelement
  1488. boolean
  1489. bytea
  1490. date
  1491. numeric
  1492. interval
  1493. timestamp without time zone
  1494. timestamp with time zone
  1495. record
  1496. query T
  1497. SELECT format_type(oid, -1) FROM pg_type WHERE typname='text' LIMIT 1
  1498. ----
  1499. text
  1500. query T
  1501. SELECT format_type(oid, -1) FROM pg_type WHERE typname='int8' LIMIT 1
  1502. ----
  1503. bigint
  1504. query T
  1505. SELECT format_type(oid, -1) FROM pg_type WHERE typname='float8' LIMIT 1
  1506. ----
  1507. double precision
  1508. query T
  1509. SELECT format_type(oid, -1) FROM pg_type WHERE typname='_int8' LIMIT 1
  1510. ----
  1511. bigint[]
  1512. query T
  1513. SELECT format_type(oid, -1) FROM pg_type WHERE typname='_text' LIMIT 1
  1514. ----
  1515. text[]
  1516. query T
  1517. SELECT pg_catalog.pg_get_expr('abc', 1);
  1518. ----
  1519. abc
  1520. query T
  1521. SELECT pg_catalog.pg_get_expr('abc', 1, true);
  1522. ----
  1523. abc
  1524. query T
  1525. SELECT pg_catalog.pg_get_expr('abc', 1, false);
  1526. ----
  1527. abc
  1528. query T
  1529. SELECT pg_catalog.pg_get_userbyid((SELECT oid FROM pg_roles WHERE rolname='root'))
  1530. ----
  1531. root
  1532. query T
  1533. SELECT pg_catalog.pg_get_userbyid(20)
  1534. ----
  1535. unknown (OID=20)
  1536. query T
  1537. SELECT pg_catalog.pg_get_indexdef(0)
  1538. ----
  1539. NULL
  1540. statement ok
  1541. CREATE TABLE test.pg_indexdef_test (a INT, UNIQUE INDEX pg_indexdef_idx (a ASC), INDEX other (a DESC))
  1542. query T
  1543. SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_idx'))
  1544. ----
  1545. CREATE UNIQUE INDEX pg_indexdef_idx ON test.public.pg_indexdef_test (a ASC)
  1546. query T
  1547. SELECT pg_catalog.pg_get_indexdef(0, 0, true)
  1548. ----
  1549. NULL
  1550. query T
  1551. SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_idx'), 0, true)
  1552. ----
  1553. CREATE UNIQUE INDEX pg_indexdef_idx ON test.public.pg_indexdef_test (a ASC)
  1554. statement ok
  1555. CREATE TABLE test.pg_indexdef_test_cols (a INT, b INT, UNIQUE INDEX pg_indexdef_cols_idx (a ASC, b DESC), INDEX other (a DESC))
  1556. query T
  1557. SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 0, true)
  1558. ----
  1559. CREATE UNIQUE INDEX pg_indexdef_cols_idx ON test.public.pg_indexdef_test_cols (a ASC, b DESC)
  1560. query T
  1561. SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 1, true)
  1562. ----
  1563. a
  1564. query T
  1565. SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 2, false)
  1566. ----
  1567. b
  1568. query T
  1569. SELECT pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 3, false)
  1570. ----
  1571. rowid
  1572. query I
  1573. SELECT length(pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), 4, false))
  1574. ----
  1575. 0
  1576. query I
  1577. SELECT length(pg_catalog.pg_get_indexdef((SELECT oid from pg_class WHERE relname='pg_indexdef_cols_idx'), -1, false))
  1578. ----
  1579. 0
  1580. query T
  1581. SELECT pg_catalog.pg_get_viewdef(0)
  1582. ----
  1583. NULL
  1584. statement ok
  1585. CREATE TABLE test.pg_viewdef_test (a int, b int, c int)
  1586. statement ok
  1587. CREATE VIEW test.pg_viewdef_view AS SELECT a, b FROM test.pg_viewdef_test
  1588. query T
  1589. SELECT pg_catalog.pg_get_viewdef('pg_viewdef_view'::regclass::oid)
  1590. ----
  1591. SELECT a, b FROM test.public.pg_viewdef_test
  1592. query T
  1593. SELECT pg_catalog.pg_get_viewdef(0, true)
  1594. ----
  1595. NULL
  1596. query T
  1597. SELECT pg_catalog.pg_get_viewdef(0, false)
  1598. ----
  1599. NULL
  1600. query T
  1601. SELECT pg_catalog.pg_get_viewdef('pg_viewdef_view'::regclass::oid, true)
  1602. ----
  1603. SELECT a, b FROM test.public.pg_viewdef_test
  1604. query T
  1605. SELECT pg_catalog.pg_get_viewdef('pg_viewdef_view'::regclass::oid, false)
  1606. ----
  1607. SELECT a, b FROM test.public.pg_viewdef_test
  1608. statement ok
  1609. CREATE TABLE test.pg_constraintdef_test (
  1610. a int,
  1611. b int unique,
  1612. c int check (c > a),
  1613. FOREIGN KEY(a) REFERENCES test.pg_indexdef_test(a) ON DELETE CASCADE
  1614. )
  1615. query T rowsort
  1616. SELECT pg_catalog.pg_get_constraintdef(oid)
  1617. FROM pg_catalog.pg_constraint
  1618. WHERE conrelid='pg_constraintdef_test'::regclass
  1619. ----
  1620. FOREIGN KEY (a) REFERENCES pg_indexdef_test (a) ON DELETE CASCADE
  1621. CHECK (c > a)
  1622. UNIQUE (b ASC)
  1623. # These functions always return NULL since we don't support comments on vtable columns and databases.
  1624. query TT
  1625. SELECT col_description('pg_class'::regclass::oid, 2),
  1626. shobj_description('pg_class'::regclass::oid, 'pg_class')
  1627. ----
  1628. NULL NULL
  1629. # vtable comments are supported
  1630. query TT
  1631. SELECT regexp_replace(obj_description('pg_class'::regclass::oid), e' .*', '') AS comment1,
  1632. regexp_replace(obj_description('pg_class'::regclass::oid, 'pg_class'), e' .*', '') AS comment2
  1633. ----
  1634. tables tables
  1635. # Regular table column comments are supported.
  1636. statement ok
  1637. CREATE TABLE t(x INT);
  1638. statement ok
  1639. COMMENT ON TABLE t IS 'waa'
  1640. statement ok
  1641. COMMENT ON COLUMN t.x IS 'woo'
  1642. query TTTT
  1643. SELECT obj_description('t'::regclass::oid),
  1644. obj_description('t'::regclass::oid, 'pg_class'),
  1645. obj_description('t'::regclass::oid, 'notexist'),
  1646. col_description('t'::regclass, 1)
  1647. ----
  1648. waa waa NULL woo
  1649. statement ok
  1650. COMMENT ON DATABASE test is 'foo'
  1651. query TTTT
  1652. SELECT shobj_description((select oid from pg_database where datname = 'materialize')::oid, 'pg_database'),
  1653. shobj_description((select oid from pg_database where datname = 'test')::oid, 'pg_database'),
  1654. shobj_description((select oid from pg_database where datname = 'notexist')::oid, 'pg_database'),
  1655. shobj_description((select oid from pg_database where datname = 'test')::oid, 'notexist')
  1656. ----
  1657. NULL foo NULL NULL
  1658. # Ensure that shobj_ and obj_description don't return the opposite type of
  1659. # comments.
  1660. query TT
  1661. SELECT shobj_description('t'::regclass::oid, 'pg_class'),
  1662. obj_description((select oid from pg_database where datname = 'test')::oid, 'pg_database')
  1663. ----
  1664. NULL NULL
  1665. # Check that base function names are also visible in namespace pg_catalog.
  1666. query I
  1667. SELECT pg_catalog.length('hello')
  1668. ----
  1669. 5
  1670. query OOO
  1671. SELECT oid(3), oid(0), oid(12023948723)
  1672. ----
  1673. 3 0 12023948723
  1674. query T
  1675. SELECT to_english(i) FROM (VALUES (1), (13), (617), (-2)) AS a(i)
  1676. ----
  1677. one
  1678. one-three
  1679. six-one-seven
  1680. minus-two
  1681. # Do some basic sanity checking of the variadic hash functions.
  1682. query BBBBBBBBB
  1683. SELECT
  1684. sha512('1') = sha512('1'),
  1685. sha512('1') = sha512('2'),
  1686. sha512('1', '2') = sha512('1', '2'),
  1687. sha512('1', '2') = sha512('2', '1'),
  1688. sha512('1', '2') = sha512('12'),
  1689. sha512('1', '2') = sha512('21'),
  1690. sha512('bar') = sha512(b'bar':::bytes),
  1691. sha512(b'bar'::bytes) = sha512(b'bar':::bytes),
  1692. sha512(b'bar'::bytes) = sha512('bar')
  1693. ----
  1694. true false true false true false true true true
  1695. # The hash functions should be stable, so verify that the following hashes
  1696. # don't change.
  1697. query T
  1698. SELECT i FROM (VALUES
  1699. (sha512(true::string)),
  1700. (sha512(false::string)),
  1701. (sha512(1::int::string)),
  1702. (sha512(1.1::float::string)),
  1703. (sha512('foo'::string)),
  1704. (sha512('3m'::interval::string)),
  1705. (sha512('2016-11-12'::date::string)),
  1706. (sha512('2015-08-24 23:45:45.53453'::timestamptz::string)),
  1707. (sha512(b'bar'::bytes))
  1708. ) AS a(i)
  1709. ----
  1710. 9120cd5faef07a08e971ff024a3fcbea1e3a6b44142a6d82ca28c6c42e4f852595bcf53d81d776f10541045abdb7c37950629415d0dc66c8d86c64a5606d32de
  1711. 719fa67eef49c4b2a2b83f0c62bddd88c106aaadb7e21ae057c8802b700e36f81fe3f144812d8b05d66dc663d908b25645e153262cf6d457aa34e684af9e328d
  1712. 4dff4ea340f0a823f15d3f4f01ab62eae0e5da579ccb851f8db9dfe84c58b2b37b89903a740e1ee172da793a6e79d560e5f7f9bd058a12a280433ed6fa46510a
  1713. be09b235155bae6cb96b94ce4645260937e856ac3907d710850256e6351f50b428f948a7af33937445604f41cf3a3121b2dd069a057708ed1f047e133e09151e
  1714. f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7
  1715. 95bce0fdbcf48ba9c944dae46238d89bbd6df696a0d0b7cc8fc16eeabd30c03d6d2506cfcce81de320b37bc677df1bd045ac9231b43ae11807773db3909d1220
  1716. b2d173023893f71caadf7cb2f9557355462570de2c9c971b9cfa5494936e28df8e13d0db4d550aab66d5e7a002f678ddb02def092c069ce473cf5fb293953986
  1717. 960b0fed9378be1e9adefd91e1be6ac9c1de7208008dfec438ff845135727bebea0f7458a5181079f61288176e0168cfea501b900c3e495b3ab9bbe4d372486d
  1718. d82c4eb5261cb9c8aa9855edd67d1bd10482f41529858d925094d173fa662aa91ff39bc5b188615273484021dfb16fd8284cf684ccf0fc795be3aa2fc1e6c181
  1719. # We only support one encoding, UTF8, which is hardcoded to id 6 just like in
  1720. # Postgres.
  1721. query TT
  1722. SELECT pg_catalog.pg_encoding_to_char(6), pg_catalog.pg_encoding_to_char(7)
  1723. ----
  1724. UTF8 NULL
  1725. # TODO(jordan): Restore this to original form by removing FROM
  1726. # clause once issue 32876 is fixed.
  1727. query TITI
  1728. SELECT pg_catalog.inet_client_addr(), pg_catalog.inet_client_port(), pg_catalog.inet_server_addr(), pg_catalog.inet_server_port()
  1729. FROM pg_class
  1730. WHERE relname = 'pg_constraint'
  1731. ----
  1732. ::/0 0 ::/0 0
  1733. query TTTT
  1734. SELECT quote_ident('foo'), quote_ident('select'), quote_ident('int8'), quote_ident('numeric')
  1735. ----
  1736. foo "select" int8 "numeric"
  1737. query TT
  1738. SELECT lpad('abc', 5, 'xy'), rpad('abc', 5, 'xy')
  1739. ----
  1740. xyabc abcxy
  1741. query TT
  1742. SELECT lpad('abc', 5, ''), rpad('abc', 5, '')
  1743. ----
  1744. abc abc
  1745. query error requested length too large
  1746. SELECT lpad('abc', 100000000000000)
  1747. query error requested length too large
  1748. SELECT rpad('abc', 100000000000000)
  1749. query TT
  1750. SELECT array_to_string(ARRAY['a', 'b,', NULL, 'c'], ','), array_to_string(ARRAY['a', 'b,', NULL, 'c'], ',', NULL)
  1751. ----
  1752. a,b,,c a,b,,c
  1753. query TT
  1754. SELECT array_to_string(ARRAY['a', 'b,', 'c'], NULL), array_to_string(ARRAY['a', 'b,', NULL, 'c'], 'foo', 'zerp')
  1755. ----
  1756. NULL afoob,foozerpfooc
  1757. query error could not determine polymorphic type because input has type unknown
  1758. SELECT array_to_string(NULL, ',')
  1759. query error could not determine polymorphic type because input has type unknown
  1760. SELECT array_to_string(NULL, 'foo', 'zerp')
  1761. subtest pg_is_in_recovery
  1762. query B colnames
  1763. SELECT pg_is_in_recovery()
  1764. ----
  1765. pg_is_in_recovery
  1766. false
  1767. subtest pg_is_xlog_replay_paused
  1768. query B colnames
  1769. SELECT pg_is_xlog_replay_paused()
  1770. ----
  1771. pg_is_xlog_replay_paused
  1772. false
  1773. query T
  1774. SELECT pg_catalog.pg_client_encoding()
  1775. ----
  1776. UTF8
  1777. subtest check_consistency
  1778. # Sanity-check crdb_internal.check_consistency.
  1779. statement error start key must be >= "\\x02"
  1780. SELECT crdb_internal.check_consistency(true, '\x01', '\xffff')
  1781. statement error end key must be < "\\xff\\xff"
  1782. SELECT crdb_internal.check_consistency(true, '\x02', '\xffff00')
  1783. statement error start key must be less than end key
  1784. SELECT crdb_internal.check_consistency(true, '\x02', '\x02')
  1785. statement error start key must be less than end key
  1786. SELECT crdb_internal.check_consistency(true, '\x03', '\x02')
  1787. query ITT
  1788. SELECT range_id, status, regexp_replace(detail, '[0-9]+', '', 'g') FROM crdb_internal.check_consistency(true, '\x02', '\xffff') WHERE range_id = 1
  1789. ----
  1790. 1 RANGE_CONSISTENT stats: {ContainsEstimates:false LastUpdateNanos: IntentAge: GCBytesAge: LiveBytes: LiveCount: KeyBytes: KeyCount: ValBytes: ValCount: IntentBytes: IntentCount: SysBytes: SysCount: XXX_NoUnkeyedLiteral:{} XXX_sizecache:}
  1791. # Without explicit keys, scans all ranges (we don't test this too precisely to
  1792. # avoid flaking the test when the range count changes, just want to know that
  1793. # we're touching multiple ranges).
  1794. query B
  1795. SELECT count(*) > 5 FROM crdb_internal.check_consistency(true, '', '')
  1796. ----
  1797. true
  1798. # Query that should touch only a single range.
  1799. query B
  1800. SELECT count(*) = 1 FROM crdb_internal.check_consistency(true, '\x03', '\x0300')
  1801. ----
  1802. true
  1803. # Ditto, but implicit start key \x02
  1804. query B
  1805. SELECT count(*) = 1 FROM crdb_internal.check_consistency(true, '', '\x0200')
  1806. ----
  1807. true
  1808. # Ditto, but implicit end key.
  1809. query B
  1810. SELECT count(*) = 1 FROM crdb_internal.check_consistency(true, '\xff', '')
  1811. ----
  1812. true