rename_view.slt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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/rename_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 error pgcode 42P01 relation "foo" does not exist
  23. ALTER VIEW foo RENAME TO bar
  24. statement ok
  25. ALTER VIEW IF EXISTS foo RENAME TO bar
  26. statement ok
  27. CREATE TABLE kv (
  28. k INT PRIMARY KEY,
  29. v INT
  30. )
  31. statement ok
  32. INSERT INTO kv VALUES (1, 2), (3, 4)
  33. statement ok
  34. CREATE VIEW v as SELECT k,v FROM kv
  35. query II rowsort
  36. SELECT * FROM v
  37. ----
  38. 1 2
  39. 3 4
  40. query T
  41. SHOW TABLES
  42. ----
  43. kv
  44. v
  45. statement error pgcode 42809 "kv" is not a view
  46. ALTER VIEW kv RENAME TO new_kv
  47. # We allow ALTER TABLE for renaming views.
  48. statement ok
  49. ALTER TABLE v RENAME TO new_v
  50. statement error pgcode 42P01 relation "v" does not exist
  51. SELECT * FROM v
  52. query II rowsort
  53. SELECT * FROM new_v
  54. ----
  55. 1 2
  56. 3 4
  57. query T
  58. SHOW TABLES
  59. ----
  60. kv
  61. new_v
  62. # check the name in the descriptor, which is used by SHOW GRANTS, is also changed
  63. query TTTTT
  64. SHOW GRANTS ON new_v
  65. ----
  66. test public new_v admin ALL
  67. test public new_v root ALL
  68. statement error invalid table name: ""
  69. ALTER VIEW "" RENAME TO foo
  70. statement error invalid table name: ""
  71. ALTER VIEW new_v RENAME TO ""
  72. statement ok
  73. ALTER VIEW new_v RENAME TO new_v
  74. statement ok
  75. CREATE TABLE t (
  76. c1 INT PRIMARY KEY,
  77. c2 INT
  78. )
  79. statement ok
  80. INSERT INTO t VALUES (4, 16), (5, 25)
  81. statement ok
  82. CREATE VIEW v as SELECT c1,c2 from t
  83. statement error pgcode 42P07 relation "new_v" already exists
  84. ALTER VIEW v RENAME TO new_v
  85. user testuser
  86. statement error user testuser does not have DROP privilege on relation v
  87. ALTER VIEW test.v RENAME TO v2
  88. user root
  89. statement ok
  90. GRANT DROP ON test.v TO testuser
  91. statement ok
  92. create database test2
  93. user testuser
  94. statement error user testuser does not have CREATE privilege on database test
  95. ALTER VIEW test.v RENAME TO v2
  96. user root
  97. statement ok
  98. GRANT CREATE ON DATABASE test TO testuser
  99. statement ok
  100. ALTER VIEW test.v RENAME TO v2
  101. query T
  102. SHOW TABLES FROM test
  103. ----
  104. kv
  105. new_v
  106. t
  107. v2
  108. user testuser
  109. statement error user testuser does not have CREATE privilege on database test2
  110. ALTER VIEW test.v2 RENAME TO test2.v
  111. user root
  112. statement ok
  113. GRANT CREATE ON DATABASE test2 TO testuser
  114. statement ok
  115. GRANT DROP ON test.new_v TO testuser
  116. user testuser
  117. statement ok
  118. ALTER VIEW test.new_v RENAME TO test2.v
  119. statement ok
  120. ALTER VIEW test.v2 RENAME TO test2.v2
  121. query T
  122. SHOW TABLES FROM test
  123. ----
  124. query T
  125. SHOW TABLES FROM test2
  126. ----
  127. v
  128. v2
  129. user root
  130. query II rowsort
  131. SELECT * FROM test2.v
  132. ----
  133. 1 2
  134. 3 4
  135. query II rowsort
  136. SELECT * FROM test2.v2
  137. ----
  138. 4 16
  139. 5 25
  140. statement ok
  141. CREATE VIEW v3 AS SELECT count(*) FROM test2.v AS v JOIN test2.v2 AS v2 ON v.k > v2.c1
  142. statement error cannot rename relation "test2.public.v" because view "test.public.v3" depends on it
  143. ALTER VIEW test2.v RENAME TO test2.v3
  144. statement error cannot rename relation "test2.public.v2" because view "test.public.v3" depends on it
  145. ALTER VIEW test2.v2 RENAME TO v4
  146. statement ok
  147. ALTER VIEW v3 RENAME TO v4
  148. statement error cannot rename relation "test2.public.v2" because view "test.public.v4" depends on it
  149. ALTER VIEW test2.v2 RENAME TO v5