Synopsis

Use the DROP VIEW statement to drop a view.

Syntax

drop_view ::= DROP VIEW [ IF EXISTS ] qualified_name  
              [ CASCADE | RESTRICT ]

drop_view

DROPVIEWIFEXISTSqualified_nameCASCADERESTRICT

Semantics

Drop a view named qualified_name. If qualified_name doesn't exist in the specified database, an error will be raised unless the IF EXISTS clause is used.

RESTRICT / CASCADE

RESTRICT is the default, and it will not drop the view if any objects depend on it.

CASCADE will drop any objects that transitively depend on the view.

Examples

Basic example.

yugabyte=# CREATE TABLE t1(a int4);
yugabyte=# CREATE VIEW m1 AS SELECT * FROM t1;
yugabyte=# CREATE VIEW m2 AS SELECT * FROM m1;
yugabyte=# DROP VIEW m1; -- fails because m2 depends on m1
ERROR:  cannot drop view m1 because other objects depend on it
DETAIL:  view m2 depends on view m1
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
yugabyte=# DROP VIEW m1 CASCADE; -- succeeds

See also