Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save meorajrul/7005bac80d8d2624ad3d91d0af4df7a2 to your computer and use it in GitHub Desktop.
Save meorajrul/7005bac80d8d2624ad3d91d0af4df7a2 to your computer and use it in GitHub Desktop.
postgres drop all table and schema
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