Created
August 19, 2019 17:22
-
-
Save studiotomi/3c8bb22fc043cfb68fc66cba979b25f3 to your computer and use it in GitHub Desktop.
truncate all tables in a postgres schema
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 $func$ | |
BEGIN | |
EXECUTE ( | |
SELECT | |
'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE' | |
FROM | |
pg_class | |
WHERE | |
relkind = 'r' | |
AND relnamespace = 'schema_name'::regnamespace); | |
END | |
$func$; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment