如何删除Postgres中的所有视图

时间:2018-03-12 01:38:43

标签: sql postgresql

我在路径中创建了很多表和视图(称为parlgov) enter image description here

我想要删除此Schema(或称为路径)中的所有表和视图,或者最好只删除所有视图并保留表格。

我尝试通过drop view视图的名称手动删除效率不高。

我想知道是否有更好的方法可以做到。

3 个答案:

答案 0 :(得分:1)

您可以使用简单的匿名PL / pgSQL块执行此操作:

sort

答案 1 :(得分:-1)

select 'DROP VIEW '||viewname||';' FROM  pg_views where schemaname='parlgov';

答案 2 :(得分:-1)

SELECT 'DROP VIEW ' || table_name || ';' 
FROM information_schema.views 
WHERE table_schema NOT IN ('pg_catalog', 'information_schema') 
AND table_name !~ '^pg_';