DROP MATERIALIZED VIEW
Synopsis
Use the DROP MATERIALIZED VIEW
statement to drop a materialized view.
Syntax
drop_matview ::= DROP MATERIALIZED VIEW [ IF EXISTS ] matview_name
[ CASCADE | RESTRICT ]
Semantics
Drop a materialized view named matview_name. If matview_name
already exists in the specified database, an error will be raised unless the IF NOT EXISTS
clause is used.
RESTRICT / CASCADE
RESTRICT
is the default and it will not drop the materialized view if any objects depend on it.
CASCADE
will drop any objects that transitively depend on the materialized view.
Examples
Basic example.
yugabyte=# CREATE TABLE t1(a int4);
yugabyte=# CREATE MATERIALIZED VIEW m1 AS SELECT * FROM t1;
yugabyte=# CREATE MATERIALIZED VIEW m2 AS SELECT * FROM m1;
yugabyte=# DROP MATERIALIZED VIEW m1; -- fails because m2 depends on m1
ERROR: cannot drop materialized view m1 because other objects depend on it
DETAIL: materialized view m2 depends on materialized view m1
yugabyte=# DROP MATERIALIZED VIEW m1 CASCADE; -- succeeds