TRUNCATE ALL Tables on Postgres
1 min readOct 25, 2019
This Halloween I TRUNCATE ALL the tables and trick or treating :D
DO $$DECLARE tables CURSOR FOR SELECT tablename FROM pg_catalog.pg_tables WHERE tableowner = 'username' AND schemaname = 'public';BEGIN FOR table IN tables LOOP EXECUTE 'TRUNCATE TABLE ' || quote_ident(table.tablename) || ' CASCADE;'; END LOOP;END;$$
Just joking.