TRUNCATE ALL Tables on Postgres

jerry80409
1 min readOct 25, 2019

--

Photo by Colton Sturgeon on Unsplash

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.

--

--

jerry80409
jerry80409

Written by jerry80409

隨便記錄一些沒有整理很清楚的想法

Responses (2)