Skip to content

Instantly share code, notes, and snippets.

@ar45
Created September 14, 2016 21:19
Show Gist options
  • Save ar45/b13f1409becb605bced78dbfe6ead6a6 to your computer and use it in GitHub Desktop.
Save ar45/b13f1409becb605bced78dbfe6ead6a6 to your computer and use it in GitHub Desktop.
Drop all tables in a schema - postgres
DO $$
DECLARE
stmt TEXT;
BEGIN
FOR stmt IN SELECT 'DROP TABLE IF EXISTS "' || tablename || '" CASCADE;'
from pg_tables
WHERE schemaname = 'public'
LOOP
EXECUTE stmt;
END LOOP;
END;
$$
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment