-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrop.sql
38 lines (34 loc) · 1.06 KB
/
drop.sql
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
DELIMITER $$
USE `mview`$$
DROP PROCEDURE IF EXISTS `drop`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `drop`(
p_schema_name VARCHAR(64),
p_mview_name VARCHAR(60)
)
BEGIN
DECLARE l_view_name VARCHAR(64);
DECLARE l_changelog_enabled INTEGER;
SELECT view_name, changelog_enabled
INTO l_view_name, l_changelog_enabled
FROM mview.metadata
WHERE mview_name = p_mview_name
AND mview_schema = p_schema_name;
IF (l_changelog_enabled = 1) THEN
BEGIN
SELECT 'Cannot drop materialized view, changelog enabled!';
END;
ELSE
BEGIN
SET @l_view_drop_script := CONCAT('DROP VIEW IF EXISTS ', p_schema_name, '.', l_view_name);
SET @l_table_drop_script := CONCAT('DROP TABLE IF EXISTS ', p_schema_name, '.', p_mview_name);
PREPARE drop_view FROM @l_view_drop_script;
EXECUTE drop_view;
PREPARE drop_table FROM @l_table_drop_script;
EXECUTE drop_table;
DELETE FROM mview.metadata
WHERE mview_name = p_mview_name
AND mview_schema = p_schema_name;
END;
END IF;
END$$
DELIMITER ;