drop_view.slt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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/drop_view
  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. # not supported yet
  20. halt
  21. mode cockroach
  22. statement ok
  23. CREATE TABLE a (k STRING PRIMARY KEY, v STRING)
  24. statement ok
  25. INSERT INTO a VALUES ('a', '1'), ('b', '2'), ('c', '3')
  26. statement ok
  27. CREATE VIEW b AS SELECT k,v from a
  28. statement ok
  29. CREATE VIEW c AS SELECT k,v from b
  30. query TT
  31. SHOW TABLES FROM test
  32. ----
  33. a (empty)
  34. b (empty)
  35. c (empty)
  36. statement error cannot drop relation "a" because view "b" depends on it
  37. DROP TABLE a
  38. statement error pgcode 42809 "b" is not a table
  39. DROP TABLE b
  40. statement error cannot drop relation "b" because view "c" depends on it
  41. DROP VIEW b
  42. statement ok
  43. CREATE VIEW d AS SELECT k,v FROM a
  44. statement ok
  45. CREATE VIEW diamond AS SELECT count(*) FROM b AS b JOIN d AS d ON b.k = d.k
  46. statement error cannot drop relation "d" because view "diamond" depends on it
  47. DROP VIEW d
  48. statement ok
  49. GRANT ALL ON d TO testuser
  50. query TT
  51. SHOW TABLES FROM test
  52. ----
  53. a (empty)
  54. b (empty)
  55. c (empty)
  56. d (empty)
  57. diamond (empty)
  58. user testuser
  59. statement error user testuser does not have DROP privilege on relation diamond
  60. DROP VIEW diamond
  61. statement error cannot drop relation "d" because view "diamond" depends on it
  62. DROP VIEW d
  63. user root
  64. statement ok
  65. CREATE VIEW testuser1 AS SELECT k,v FROM a
  66. statement ok
  67. CREATE VIEW testuser2 AS SELECT k,v FROM testuser1
  68. statement ok
  69. CREATE VIEW testuser3 AS SELECT k,v FROM testuser2
  70. statement ok
  71. GRANT ALL ON testuser1 to testuser
  72. statement ok
  73. GRANT ALL ON testuser2 to testuser
  74. statement ok
  75. GRANT ALL ON testuser3 to testuser
  76. query TT
  77. SHOW TABLES FROM test
  78. ----
  79. a (empty)
  80. b (empty)
  81. c (empty)
  82. d (empty)
  83. diamond (empty)
  84. testuser1 (empty)
  85. testuser2 (empty)
  86. testuser3 (empty)
  87. user testuser
  88. statement ok
  89. DROP VIEW testuser3
  90. query TT
  91. SHOW TABLES FROM test
  92. ----
  93. d (empty)
  94. testuser1 (empty)
  95. testuser2 (empty)
  96. statement error cannot drop relation "testuser1" because view "testuser2" depends on it
  97. DROP VIEW testuser1
  98. statement error cannot drop relation "testuser1" because view "testuser2" depends on it
  99. DROP VIEW testuser1 RESTRICT
  100. statement ok
  101. DROP VIEW testuser1 CASCADE
  102. query TT
  103. SHOW TABLES FROM test
  104. ----
  105. d (empty)
  106. statement error pgcode 42P01 relation "testuser2" does not exist
  107. DROP VIEW testuser2
  108. user root
  109. statement ok
  110. GRANT ALL ON a to testuser
  111. statement ok
  112. GRANT ALL ON b to testuser
  113. statement ok
  114. GRANT ALL ON c to testuser
  115. statement ok
  116. GRANT ALL ON d to testuser
  117. user testuser
  118. statement error user testuser does not have DROP privilege on relation diamond
  119. DROP TABLE a CASCADE
  120. user root
  121. statement ok
  122. DROP TABLE a CASCADE
  123. query TT
  124. SHOW TABLES FROM test
  125. ----
  126. statement ok
  127. CREATE VIEW x AS VALUES (1, 2), (3, 4)
  128. statement ok
  129. CREATE VIEW y AS SELECT column1, column2 FROM x
  130. statement error cannot drop relation "x" because view "y" depends on it
  131. DROP VIEW x
  132. statement ok
  133. DROP VIEW x, y
  134. statement ok
  135. CREATE VIEW x AS VALUES (1, 2), (3, 4)
  136. statement ok
  137. CREATE VIEW y AS SELECT column1, column2 FROM x
  138. statement error cannot drop relation "x" because view "y" depends on it
  139. DROP VIEW x
  140. statement ok
  141. DROP VIEW y, x
  142. # Ensure that dropping a database works even when views get referred to more=
  143. # than once. See materialize#15953 for more details.
  144. statement ok
  145. CREATE DATABASE a
  146. statement ok
  147. SET DATABASE=a
  148. statement ok
  149. CREATE TABLE a (a int);
  150. statement ok
  151. CREATE TABLE b (b int);
  152. statement ok
  153. CREATE VIEW v AS SELECT a.a, b.b FROM a CROSS JOIN b
  154. statement ok
  155. CREATE VIEW u AS SELECT a FROM a UNION SELECT a FROM a
  156. statement ok
  157. DROP DATABASE a CASCADE