Created
September 13, 2016 17:30
-
-
Save yiqingj/ee495383f9dc29d435edca547bb2f81f to your computer and use it in GitHub Desktop.
delete all data in database
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
| CREATE OR REPLACE FUNCTION truncate_tables(username IN VARCHAR) RETURNS void AS $$ | |
| DECLARE | |
| statements CURSOR FOR | |
| SELECT tablename FROM pg_tables | |
| WHERE tableowner = username AND schemaname = 'public'; | |
| BEGIN | |
| FOR stmt IN statements LOOP | |
| EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;'; | |
| END LOOP; | |
| END; | |
| $$ LANGUAGE plpgsql; | |
| SELECT truncate_tables('www-data'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment