Created
July 9, 2024 22:48
-
-
Save j33ty/72324d5d25c8109dc7e7fdca5f28f7e6 to your computer and use it in GitHub Desktop.
Drop all postgresql schemas in a batch
This file contains 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
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Courtesy: https://gist.github.com/xlucasdemelo/51d8d4a94e9a402daadf0579b0144a76