Created
October 19, 2012 16:23
-
-
Save hgdeoro/3919157 to your computer and use it in GitHub Desktop.
Truncate all the tables of 'public' schema
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
CREATE OR REPLACE FUNCTION truncate_all_tables() RETURNS void AS $$ | |
DECLARE | |
stmt RECORD; | |
statements CURSOR FOR SELECT tablename from pg_tables where schemaname = 'public'; | |
BEGIN | |
FOR stmt IN statements LOOP | |
EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;'; | |
END LOOP; | |
END; | |
$$ LANGUAGE 'plpgsql'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment