Last Updated: February 25, 2016
·
427
· snuxoll

PostgreSQL - Drop all tables in current DB

DO $$
DECLARE
  tbl pg_tables%ROWTYPE;
BEGIN
  FOR tbl IN SELECT * FROM pg_tables
  WHERE schemaname = 'public'
  LOOP
    EXECUTE 'DROP TABLE ' || tbl.tablename || ' CASCADE;';
  END LOOP;
END$$