Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop all functions from Postgres database

Tags:

I have a database with an old broken version of PostGIS installed in it. I would like to easily drop all functions in the database (they're all from PostGIS). Is there a simple way to do this? Even simply extracting a list of function names would be acceptable as I could just make a large DROP FUNCTION statement.

like image 604
Jim Mitchener Avatar asked May 14 '12 21:05

Jim Mitchener


People also ask

What is drop cascade in PostgreSQL?

The CASCADE option allows you to remove the table and its dependent objects. The RESTRICT option rejects the removal if there is any object depends on the table. The RESTRICT option is the default if you don't explicitly specify it in the DROP TABLE statement.

How do I select all in PostgreSQL?

If you want to select data from all the columns of the table, you can use an asterisk ( * ) shorthand instead of specifying all the column names. The select list may also contain expressions or literal values. Second, specify the name of the table from which you want to query data after the FROM keyword.


2 Answers

A fine answer to this question can be found here:

SELECT 'DROP FUNCTION ' || ns.nspname || '.' || proname         || '(' || oidvectortypes(proargtypes) || ');' FROM pg_proc INNER JOIN pg_namespace ns ON (pg_proc.pronamespace = ns.oid) WHERE ns.nspname = 'my_messed_up_schema'  order by proname; 
like image 185
ChristopheD Avatar answered Oct 04 '22 20:10

ChristopheD


Just as there was a postgis.sql enabler install script, there is also an uninstall_postgis.sql uninstall script.

psql -d [yourdatabase] -f /path/to/uninstall_postgis.sql 

Warning: Be prepared to see your geometry/geography columns and data disappear!

like image 30
Mike T Avatar answered Oct 04 '22 18:10

Mike T