Skip to content

Instantly share code, notes, and snippets.

@lfittl
Created September 15, 2017 21:08
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 lfittl/69de944e9b778e8256c8b30797856bdd to your computer and use it in GitHub Desktop.
Save lfittl/69de944e9b778e8256c8b30797856bdd to your computer and use it in GitHub Desktop.
Drop All Tables
DO LANGUAGE plpgsql $$
DECLARE
t record;
tables text[];
BEGIN
FOR t IN SELECT schemaname, tablename FROM pg_tables WHERE schemaname NOT IN ('pg_catalog', 'information_schema') LOOP
tables := array_append(tables, quote_ident(t.schemaname) || '.' || quote_ident(t.tablename));
END LOOP;
IF array_length(tables, 1) > 0 THEN
EXECUTE 'DROP TABLE ' || array_to_string(tables, ', ') || ' CASCADE';
END IF;
END$$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment