Skip to content

Instantly share code, notes, and snippets.

@VictorHugoBatista
Last active October 14, 2021 17:44
Show Gist options
  • Save VictorHugoBatista/50d440e7afba5730bc7eee72d9649871 to your computer and use it in GitHub Desktop.
Save VictorHugoBatista/50d440e7afba5730bc7eee72d9649871 to your computer and use it in GitHub Desktop.
Drop all tables from a postgres database
# /!\ Double check before press enter on this command /!\
DO $$ DECLARE
r RECORD;
BEGIN
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
EXECUTE 'DROP TABLE IF EXISTS ' || 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