types.slt 16 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. # 🔬 Type resolution (non-array)
  10. # 🔬🔬 bool
  11. query T
  12. SELECT 'true'::bool
  13. ----
  14. true
  15. query T
  16. SELECT 'true'::pg_catalog.bool
  17. ----
  18. true
  19. # 🔬🔬🔬 bool alias
  20. query T
  21. SELECT 'true'::boolean
  22. ----
  23. true
  24. query T
  25. SELECT pg_typeof('true'::boolean)
  26. ----
  27. boolean
  28. query error type "pg_catalog.boolean" does not exist
  29. SELECT 'true'::pg_catalog.boolean
  30. # 🔬🔬 bytea
  31. query T
  32. SELECT 'a'::bytea
  33. ----
  34. a
  35. query T
  36. SELECT 'a'::pg_catalog.bytea
  37. ----
  38. a
  39. # 🔬🔬🔬 bytea alias
  40. query T
  41. SELECT 'a'::bytes
  42. ----
  43. a
  44. query error type "pg_catalog.bytes" does not exist
  45. SELECT ''::pg_catalog.bytes
  46. # 🔬🔬 date
  47. query T
  48. SELECT '2007-02-01'::date
  49. ----
  50. 2007-02-01
  51. query T
  52. SELECT '2007-02-01'::pg_catalog.date
  53. ----
  54. 2007-02-01
  55. # 🔬🔬 float4
  56. query T
  57. SELECT '1.2'::float4
  58. ----
  59. 1.200
  60. query T
  61. SELECT '1.2'::pg_catalog.float4
  62. ----
  63. 1.200
  64. # 🔬🔬🔬 float4 aliases
  65. query T
  66. SELECT '1.2'::float(1)
  67. ----
  68. 1.200
  69. query error type "pg_catalog.float" does not exist
  70. SELECT '1.2'::pg_catalog.float(1)
  71. query T
  72. SELECT pg_typeof('1.2'::float(1))
  73. ----
  74. real
  75. query T
  76. SELECT '1.2'::real
  77. ----
  78. 1.200
  79. query error type "pg_catalog.real" does not exist
  80. SELECT '1.2'::pg_catalog.real
  81. query T
  82. SELECT pg_typeof('1.2'::real)
  83. ----
  84. real
  85. # 🔬🔬 float8
  86. query T
  87. SELECT '1.2'::float8
  88. ----
  89. 1.200
  90. query T
  91. SELECT '1.2'::pg_catalog.float8
  92. ----
  93. 1.200
  94. # 🔬🔬🔬 float8 aliases
  95. query T
  96. SELECT '1.2'::float(53)
  97. ----
  98. 1.200
  99. query error type "pg_catalog.float" does not exist
  100. SELECT '1.2'::pg_catalog.float(53)
  101. query T
  102. SELECT pg_typeof('1.2'::float(53))
  103. ----
  104. double precision
  105. query T
  106. SELECT '1.2'::double
  107. ----
  108. 1.200
  109. query error type "pg_catalog.double" does not exist
  110. SELECT '1.2'::pg_catalog.double
  111. query T
  112. SELECT pg_typeof('1.2'::double)
  113. ----
  114. double precision
  115. # 🔬🔬 int2
  116. query T
  117. SELECT '1'::int2
  118. ----
  119. 1
  120. query T
  121. SELECT '1'::pg_catalog.int2
  122. ----
  123. 1
  124. # 🔬🔬🔬 int2 aliases
  125. query T
  126. SELECT '1'::smallint
  127. ----
  128. 1
  129. query error type "pg_catalog.smallint" does not exist
  130. SELECT '1'::pg_catalog.smallint
  131. query T
  132. SELECT pg_typeof('1'::smallint)
  133. ----
  134. smallint
  135. # 🔬🔬 int4
  136. query T
  137. SELECT '1'::int4
  138. ----
  139. 1
  140. query T
  141. SELECT '1'::pg_catalog.int4
  142. ----
  143. 1
  144. # 🔬🔬🔬 int4 aliases
  145. query T
  146. SELECT '1'::int
  147. ----
  148. 1
  149. query error type "pg_catalog.int" does not exist
  150. SELECT '1'::pg_catalog.int
  151. query T
  152. SELECT pg_typeof('1'::int)
  153. ----
  154. integer
  155. query T
  156. SELECT '1'::integer
  157. ----
  158. 1
  159. query error type "pg_catalog.integer" does not exist
  160. SELECT '1'::pg_catalog.integer
  161. query T
  162. SELECT pg_typeof('1'::integer)
  163. ----
  164. integer
  165. # 🔬🔬 int8
  166. query T
  167. SELECT '1'::int8
  168. ----
  169. 1
  170. query T
  171. SELECT '1'::pg_catalog.int8
  172. ----
  173. 1
  174. # 🔬🔬🔬 int8 aliases
  175. query T
  176. SELECT '1'::bigint
  177. ----
  178. 1
  179. query error type "pg_catalog.bigint" does not exist
  180. SELECT '1'::pg_catalog.bigint
  181. query T
  182. SELECT pg_typeof('1'::bigint)
  183. ----
  184. bigint
  185. # 🔬🔬 interval
  186. query T
  187. SELECT '1-2 3 4:5:6.7'::interval
  188. ----
  189. 1 year 2 months 3 days 04:05:06.7
  190. query T
  191. SELECT '1-2 3 4:5:6.7'::pg_catalog.interval
  192. ----
  193. 1 year 2 months 3 days 04:05:06.7
  194. # 🔬🔬🔬 interval prefix
  195. query T
  196. SELECT interval '1-2 3 4:5:6.7'
  197. ----
  198. 1 year 2 months 3 days 04:05:06.7
  199. query T
  200. SELECT pg_catalog.interval '1-2 3 4:5:6.7'
  201. ----
  202. 1 year 2 months 3 days 04:05:06.7
  203. # Special interval literal syntax doesn't apply to qualified interval
  204. query error Expected end of statement, found DAY
  205. SELECT pg_catalog.interval '1-2 3 4:5:6.7' DAY
  206. # 🔬🔬 jsonb
  207. query T
  208. SELECT '{"1":2,"3":4}'::jsonb
  209. ----
  210. {"1":2,"3":4}
  211. query T
  212. SELECT '{"1":2,"3":4}'::pg_catalog.jsonb
  213. ----
  214. {"1":2,"3":4}
  215. # 🔬🔬🔬 jsonb aliases
  216. query T
  217. SELECT '{"1":2,"3":4}'::json
  218. ----
  219. {"1":2,"3":4}
  220. query error type "pg_catalog.json" does not exist
  221. SELECT '{"1":2,"3":4}'::pg_catalog.json
  222. # 🔬🔬 numeric
  223. query T
  224. SELECT '1'::numeric(38,0)
  225. ----
  226. 1
  227. query T
  228. SELECT '1'::pg_catalog.numeric(38,0)
  229. ----
  230. 1
  231. # 🔬🔬🔬 numeric aliases –– note that decimal alises all resolve to numeric when
  232. # qualified, unlike all other aliases
  233. query T
  234. SELECT '1'::decimal(38,0)
  235. ----
  236. 1
  237. query error type "pg_catalog.decimal" does not exist
  238. SELECT '1'::pg_catalog.decimal(38,0)
  239. query T
  240. SELECT '1'::dec(38,0)
  241. ----
  242. 1
  243. query error type "pg_catalog.dec" does not exist
  244. SELECT '1'::pg_catalog.dec(38,0)
  245. # 🔬🔬 oid
  246. query T
  247. SELECT '1'::oid
  248. ----
  249. 1
  250. query T
  251. SELECT '1'::pg_catalog.oid
  252. ----
  253. 1
  254. query I
  255. SELECT 1::oid
  256. ----
  257. 1
  258. query I
  259. SELECT 1::int4::oid
  260. ----
  261. 1
  262. query I
  263. SELECT 1::int4::oid::int4
  264. ----
  265. 1
  266. # 🔬🔬 record
  267. query error cannot reference pseudo type pg_catalog.record
  268. SELECT ROW(1, 2)::record;
  269. query error cannot reference pseudo type pg_catalog.record
  270. SELECT ROW(1, 2)::pg_catalog.record;
  271. # 🔬🔬 text
  272. query T
  273. SELECT 'dog'::text
  274. ----
  275. dog
  276. query T
  277. SELECT 'dog'::pg_catalog.text
  278. ----
  279. dog
  280. # 🔬🔬🔬 char
  281. query T
  282. SELECT 'dog'::char(3)
  283. ----
  284. dog
  285. query T
  286. SELECT 'dog'::pg_catalog.bpchar(3)
  287. ----
  288. dog
  289. query error pg_catalog.char does not support type modifiers
  290. SELECT 'dog'::pg_catalog.char(3)
  291. # 🔬🔬🔬 varchar
  292. query T
  293. SELECT 'dog'::varchar(10)
  294. ----
  295. dog
  296. query T
  297. SELECT 'dog'::pg_catalog.varchar(10)
  298. ----
  299. dog
  300. # 🔬🔬 time
  301. query T
  302. SELECT '01:23:45'::time
  303. ----
  304. 01:23:45
  305. query T
  306. SELECT '01:23:45'::pg_catalog.time
  307. ----
  308. 01:23:45
  309. # 🔬🔬 timestamp
  310. query T
  311. SELECT '2007-02-01 15:04:05'::timestamp
  312. ----
  313. 2007-02-01 15:04:05
  314. query T
  315. SELECT '2007-02-01 15:04:05'::pg_catalog.timestamp
  316. ----
  317. 2007-02-01 15:04:05
  318. # 🔬🔬 timestamptz
  319. query T
  320. SELECT '2007-02-01 15:04:05'::timestamptz
  321. ----
  322. 2007-02-01 15:04:05+00
  323. query T
  324. SELECT '2007-02-01 15:04:05'::pg_catalog.timestamptz
  325. ----
  326. 2007-02-01 15:04:05+00
  327. # 🔬🔬 uuid
  328. query T
  329. SELECT '63616665-6630-3064-6465-616462656568'::uuid
  330. ----
  331. 63616665-6630-3064-6465-616462656568
  332. query T
  333. SELECT '63616665-6630-3064-6465-616462656568'::pg_catalog.uuid
  334. ----
  335. 63616665-6630-3064-6465-616462656568
  336. # 🔬 Type resolution of list element
  337. query T
  338. SELECT '{true}'::bool list::text
  339. ----
  340. {t}
  341. query T
  342. SELECT '{true}'::pg_catalog.bool list::text
  343. ----
  344. {t}
  345. # 🔬 float resolves to proper types
  346. query T
  347. SELECT pg_typeof(1::float)
  348. ----
  349. double precision
  350. query T
  351. SELECT pg_typeof(1::float(1))
  352. ----
  353. real
  354. query T
  355. SELECT pg_typeof(1::float(53))
  356. ----
  357. double precision
  358. query T
  359. SELECT pg_typeof(1::float(53))
  360. ----
  361. double precision
  362. # 🔬 misc. resolution tests
  363. # pg_catalog and materialize.pg_catalog resolution are equivalent
  364. query T
  365. SELECT '1'::materialize.pg_catalog.int4
  366. ----
  367. 1
  368. # tables are not types yet
  369. query error type "pg_catalog.pg_enum" does not exist
  370. SELECT '1'::pg_catalog.pg_enum
  371. # relations can have the same name as built-in types
  372. statement ok
  373. CREATE VIEW int4 AS VALUES (1)
  374. query I
  375. SELECT * FROM int4
  376. ----
  377. 1
  378. # but within the same schema, types cannot have the same name as a relation
  379. statement error view "materialize.public.int4" already exists
  380. CREATE TYPE int4 AS (a int)
  381. # creating relations with the same name as an existing type is not allowed
  382. # (see database-issues#7142)...
  383. statement ok
  384. CREATE TYPE rectype AS (a int)
  385. statement error type "materialize.public.rectype" already exists
  386. CREATE VIEW rectype AS VALUES (1)
  387. statement error type "materialize.public.rectype" already exists
  388. CREATE MATERIALIZED VIEW rectype AS VALUES (1)
  389. statement error type "materialize.public.rectype" already exists
  390. CREATE TABLE rectype (a int)
  391. statement error type "materialize.public.rectype" already exists
  392. CREATE SOURCE rectype FROM LOAD GENERATOR COUNTER
  393. statement error type "materialize.public.rectype" already exists
  394. CREATE INDEX rectype ON int4 (column1)
  395. # ...not even via rename...
  396. statement ok
  397. CREATE VIEW rectype_sneaky_v AS VALUES (1)
  398. statement error catalog item 'rectype' already exists
  399. ALTER VIEW rectype_sneaky_v RENAME TO rectype
  400. statement ok
  401. CREATE MATERIALIZED VIEW rectype_sneaky_mv AS VALUES (1)
  402. statement error catalog item 'rectype' already exists
  403. ALTER MATERIALIZED VIEW rectype_sneaky_mv RENAME TO rectype
  404. statement ok
  405. CREATE TABLE rectype_sneaky_t (a int)
  406. statement error catalog item 'rectype' already exists
  407. ALTER TABLE rectype_sneaky_t RENAME TO rectype
  408. statement ok
  409. CREATE SOURCE rectype_sneaky_s FROM LOAD GENERATOR COUNTER
  410. statement error catalog item 'rectype' already exists
  411. ALTER SOURCE rectype_sneaky_s RENAME TO rectype
  412. statement ok
  413. CREATE INDEX rectype_sneaky_i ON int4 (column1)
  414. statement error catalog item 'rectype' already exists
  415. ALTER INDEX rectype_sneaky_i RENAME TO rectype
  416. # creating secrets with the same name as a type is ok though...
  417. statement ok
  418. CREATE SECRET rectype AS 'ignored'
  419. statement ok
  420. DROP SECRET rectype
  421. statement ok
  422. CREATE SECRET rectype_sneaky AS 'ignored'
  423. statement ok
  424. ALTER SECRET rectype_sneaky RENAME TO rectype
  425. statement ok
  426. DROP SECRET rectype
  427. statement ok
  428. CREATE CONNECTION rectype TO SSH TUNNEL (HOST 'localhost', USER 'ignored')
  429. statement ok
  430. DROP CONNECTION rectype
  431. statement ok
  432. CREATE CONNECTION rectype_sneaky TO SSH TUNNEL (HOST 'localhost', USER 'ignored')
  433. statement ok
  434. ALTER CONNECTION rectype_sneaky RENAME TO rectype
  435. statement ok
  436. DROP CONNECTION rectype
  437. # 🔬 format_type
  438. query T
  439. SELECT format_type(NULL, NULL)
  440. ----
  441. NULL
  442. query T
  443. SELECT format_type(NULL, 1)
  444. ----
  445. NULL
  446. query T
  447. SELECT format_type(16, NULL)
  448. ----
  449. boolean
  450. query T
  451. SELECT format_type(17, NULL)
  452. ----
  453. bytea
  454. query T
  455. SELECT format_type(20, NULL)
  456. ----
  457. bigint
  458. query T
  459. SELECT format_type(23, NULL)
  460. ----
  461. integer
  462. query T
  463. SELECT format_type(25, NULL)
  464. ----
  465. text
  466. query T
  467. SELECT format_type(18, NULL)
  468. ----
  469. character
  470. query T
  471. SELECT format_type(1043, NULL)
  472. ----
  473. character varying
  474. query T
  475. SELECT format_type(26, NULL)
  476. ----
  477. oid
  478. query T
  479. SELECT format_type(700, NULL)
  480. ----
  481. real
  482. query T
  483. SELECT format_type(701, NULL)
  484. ----
  485. double precision
  486. query T
  487. SELECT format_type(1082, NULL)
  488. ----
  489. date
  490. query T
  491. SELECT format_type(1083, NULL)
  492. ----
  493. time
  494. query T
  495. SELECT format_type(1114, NULL)
  496. ----
  497. timestamp without time zone
  498. query T
  499. SELECT format_type(1114, -2)
  500. ----
  501. timestamp without time zone
  502. query T
  503. SELECT format_type(1114, -1)
  504. ----
  505. timestamp without time zone
  506. query T
  507. SELECT format_type(1114, 0)
  508. ----
  509. timestamp(0) without time zone
  510. query T
  511. SELECT format_type(1114, 1)
  512. ----
  513. timestamp(1) without time zone
  514. query T
  515. SELECT format_type(1114, 2)
  516. ----
  517. timestamp(2) without time zone
  518. query T
  519. SELECT format_type(1114, 3)
  520. ----
  521. timestamp(3) without time zone
  522. query T
  523. SELECT format_type(1114, 4)
  524. ----
  525. timestamp(4) without time zone
  526. query T
  527. SELECT format_type(1114, 5)
  528. ----
  529. timestamp(5) without time zone
  530. query T
  531. SELECT format_type(1114, 6)
  532. ----
  533. timestamp(6) without time zone
  534. query T
  535. SELECT format_type(1114, 7)
  536. ----
  537. timestamp(7) without time zone
  538. query T
  539. SELECT format_type(1184, NULL)
  540. ----
  541. timestamp with time zone
  542. query T
  543. SELECT format_type(1184, -2)
  544. ----
  545. timestamp with time zone
  546. query T
  547. SELECT format_type(1184, -1)
  548. ----
  549. timestamp with time zone
  550. query T
  551. SELECT format_type(1184, 0)
  552. ----
  553. timestamp(0) with time zone
  554. query T
  555. SELECT format_type(1184, 1)
  556. ----
  557. timestamp(1) with time zone
  558. query T
  559. SELECT format_type(1184, 2)
  560. ----
  561. timestamp(2) with time zone
  562. query T
  563. SELECT format_type(1184, 3)
  564. ----
  565. timestamp(3) with time zone
  566. query T
  567. SELECT format_type(1184, 4)
  568. ----
  569. timestamp(4) with time zone
  570. query T
  571. SELECT format_type(1184, 5)
  572. ----
  573. timestamp(5) with time zone
  574. query T
  575. SELECT format_type(1184, 6)
  576. ----
  577. timestamp(6) with time zone
  578. query T
  579. SELECT format_type(1184, 7)
  580. ----
  581. timestamp(7) with time zone
  582. query T
  583. SELECT format_type(1186, NULL)
  584. ----
  585. interval
  586. query T
  587. SELECT format_type(1700, NULL)
  588. ----
  589. numeric
  590. query T
  591. SELECT format_type(2950, NULL)
  592. ----
  593. uuid
  594. query T
  595. SELECT format_type(3802, NULL)
  596. ----
  597. jsonb
  598. query T
  599. SELECT format_type(1000, NULL)
  600. ----
  601. boolean[]
  602. query T
  603. SELECT format_type(1001, NULL)
  604. ----
  605. bytea[]
  606. query T
  607. SELECT format_type(1005, NULL)
  608. ----
  609. smallint[]
  610. query T
  611. SELECT format_type(1016, NULL)
  612. ----
  613. bigint[]
  614. query T
  615. SELECT format_type(1007, NULL)
  616. ----
  617. integer[]
  618. query T
  619. SELECT format_type(1009, NULL)
  620. ----
  621. text[]
  622. query T
  623. SELECT format_type(1028, NULL)
  624. ----
  625. oid[]
  626. query T
  627. SELECT format_type(1021, NULL)
  628. ----
  629. real[]
  630. query T
  631. SELECT format_type(1022, NULL)
  632. ----
  633. double precision[]
  634. query T
  635. SELECT format_type(1182, NULL)
  636. ----
  637. date[]
  638. query T
  639. SELECT format_type(1183, NULL)
  640. ----
  641. time[]
  642. query T
  643. SELECT format_type(1115, NULL)
  644. ----
  645. timestamp without time zone[]
  646. query T
  647. SELECT format_type(1185, NULL)
  648. ----
  649. timestamp with time zone[]
  650. query T
  651. SELECT format_type(1187, NULL)
  652. ----
  653. interval[]
  654. query T
  655. SELECT format_type(1231, NULL)
  656. ----
  657. numeric[]
  658. query T
  659. SELECT format_type(2951, NULL)
  660. ----
  661. uuid[]
  662. query T
  663. SELECT format_type(3807, NULL)
  664. ----
  665. jsonb[]
  666. query T
  667. SELECT format_type(2210, NULL)
  668. ----
  669. regclass[]
  670. query T
  671. SELECT format_type(1008, NULL)
  672. ----
  673. regproc[]
  674. query T
  675. SELECT format_type(2211, NULL)
  676. ----
  677. regtype[]
  678. # 🔬🔬 non-type OID
  679. query T
  680. SELECT format_type(6, NULL);
  681. ----
  682. ???
  683. query T
  684. SELECT format_type(600, 100);
  685. ----
  686. ???
  687. query T
  688. SELECT format_type(6000, -100);
  689. ----
  690. ???
  691. # 🔬🔬 non-NULL typemod
  692. query T
  693. SELECT format_type(1700, 0);
  694. ----
  695. numeric
  696. query T
  697. SELECT format_type(1700, 3);
  698. ----
  699. numeric
  700. query T
  701. SELECT format_type(1700, 4);
  702. ----
  703. numeric(0,0)
  704. query T
  705. SELECT format_type(1700, 65540);
  706. ----
  707. numeric(1,0)
  708. query T
  709. SELECT format_type(1700, 65541);
  710. ----
  711. numeric(1,1)
  712. query T
  713. SELECT format_type(1700, 2490372);
  714. ----
  715. numeric(38,0)
  716. query T
  717. SELECT format_type(1700, 2490371);
  718. ----
  719. numeric(37,-1)
  720. query T
  721. SELECT format_type(1700, 2490373);
  722. ----
  723. numeric(38,1)
  724. query T
  725. SELECT format_type(1700, -2490373);
  726. ----
  727. numeric
  728. query T
  729. SELECT format_type(26, 1);
  730. ----
  731. oid(1)
  732. query T
  733. SELECT format_type(26, -1);
  734. ----
  735. oid
  736. ## coalesce nullability
  737. statement ok
  738. CREATE TABLE t1(key int, val int, n int NOT NULL);
  739. # coalesce's output type should be non-nullable when any of its input types are non-nullable
  740. query T multiline
  741. EXPLAIN OPTIMIZED PLAN WITH(types, humanized expressions) AS VERBOSE TEXT FOR
  742. SELECT coalesce(key, 0)
  743. FROM t1;
  744. ----
  745. Explained Query:
  746. Project (#3) // { types: "(integer)" }
  747. Map (coalesce(#0{key}, 0)) // { types: "(integer?, integer?, integer, integer)" }
  748. ReadStorage materialize.public.t1 // { types: "(integer?, integer?, integer)" }
  749. Source materialize.public.t1
  750. Target cluster: quickstart
  751. EOF
  752. query T multiline
  753. EXPLAIN OPTIMIZED PLAN WITH(types, humanized expressions) AS VERBOSE TEXT FOR
  754. SELECT coalesce(key, n)
  755. FROM t1;
  756. ----
  757. Explained Query:
  758. Project (#3) // { types: "(integer)" }
  759. Map (coalesce(#0{key}, #2{n})) // { types: "(integer?, integer?, integer, integer)" }
  760. ReadStorage materialize.public.t1 // { types: "(integer?, integer?, integer)" }
  761. Source materialize.public.t1
  762. Target cluster: quickstart
  763. EOF
  764. query T multiline
  765. EXPLAIN OPTIMIZED PLAN WITH(types, humanized expressions) AS VERBOSE TEXT FOR
  766. SELECT coalesce(key, 0), sum(val)
  767. FROM t1
  768. GROUP BY key;
  769. ----
  770. Explained Query:
  771. Project (#2, #1{sum_val}) // { types: "(integer, bigint?)" }
  772. Map (coalesce(#0{key}, 0)) // { types: "(integer?, bigint?, integer)" }
  773. Reduce group_by=[#0{key}] aggregates=[sum(#1{val})] // { types: "(integer?, bigint?)" }
  774. Project (#0{key}, #1{val}) // { types: "(integer?, integer?)" }
  775. ReadStorage materialize.public.t1 // { types: "(integer?, integer?, integer)" }
  776. Source materialize.public.t1
  777. Target cluster: quickstart
  778. EOF
  779. # coalesce's output type should be nullable when all of its input types are nullable
  780. query T multiline
  781. EXPLAIN OPTIMIZED PLAN WITH(types, humanized expressions) AS VERBOSE TEXT FOR
  782. SELECT coalesce(key, val)
  783. FROM t1;
  784. ----
  785. Explained Query:
  786. Project (#3) // { types: "(integer?)" }
  787. Map (coalesce(#0{key}, #1{val})) // { types: "(integer?, integer?, integer, integer?)" }
  788. ReadStorage materialize.public.t1 // { types: "(integer?, integer?, integer)" }
  789. Source materialize.public.t1
  790. Target cluster: quickstart
  791. EOF
  792. query T multiline
  793. EXPLAIN OPTIMIZED PLAN WITH(types, humanized expressions) AS VERBOSE TEXT FOR
  794. SELECT coalesce(key, val + 5)
  795. FROM t1;
  796. ----
  797. Explained Query:
  798. Project (#3) // { types: "(integer?)" }
  799. Map (coalesce(#0{key}, (#1{val} + 5))) // { types: "(integer?, integer?, integer, integer?)" }
  800. ReadStorage materialize.public.t1 // { types: "(integer?, integer?, integer)" }
  801. Source materialize.public.t1
  802. Target cluster: quickstart
  803. EOF