Created
November 13, 2018 21:51
-
-
Save mlshvdv/cdcf94da3393ea518d192644ae4af7fb to your computer and use it in GitHub Desktop.
Drop all PostgreSQL tables by one query
This file contains hidden or 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 | |
| FOR r IN SELECT quote_ident(tablename) AS tablename, quote_ident(schemaname) AS schemaname FROM pg_tables WHERE schemaname = 'public' | |
| LOOP | |
| RAISE INFO 'Dropping table %.%', r.schemaname, r.tablename; | |
| EXECUTE format('DROP TABLE IF EXISTS %I.%I CASCADE', r.schemaname, r.tablename); | |
| END LOOP; | |
| END$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment