pgoidtype.slt 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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/pgoidtype
  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. query OO
  25. SELECT 3::OID, '3'::OID
  26. ----
  27. 3 3
  28. query O
  29. SELECT 3::OID::INT::OID
  30. ----
  31. 3
  32. # The rest of this file is not yet supported.
  33. halt
  34. query OOOOOO
  35. SELECT 1::OID, 1::REGCLASS, 1::REGNAMESPACE, 1::REGPROC, 1::REGPROCEDURE, 1::REGTYPE
  36. ----
  37. 1 1 1 1 1 1
  38. query OOOOO
  39. SELECT 1::OID::REGCLASS, 1::OID::REGNAMESPACE, 1::OID::REGPROC, 1::OID::REGPROCEDURE, 1::OID::REGTYPE
  40. ----
  41. 1 1 1 1 1
  42. query TTT
  43. SELECT pg_typeof(1::OID), pg_typeof(1::REGCLASS), pg_typeof(1::REGNAMESPACE)
  44. ----
  45. oid regclass regnamespace
  46. query TTT
  47. SELECT pg_typeof(1::REGPROC), pg_typeof(1::REGPROCEDURE), pg_typeof(1::REGTYPE)
  48. ----
  49. regproc regprocedure regtype
  50. query TTT
  51. SELECT pg_typeof('1'::OID), pg_typeof('pg_constraint'::REGCLASS), pg_typeof('public'::REGNAMESPACE)
  52. ----
  53. oid regclass regnamespace
  54. query TTT
  55. SELECT pg_typeof('upper'::REGPROC), pg_typeof('upper'::REGPROCEDURE), pg_typeof('bool'::REGTYPE)
  56. ----
  57. regproc regprocedure regtype
  58. query OO
  59. SELECT 'pg_constraint'::REGCLASS, 'pg_catalog.pg_constraint'::REGCLASS
  60. ----
  61. pg_constraint pg_constraint
  62. query error pgcode 42P01 relation "foo.pg_constraint" does not exist
  63. SELECT 'foo.pg_constraint'::REGCLASS
  64. query OO
  65. SELECT '"pg_constraint"'::REGCLASS, ' "pg_constraint" '::REGCLASS
  66. ----
  67. pg_constraint pg_constraint
  68. query OO
  69. SELECT 'pg_constraint '::REGCLASS, ' pg_constraint '::REGCLASS
  70. ----
  71. pg_constraint pg_constraint
  72. query OO
  73. SELECT 'pg_constraint '::REGCLASS, '"pg_constraint"'::REGCLASS::OID
  74. ----
  75. pg_constraint 4294967232
  76. query O
  77. SELECT 4061301040::REGCLASS
  78. ----
  79. 4061301040
  80. query OOIOT
  81. SELECT oid, oid::regclass, oid::regclass::int, oid::regclass::int::regclass, oid::regclass::text
  82. FROM pg_class
  83. WHERE relname = 'pg_constraint'
  84. ----
  85. 4294967232 pg_constraint 4294967232 pg_constraint pg_constraint
  86. query OOOO
  87. SELECT 'upper'::REGPROC, 'upper'::REGPROCEDURE, 'pg_catalog.upper'::REGPROCEDURE, 'upper'::REGPROC::OID
  88. ----
  89. upper upper upper 3615042040
  90. query error invalid function name
  91. SELECT 'invalid.more.pg_catalog.upper'::REGPROCEDURE
  92. query OOO
  93. SELECT 'upper(int)'::REGPROC, 'upper(int)'::REGPROCEDURE, 'upper(int)'::REGPROC::OID
  94. ----
  95. upper upper 3615042040
  96. query error unknown function: blah\(\)
  97. SELECT 'blah(ignored, ignored)'::REGPROC, 'blah(ignored, ignored)'::REGPROCEDURE
  98. query error unknown function: blah\(\)
  99. SELECT ' blah ( ignored , ignored ) '::REGPROC
  100. query error unknown function: blah\(\)
  101. SELECT 'blah ()'::REGPROC
  102. query error unknown function: blah\(\)
  103. SELECT 'blah( )'::REGPROC
  104. query error unknown function: blah\(, \)\(\)
  105. SELECT 'blah(, )'::REGPROC
  106. query error more than one function named 'sqrt'
  107. SELECT 'sqrt'::REGPROC
  108. query OOOO
  109. SELECT 'array_in'::REGPROC, 'array_in(a,b,c)'::REGPROC, 'pg_catalog.array_in'::REGPROC, 'pg_catalog.array_in( a ,b, c )'::REGPROC
  110. ----
  111. array_in array_in array_in array_in
  112. query OOOO
  113. SELECT 'array_in'::REGPROCEDURE, 'array_in(a,b,c)'::REGPROCEDURE, 'pg_catalog.array_in'::REGPROCEDURE, 'pg_catalog.array_in( a ,b, c )'::REGPROCEDURE
  114. ----
  115. array_in array_in array_in array_in
  116. query OO
  117. SELECT 'public'::REGNAMESPACE, 'public'::REGNAMESPACE::OID
  118. ----
  119. public 3426283741
  120. query OO
  121. SELECT 'bool'::REGTYPE, 'bool'::REGTYPE::OID
  122. ----
  123. boolean 16
  124. query OO
  125. SELECT 'numeric(10,3)'::REGTYPE, 'numeric( 10, 3 )'::REGTYPE
  126. ----
  127. numeric numeric
  128. query error type 'foo.' does not exist
  129. SELECT 'foo.'::REGTYPE
  130. query error pgcode 42P01 relation "blah" does not exist
  131. SELECT 'blah'::REGCLASS
  132. query error unknown function: blah\(\)
  133. SELECT 'blah'::REGPROC
  134. query error unknown function: blah\(\)
  135. SELECT 'blah'::REGPROCEDURE
  136. query error namespace 'blah' does not exist
  137. SELECT 'blah'::REGNAMESPACE
  138. query error type 'blah' does not exist
  139. SELECT 'blah'::REGTYPE
  140. ## Test other cast syntaxes
  141. query O
  142. SELECT CAST ('pg_constraint' AS REGCLASS)
  143. ----
  144. pg_constraint
  145. # This forces the b_expr form of the cast syntax.
  146. query OO
  147. SELECT ('pg_constraint')::REGCLASS, ('pg_constraint')::REGCLASS::OID
  148. ----
  149. pg_constraint 4294967232
  150. ## Test visibility of pg_* via oid casts.
  151. statement ok
  152. CREATE TABLE a (id INT PRIMARY KEY)
  153. query T
  154. SELECT relname from pg_class where oid='a'::regclass
  155. ----
  156. a
  157. ## Regression for materialize#16767 - ensure regclass casts use normalized table names
  158. statement ok
  159. CREATE TABLE hasCase (id INT PRIMARY KEY)
  160. query T
  161. SELECT relname from pg_class where oid='hasCase'::regclass
  162. ----
  163. hascase
  164. statement ok
  165. CREATE TABLE "quotedCase" (id INT PRIMARY KEY)
  166. query error pgcode 42P01 relation "quotedcase" does not exist
  167. SELECT relname from pg_class where oid='quotedCase'::regclass
  168. query T
  169. SELECT relname from pg_class where oid='"quotedCase"'::regclass
  170. ----
  171. quotedCase
  172. # a non-root user with sufficient permissions can get the OID of a table from
  173. # the current database
  174. statement ok
  175. GRANT ALL ON DATABASE test TO testuser
  176. statement ok
  177. GRANT SELECT ON test.* TO testuser
  178. user testuser
  179. query T
  180. SELECT relname from pg_class where oid='a'::regclass
  181. ----
  182. a
  183. user root
  184. statement ok
  185. CREATE DATABASE otherdb
  186. ## a non-root user can't get the OID of a table from a different database
  187. user testuser
  188. statement ok
  189. SET DATABASE = otherdb
  190. query error pgcode 42P01 relation "a" does not exist
  191. SELECT 'a'::regclass
  192. user root
  193. statement ok
  194. SET DATABASE = otherdb
  195. statement ok
  196. CREATE TABLE a (id INT PRIMARY KEY, foo STRING)
  197. ## There is now a table named 'a' in both the database 'otherdb' and the
  198. ## database 'test'. The following query shows that the root user can still
  199. ## determine the OID of the table 'a' by using a regclass cast, despite the
  200. ## fact that the root user has visibility into both of the tables. The 'a' that
  201. ## gets selected should be the 'a' that exists in the current database.
  202. ## See https://github.com/cockroachdb/cockroach/issues/13695
  203. query OI
  204. SELECT relname, relnatts FROM pg_class WHERE oid='a'::regclass
  205. ----
  206. a 2
  207. statement ok
  208. SET DATABASE = test
  209. query OI
  210. SELECT relname, relnatts FROM pg_class WHERE oid='a'::regclass
  211. ----
  212. a 1
  213. statement ok
  214. CREATE DATABASE thirddb
  215. statement ok
  216. SET DATABASE = thirddb
  217. # Ensure that if the table is not in the current database, but it
  218. # still exists in another database, the query does fail (regclass
  219. # does not automatically search in other dbs, even for the root user).
  220. query error pgcode 42P01 relation "a" does not exist
  221. SELECT relname, relnatts FROM pg_class WHERE oid='a'::regclass
  222. statement ok
  223. CREATE TABLE o (a OID PRIMARY KEY)
  224. statement ok
  225. INSERT INTO o VALUES (1), (4)
  226. query O
  227. SELECT * FROM o WHERE a < 3
  228. ----
  229. 1
  230. query O rowsort
  231. SELECT * FROM o WHERE a <= 4
  232. ----
  233. 1
  234. 4
  235. # Regression test for materialize#23652.
  236. query B
  237. SELECT NOT (prorettype::regtype::text = 'foo') AND proretset FROM pg_proc WHERE proretset=false LIMIT 1
  238. ----
  239. false
  240. query TTTTT
  241. SELECT crdb_internal.create_regtype(10, 'foo'), crdb_internal.create_regclass(10, 'foo'), crdb_internal.create_regproc(10, 'foo'), crdb_internal.create_regprocedure(10, 'foo'), crdb_internal.create_regnamespace(10, 'foo')
  242. ----
  243. foo foo foo foo foo
  244. query OOOOO
  245. SELECT crdb_internal.create_regtype(10, 'foo')::oid, crdb_internal.create_regclass(10, 'foo')::oid, crdb_internal.create_regproc(10, 'foo')::oid, crdb_internal.create_regprocedure(10, 'foo')::oid, crdb_internal.create_regnamespace(10, 'foo')::oid
  246. ----
  247. 10 10 10 10 10
  248. # Regression test for cockroach#32422: ensure that VALUES nodes properly retain special
  249. # OID properties.
  250. query OO
  251. VALUES ('pg_constraint'::REGCLASS, 'pg_catalog.pg_constraint'::REGCLASS)
  252. ----
  253. pg_constraint pg_constraint