Created
December 12, 2017 00:24
-
-
Save Benoss/136f5d3e25c6da2ac98857e16bb39972 to your computer and use it in GitHub Desktop.
Delete all tables from current schema in postgres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO $$ DECLARE | |
r RECORD; | |
BEGIN | |
-- if the schema you operate on is not "current", you will want to | |
-- replace current_schema() in query with 'schematodeletetablesfrom' | |
-- *and* update the generate 'DROP...' accordingly. | |
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP | |
EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE'; | |
END LOOP; | |
END $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment