Skip to content

Instantly share code, notes, and snippets.

@j33ty
Created July 9, 2024 22:48
Show Gist options
  • Save j33ty/72324d5d25c8109dc7e7fdca5f28f7e6 to your computer and use it in GitHub Desktop.
Save j33ty/72324d5d25c8109dc7e7fdca5f28f7e6 to your computer and use it in GitHub Desktop.
Drop all postgresql schemas in a batch
CREATE OR REPLACE FUNCTION drop_all ()
RETURNS VOID AS
$$
DECLARE rec RECORD;
BEGIN
-- Get all the schemas
FOR rec IN
SELECT nspname FROM pg_catalog.pg_namespace WHERE (nspname != 'public') and (nspname NOT LIKE 'pg_%') and (nspname != 'information_schema') LIMIT 50
LOOP
EXECUTE format('DROP SCHEMA "%s" CASCADE', rec.nspname);
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
SELECT drop_all();
@j33ty
Copy link
Author

j33ty commented Jul 9, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment