Created
October 23, 2014 23:40
-
-
Save happysundar/7dfefc971859dcf8d140 to your computer and use it in GitHub Desktop.
posgresql function to cleanup the schemas within a database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP FUNCTION IF EXISTS cleanup( ) CASCADE; | |
CREATE OR REPLACE FUNCTION | |
cleanup() | |
RETURNS VOID | |
AS $$ | |
DECLARE | |
row RECORD ; | |
BEGIN | |
FOR row IN WITH T1 AS (SELECT nspname :: TEXT AS schema_name | |
FROM pg_catalog.pg_namespace), T2 AS (SELECT schema_name | |
FROM T1 | |
WHERE schema_name LIKE 'unbound_%') SELECT * | |
FROM T2 | |
LOOP | |
RAISE LOG 'DROP SCHEMA % CASCADE', row.schema_name; | |
EXECUTE 'DROP SCHEMA '|| quote_ident(row.schema_name) || ' CASCADE'; | |
END LOOP; | |
END | |
$$ LANGUAGE plpgsql; | |
SELECT cleanup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment