Created
September 15, 2017 21:08
-
-
Save lfittl/69de944e9b778e8256c8b30797856bdd to your computer and use it in GitHub Desktop.
Drop All Tables
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
DO LANGUAGE plpgsql $$ | |
DECLARE | |
t record; | |
tables text[]; | |
BEGIN | |
FOR t IN SELECT schemaname, tablename FROM pg_tables WHERE schemaname NOT IN ('pg_catalog', 'information_schema') LOOP | |
tables := array_append(tables, quote_ident(t.schemaname) || '.' || quote_ident(t.tablename)); | |
END LOOP; | |
IF array_length(tables, 1) > 0 THEN | |
EXECUTE 'DROP TABLE ' || array_to_string(tables, ', ') || ' CASCADE'; | |
END IF; | |
END$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment