Last active
April 25, 2025 02:15
-
-
Save yousan/a29149ffe7ba7459011a61cb9710674b to your computer and use it in GitHub Desktop.
Remove all data at PostgreSQL on public schema
This file contains hidden or 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
-- truncate All tables (Including foreign key constraint as CASCADE) | |
DO $$ | |
DECLARE | |
r RECORD; | |
BEGIN | |
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = 'public') LOOP | |
EXECUTE 'TRUNCATE TABLE public.' || 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