forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrename_view.slt
200 lines (149 loc) · 3.79 KB
/
rename_view.slt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
#
# This file is derived from the logic test suite in CockroachDB. The
# original file was retrieved on June 10, 2019 from:
#
# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/rename_view
#
# The original source code is subject to the terms of the Apache
# 2.0 license, a copy of which can be found in the LICENSE file at the
# root of this repository.
# not supported yet
halt
mode cockroach
statement error pgcode 42P01 relation "foo" does not exist
ALTER VIEW foo RENAME TO bar
statement ok
ALTER VIEW IF EXISTS foo RENAME TO bar
statement ok
CREATE TABLE kv (
k INT PRIMARY KEY,
v INT
)
statement ok
INSERT INTO kv VALUES (1, 2), (3, 4)
statement ok
CREATE VIEW v as SELECT k,v FROM kv
query II rowsort
SELECT * FROM v
----
1 2
3 4
query T
SHOW TABLES
----
kv
v
statement error pgcode 42809 "kv" is not a view
ALTER VIEW kv RENAME TO new_kv
# We allow ALTER TABLE for renaming views.
statement ok
ALTER TABLE v RENAME TO new_v
statement error pgcode 42P01 relation "v" does not exist
SELECT * FROM v
query II rowsort
SELECT * FROM new_v
----
1 2
3 4
query T
SHOW TABLES
----
kv
new_v
# check the name in the descriptor, which is used by SHOW GRANTS, is also changed
query TTTTT
SHOW GRANTS ON new_v
----
test public new_v admin ALL
test public new_v root ALL
statement error invalid table name: ""
ALTER VIEW "" RENAME TO foo
statement error invalid table name: ""
ALTER VIEW new_v RENAME TO ""
statement ok
ALTER VIEW new_v RENAME TO new_v
statement ok
CREATE TABLE t (
c1 INT PRIMARY KEY,
c2 INT
)
statement ok
INSERT INTO t VALUES (4, 16), (5, 25)
statement ok
CREATE VIEW v as SELECT c1,c2 from t
statement error pgcode 42P07 relation "new_v" already exists
ALTER VIEW v RENAME TO new_v
user testuser
statement error user testuser does not have DROP privilege on relation v
ALTER VIEW test.v RENAME TO v2
user root
statement ok
GRANT DROP ON test.v TO testuser
statement ok
create database test2
user testuser
statement error user testuser does not have CREATE privilege on database test
ALTER VIEW test.v RENAME TO v2
user root
statement ok
GRANT CREATE ON DATABASE test TO testuser
statement ok
ALTER VIEW test.v RENAME TO v2
query T
SHOW TABLES FROM test
----
kv
new_v
t
v2
user testuser
statement error user testuser does not have CREATE privilege on database test2
ALTER VIEW test.v2 RENAME TO test2.v
user root
statement ok
GRANT CREATE ON DATABASE test2 TO testuser
statement ok
GRANT DROP ON test.new_v TO testuser
user testuser
statement ok
ALTER VIEW test.new_v RENAME TO test2.v
statement ok
ALTER VIEW test.v2 RENAME TO test2.v2
query T
SHOW TABLES FROM test
----
query T
SHOW TABLES FROM test2
----
v
v2
user root
query II rowsort
SELECT * FROM test2.v
----
1 2
3 4
query II rowsort
SELECT * FROM test2.v2
----
4 16
5 25
statement ok
CREATE VIEW v3 AS SELECT count(*) FROM test2.v AS v JOIN test2.v2 AS v2 ON v.k > v2.c1
statement error cannot rename relation "test2.public.v" because view "test.public.v3" depends on it
ALTER VIEW test2.v RENAME TO test2.v3
statement error cannot rename relation "test2.public.v2" because view "test.public.v3" depends on it
ALTER VIEW test2.v2 RENAME TO v4
statement ok
ALTER VIEW v3 RENAME TO v4
statement error cannot rename relation "test2.public.v2" because view "test.public.v4" depends on it
ALTER VIEW test2.v2 RENAME TO v5