Skip to content

Instantly share code, notes, and snippets.

@yousan
Last active April 25, 2025 02:15
Show Gist options
  • Save yousan/a29149ffe7ba7459011a61cb9710674b to your computer and use it in GitHub Desktop.
Save yousan/a29149ffe7ba7459011a61cb9710674b to your computer and use it in GitHub Desktop.
Remove all data at PostgreSQL on public schema
-- 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