Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tonyyates/dd3660edd58aaa658f46282376516d6e to your computer and use it in GitHub Desktop.

Select an option

Save tonyyates/dd3660edd58aaa658f46282376516d6e to your computer and use it in GitHub Desktop.
drop all tables in a postgres database
DO $$ DECLARE
tabname RECORD;
BEGIN
FOR tabname IN (SELECT tablename
FROM pg_tables
WHERE schemaname = current_schema())
LOOP
EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(tabname.tablename) || ' CASCADE';
END LOOP;
END $$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment