Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mchoplin
Created April 29, 2020 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchoplin/586c8c4a1255deff46d631ac77914744 to your computer and use it in GitHub Desktop.
Save mchoplin/586c8c4a1255deff46d631ac77914744 to your computer and use it in GitHub Desktop.
script to truncate all tables from postgres database
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