Created
April 29, 2020 11:26
-
-
Save mchoplin/586c8c4a1255deff46d631ac77914744 to your computer and use it in GitHub Desktop.
script to truncate all tables from postgres database
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 $$ DECLARE | |
r RECORD; | |
BEGIN | |
FOR r IN (SELECT tablename FROM pg_tables | |
WHERE schemaname = current_schema() | |
AND current_database() = 'make sure you have the right database') LOOP | |
EXECUTE 'TRUNCATE ' || quote_ident(r.tablename) || ' CASCADE'; | |
END LOOP; | |
END $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment