Skip to content

Instantly share code, notes, and snippets.

@studiotomi
Created August 19, 2019 17:22
Show Gist options
  • Save studiotomi/3c8bb22fc043cfb68fc66cba979b25f3 to your computer and use it in GitHub Desktop.
Save studiotomi/3c8bb22fc043cfb68fc66cba979b25f3 to your computer and use it in GitHub Desktop.
truncate all tables in a postgres schema
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