regtype.slt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. reset-server
  10. # regtype
  11. query T
  12. SELECT 1::regtype
  13. ----
  14. 1
  15. query T
  16. SELECT 1::int4::regtype
  17. ----
  18. 1
  19. query T
  20. SELECT 1::oid::regtype
  21. ----
  22. 1
  23. query T
  24. SELECT 1::oid::regtype::oid
  25. ----
  26. 1
  27. query T
  28. SELECT '1'::regtype
  29. ----
  30. 1
  31. query T
  32. SELECT '1'::pg_catalog.regtype
  33. ----
  34. 1
  35. query T
  36. SELECT '1'::regtype::text
  37. ----
  38. 1
  39. query T
  40. SELECT 'date'::regtype::text
  41. ----
  42. date
  43. query T
  44. SELECT 1082::regtype::text
  45. ----
  46. date
  47. query T
  48. SELECT 'date'::regtype
  49. ----
  50. 1082
  51. query T
  52. SELECT 'date'::regtype::oid
  53. ----
  54. 1082
  55. query error type "dne" does not exist
  56. SELECT 'dne'::regtype
  57. query B
  58. SELECT 1082 = 'date'::regtype
  59. ----
  60. true
  61. statement ok
  62. CREATE TABLE text_to_regtype (a text);
  63. statement ok
  64. INSERT INTO text_to_regtype VALUES (NULL), ('date');
  65. query I
  66. SELECT a::regtype FROM text_to_regtype ORDER BY a
  67. ----
  68. 1082
  69. NULL
  70. # Regression for materialize issue 9194
  71. # This shouldn't be an error but seems to be impacted by
  72. # some evaluation order issue akin to database-issues#4972
  73. # TODO: this has an optimization bug.
  74. query error
  75. select 'date'::regtype::oid::text::regtype
  76. query T
  77. SELECT 'date'::regtype::oid::text;
  78. ----
  79. 1082
  80. query I
  81. SELECT '1082'::text::regtype;
  82. ----
  83. 1082
  84. # These overflow their stack in debug mode.
  85. # query T
  86. # SELECT 'date'::regtype::text::regtype
  87. # ----
  88. # 1082
  89. #
  90. # query T
  91. # SELECT 'date'::regtype::text::regtype::text
  92. # ----
  93. # date
  94. query T
  95. SELECT NULL::regtype::text
  96. ----
  97. NULL
  98. # ensure that all existing types can be cast to their respective names
  99. statement OK
  100. select oid, oid::regtype::text from (select oid from mz_catalog.mz_types)
  101. statement OK
  102. create schema s
  103. statement ok
  104. CREATE TYPE t AS LIST (ELEMENT TYPE = int4);
  105. statement ok
  106. CREATE TYPE s.t AS LIST (ELEMENT TYPE = int4);
  107. statement ok
  108. CREATE DATABASE d;
  109. statement ok
  110. CREATE TYPE d.public.t AS LIST (ELEMENT TYPE = int4);
  111. query T
  112. SELECT 't'::regtype::oid::int
  113. ----
  114. 20191
  115. query T
  116. SELECT 's.t'::regtype::oid::int
  117. ----
  118. 20192
  119. query T
  120. SELECT 't'::regtype = 's.t'::regtype
  121. ----
  122. false
  123. query T
  124. SELECT 'public.t'::regtype::text;
  125. ----
  126. t
  127. query T
  128. SELECT 't'::regtype::text;
  129. ----
  130. t
  131. query T
  132. SELECT 's.t'::regtype::text;
  133. ----
  134. s.t
  135. statement ok
  136. SET search_path = s, public
  137. query T
  138. SELECT 's.t'::regtype::text;
  139. ----
  140. t
  141. statement ok
  142. SET search_path = public
  143. query T
  144. SELECT 's.t'::regtype::text;
  145. ----
  146. s.t
  147. query T
  148. SELECT 'd.public.t'::regtype::text;
  149. ----
  150. d.public.t
  151. # Check that we handle functions and types w/ same name
  152. query T
  153. SELECT '1178'::regproc::text;
  154. ----
  155. pg_catalog.date
  156. query T
  157. SELECT '1082'::regtype::text;
  158. ----
  159. date
  160. query error db error: ERROR: more than one function named "date"
  161. SELECT 'date'::regproc::text;
  162. query T
  163. SELECT 'date'::regtype::text;
  164. ----
  165. date
  166. statement ok
  167. CREATE TYPE array_length AS LIST (ELEMENT TYPE = int4);
  168. query T
  169. SELECT 'array_length'::regproc::text;
  170. ----
  171. array_length
  172. query T
  173. SELECT 'array_length'::regtype::text;
  174. ----
  175. array_length