My database is PostgreSQL (9.3.5).
We have more than 500 materialized views and want to drop some of them.
For that we are fetching from those materialized views from pg_class
:
FOR MVNAME IN (SELECT relname
FROM pg_class
WHERE relkind='m')
LOOP
EXECUTE 'DROP MATERIALIZED VIEW '||MVNAME||'';
END LOOP;
At executing time it's giving us an error:
ERROR: "dimension" is not a materialized view SQL state: 42809 Hint: Use DROP FOREIGN TABLE to remove a foreign table. Context: SQL statement "DROP MATERIALIZED VIEW dimension" PL/pgSQL function test_drop_dims() line 14 at EXECUTE statement
We can drop one materialized view using:
DROP MATERIALIZED VIEW MVNAME;
But we can't drop multiple materialized views using EXECUTE
statement.