I have a database with an old broken version of PostGIS installed in it. I would like to easily drop all views in the database (they're all from PostGIS). Is there a simple way to do this? Even simply extracting a list of views names would be acceptable as I could just make a large DROP VIEWS statement.? Thanks In Advance
1 Answer
This should give you a set of view names in the public schema. Replace 'sandbox' with the name of your database.
select table_name
from information_schema.views
where table_catalog = 'sandbox'
and table_schema = 'public'
1 Comment
Craig Ringer
+1, and Satish can wrap this up into a PL/PgSQL function using
EXECUTE, string_agg and quote_ident to make a simple function to drop all views. S: To find out how, just do some searching, there are plenty of answers here that explain EXECUTE, format, etc.