I am creating multiple views in my code and each time the code is run, I would like to drop all the materialized views generated thus far. Is there any command that will list all the materialized views for Postgres or drop all of them?
相关问题
- NOT DISTINCT query in mySQL
- Flush single app django 1.9
- Django distinct is not working
- PostgreSQL: left outer join syntax
- Connecting Python to a Heroku PostgreSQL DB?
相关文章
- postgresql 关于使用between and 中是字符串的问题
- postgresql 月份差计算问题
- Using boolean expression in order by clause
- Table valued Parameter Equivalent in Postgresql
- in redshift postgresql can I skip columns with the
- Oracle equivalent of PostgreSQL INSERT…RETURNING *
- Connection pooling vs persist connection mysqli
- PostgreSQL field data type for IPv4 addresses
Show all:
Names are automatically double-quoted and schema-qualified where needed according to your current
search_path
in the cast fromregclass
totext
.In the system catalog
pg_class
materialized views are tagged withrelkind = 'm'
.The manual:
To drop all, you can generate the needed SQL script with this query:
Returns:
One
DROP MATERIALIZED VIEW
statement can take care of multiple materialized views. You may need to addCASCADE
at the end if you have nested views.Inspect the resulting DDL script to be sure before executing it. Are you sure you want to drop all MVs from all schemas in the db? And do you have the required privileges to do so? (Currently there are no materialized views in a fresh standard installation.)
This an answer is based on the answer from Erwin Brandstetter. The version below adds a specific schema name to only retrieve the materialized views from a defined schema. The Cascasde also drops dependencies on the materialized views from that schema. Be careful with that.
This would be easier if you want to get a full list with the DROP statement in front of each view: