regclass.slt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. # regclass
  11. statement OK
  12. create schema s
  13. statement ok
  14. CREATE TABLE t(i int);
  15. statement ok
  16. CREATE TABLE s.t(i int);
  17. statement ok
  18. CREATE DATABASE d;
  19. statement ok
  20. CREATE TABLE d.public.t();
  21. statement ok
  22. CREATE MATERIALIZED VIEW m AS SELECT * FROM t;
  23. statement ok
  24. CREATE MATERIALIZED VIEW s.m AS SELECT * FROM s.t;
  25. query T
  26. SELECT 't'::regclass::oid::int
  27. ----
  28. 20190
  29. query T
  30. SELECT 's.t'::regclass::oid::int
  31. ----
  32. 20191
  33. query T
  34. SELECT 't'::regclass = 's.t'::regclass
  35. ----
  36. false
  37. query T
  38. SELECT 'public.t'::regclass::text;
  39. ----
  40. t
  41. query T
  42. SELECT 't'::regclass::text;
  43. ----
  44. t
  45. query T
  46. SELECT 's.t'::regclass::text;
  47. ----
  48. s.t
  49. statement ok
  50. SET search_path = s, public
  51. query T
  52. SELECT 's.t'::regclass::text;
  53. ----
  54. t
  55. query T
  56. SELECT 't'::regclass::oid::int
  57. ----
  58. 20191
  59. query T
  60. SELECT 'public.t'::regclass::text;
  61. ----
  62. public.t
  63. statement ok
  64. SET search_path = public
  65. query T
  66. SELECT 's.t'::regclass::text;
  67. ----
  68. s.t
  69. query T
  70. SELECT 'public.t'::regclass::text;
  71. ----
  72. t
  73. query T
  74. SELECT 'd.public.t'::regclass::text;
  75. ----
  76. d.public.t
  77. query T
  78. SELECT 'm'::regclass::oid::int
  79. ----
  80. 20195
  81. query T
  82. SELECT 's.m'::regclass::oid::int
  83. ----
  84. 20196
  85. query T
  86. SELECT 'm'::regclass = 's.m'::regclass
  87. ----
  88. false
  89. query error db error: ERROR: relation "abs" does not exist
  90. SELECT 'abs'::regclass
  91. query error db error: ERROR: relation "dne" does not exist
  92. SELECT 'dne'::regclass
  93. statement ok
  94. CREATE TABLE "2"()
  95. query T
  96. SELECT 2::regclass
  97. ----
  98. 2
  99. query T
  100. SELECT '2'::regclass
  101. ----
  102. 2
  103. # PG supports this
  104. query error db error: ERROR: string is not a valid identifier: "2"
  105. SELECT '2'::text::regclass
  106. query B
  107. SELECT '"2"'::regclass != 2
  108. ----
  109. true
  110. query T
  111. SELECT '"2"'::regclass::text
  112. ----
  113. 2
  114. statement ok
  115. CREATE TABLE "2x"()
  116. query T
  117. SELECT '"2x"'::regclass::text
  118. ----
  119. 2x
  120. query error db error: ERROR: relation "dne" does not exist
  121. SELECT 'dne'::regclass;
  122. # Check that we handle functions and classes w/ same name
  123. statement ok
  124. CREATE TABLE array_length();
  125. query T
  126. SELECT 'array_length'::regclass::text;
  127. ----
  128. array_length
  129. query T
  130. SELECT 'array_length'::regproc::text;
  131. ----
  132. array_length
  133. # Check that we handle types and classes w/ same name
  134. statement ok
  135. CREATE TABLE int4();
  136. query T
  137. SELECT 'int4'::regclass::text;
  138. ----
  139. int4
  140. query T
  141. SELECT 'int4'::regtype::text;
  142. ----
  143. int4
  144. query T
  145. SELECT 'int4'::regclass::oid = 'int4'::regtype::oid;
  146. ----
  147. false
  148. query T
  149. SELECT 1::regclass
  150. ----
  151. 1
  152. query T
  153. SELECT 1::int4::regclass
  154. ----
  155. 1
  156. query T
  157. SELECT 1::oid::regclass
  158. ----
  159. 1
  160. query T
  161. SELECT 1::oid::regclass::oid
  162. ----
  163. 1
  164. query T
  165. SELECT '1'::regclass
  166. ----
  167. 1
  168. query T
  169. SELECT '1'::pg_catalog.regclass
  170. ----
  171. 1
  172. query T
  173. SELECT '1'::regclass::text
  174. ----
  175. 1
  176. query T
  177. SELECT 'mz_tables'::regclass::text
  178. ----
  179. mz_tables
  180. query B
  181. SELECT 'mz_tables'::regclass = (SELECT oid FROM mz_objects WHERE name = 'mz_tables')
  182. ----
  183. true
  184. query B
  185. SELECT 'mz_tables'::regclass::oid = (SELECT oid FROM mz_objects WHERE name = 'mz_tables')
  186. ----
  187. true
  188. # This shouldn't be an error but seems to be impacted by
  189. # some evaluation order issue akin to database-issues#4972
  190. # # Regression for 9194
  191. # query B
  192. # select 'mz_tables'::regclass::oid::text::regclass = (SELECT oid FROM mz_objects WHERE name = 'mz_tables')
  193. # ----
  194. # true
  195. query error relation "nonexistent" does not exist
  196. SELECT 'nonexistent'::regclass
  197. statement ok
  198. CREATE TABLE text_to_regclass (a text);
  199. statement ok
  200. INSERT INTO text_to_regclass VALUES (NULL), ('mz_tables');
  201. # Overflows its stack in debug mode
  202. # query T
  203. # SELECT a::regclass::text FROM text_to_regclass ORDER BY a
  204. # ----
  205. # mz_tables
  206. # NULL
  207. # Make sure that there are no classes with duplicate OIDs
  208. query I
  209. select oid from (select count(*) as cnt, oid from pg_catalog.pg_class group by oid) where cnt>1
  210. ----
  211. query T
  212. SELECT NULL::regclass::text
  213. ----
  214. NULL
  215. # ensure that all existing types can be cast to their respective names
  216. statement OK
  217. select oid, oid::regclass::text from (select oid from pg_catalog.pg_class)
  218. # ensure that catalog items can be resolved if the active database is invalid
  219. statement OK
  220. SET database TO ''
  221. query T
  222. SELECT 'mz_tables'::regclass = (SELECT oid FROM mz_objects WHERE name = 'mz_tables')
  223. ----
  224. true
  225. query T
  226. SELECT 'mz_internal.mz_recent_activity_log'::regclass = (SELECT oid FROM mz_objects WHERE name = 'mz_recent_activity_log')
  227. ----
  228. true
  229. query T
  230. SELECT 'materialize.public.t'::regclass::oid::int
  231. ----
  232. 20190
  233. query error db error: ERROR: relation "t" does not exist
  234. SELECT 't'::regclass::oid::int