Skip to content

Instantly share code, notes, and snippets.

@knopki
Last active August 14, 2022 12:27
Show Gist options
  • Select an option

  • Save knopki/63a9bc625864ee3b4b3aeb0e0ddfd884 to your computer and use it in GitHub Desktop.

Select an option

Save knopki/63a9bc625864ee3b4b3aeb0e0ddfd884 to your computer and use it in GitHub Desktop.
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;
FOR r IN (SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema()) LOOP
EXECUTE 'DROP SEQUENCE IF EXISTS ' || quote_ident(r.sequence_name);
END LOOP;
END $$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment