-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#23117] YSQL: Enable ALTER VIEW in parser
Summary: With this diff, the following ALTER VIEW commands are allowed: - ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name SET DEFAULT expression - ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name DROP DEFAULT - ALTER VIEW [ IF EXISTS ] name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER } - ALTER VIEW [ IF EXISTS ] name RENAME TO new_name - ALTER VIEW [ IF EXISTS ] name SET SCHEMA new_schema These commands do not require any additional YB changes, as they are metadata-only changes. Therefore, we only need to enable them in the parser. Note: ALTER VIEW ... SET/RESET commands are not enabled as the generalized ALTER TABLE ... SET/RESET is not supported. Jira: DB-12050 Test Plan: yb_view, yb_pg_create_view Reviewers: myang, jason Reviewed By: myang Subscribers: jason, yql Differential Revision: https://phorge.dev.yugabyte.com/D35937
- Loading branch information
1 parent
4768023
commit 3d4bc2a
Showing
6 changed files
with
312 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
-- | ||
-- YB tests for views | ||
-- | ||
CREATE TABLE test (a int, b int, c int DEFAULT 5); | ||
INSERT INTO test VALUES (generate_series(1, 5), generate_series(1, 5)); | ||
CREATE VIEW test_view AS SELECT * FROM test ORDER BY a, b; | ||
SELECT * FROM test_view; | ||
a | b | c | ||
---+---+--- | ||
1 | 1 | 5 | ||
2 | 2 | 5 | ||
3 | 3 | 5 | ||
4 | 4 | 5 | ||
5 | 5 | 5 | ||
(5 rows) | ||
|
||
-- Tests for ALTER VIEW. | ||
-- test ALTER VIEW ... ALTER COLUMN ... SET/DROP DEFAULT | ||
ALTER VIEW test_view ALTER COLUMN c SET DEFAULT 10; | ||
INSERT INTO test (a, b) VALUES (6, 6); | ||
INSERT INTO test_view (a, b) VALUES (7, 7); | ||
SELECT * FROM test_view; | ||
a | b | c | ||
---+---+---- | ||
1 | 1 | 5 | ||
2 | 2 | 5 | ||
3 | 3 | 5 | ||
4 | 4 | 5 | ||
5 | 5 | 5 | ||
6 | 6 | 5 | ||
7 | 7 | 10 | ||
(7 rows) | ||
|
||
ALTER VIEW test_view ALTER COLUMN c DROP DEFAULT; | ||
INSERT INTO test (a, b) VALUES (8, 8); | ||
SELECT * FROM test_view; | ||
a | b | c | ||
---+---+---- | ||
1 | 1 | 5 | ||
2 | 2 | 5 | ||
3 | 3 | 5 | ||
4 | 4 | 5 | ||
5 | 5 | 5 | ||
6 | 6 | 5 | ||
7 | 7 | 10 | ||
8 | 8 | 5 | ||
(8 rows) | ||
|
||
ALTER VIEW IF EXISTS non_existent_view ALTER COLUMN c SET DEFAULT 10; | ||
NOTICE: relation "non_existent_view" does not exist, skipping | ||
ALTER VIEW IF EXISTS non_existent_view ALTER COLUMN c DROP DEFAULT; | ||
NOTICE: relation "non_existent_view" does not exist, skipping | ||
-- test ALTER VIEW ... OWNER TO | ||
CREATE ROLE test_role; | ||
ALTER VIEW test_view OWNER TO test_role; | ||
SELECT * FROM test_view; | ||
ERROR: permission denied for table test | ||
ALTER VIEW test_view OWNER TO CURRENT_USER; | ||
SELECT * FROM test_view; | ||
a | b | c | ||
---+---+---- | ||
1 | 1 | 5 | ||
2 | 2 | 5 | ||
3 | 3 | 5 | ||
4 | 4 | 5 | ||
5 | 5 | 5 | ||
6 | 6 | 5 | ||
7 | 7 | 10 | ||
8 | 8 | 5 | ||
(8 rows) | ||
|
||
ALTER VIEW IF EXISTS non_existent_view OWNER TO test_role; | ||
NOTICE: relation "non_existent_view" does not exist, skipping | ||
-- test ALTER VIEW ... RENAME | ||
ALTER VIEW test_view RENAME TO test_view_renamed; | ||
SELECT * FROM test_view_renamed; | ||
a | b | c | ||
---+---+---- | ||
1 | 1 | 5 | ||
2 | 2 | 5 | ||
3 | 3 | 5 | ||
4 | 4 | 5 | ||
5 | 5 | 5 | ||
6 | 6 | 5 | ||
7 | 7 | 10 | ||
8 | 8 | 5 | ||
(8 rows) | ||
|
||
ALTER VIEW IF EXISTS non_existent_view RENAME TO non_existent_view_renamed; | ||
NOTICE: relation "non_existent_view" does not exist, skipping | ||
ALTER VIEW test_view_renamed RENAME TO test_view; | ||
-- test ALTER VIEW ... SET SCHEMA | ||
CREATE SCHEMA test_schema; | ||
ALTER VIEW test_view SET SCHEMA test_schema; | ||
SELECT * FROM test_schema.test_view; | ||
a | b | c | ||
---+---+---- | ||
1 | 1 | 5 | ||
2 | 2 | 5 | ||
3 | 3 | 5 | ||
4 | 4 | 5 | ||
5 | 5 | 5 | ||
6 | 6 | 5 | ||
7 | 7 | 10 | ||
8 | 8 | 5 | ||
(8 rows) | ||
|
||
ALTER VIEW test_schema.test_view SET SCHEMA public; | ||
SELECT * FROM test_view; | ||
a | b | c | ||
---+---+---- | ||
1 | 1 | 5 | ||
2 | 2 | 5 | ||
3 | 3 | 5 | ||
4 | 4 | 5 | ||
5 | 5 | 5 | ||
6 | 6 | 5 | ||
7 | 7 | 10 | ||
8 | 8 | 5 | ||
(8 rows) | ||
|
||
ALTER VIEW IF EXISTS non_existent_view SET SCHEMA test_schema; | ||
NOTICE: relation "non_existent_view" does not exist, skipping |
Oops, something went wrong.