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();