#!/bin/sh echo " drop table if exists t; -- dropping a table, be careful! create table t as select d from generate_series( current_timestamp - interval '99 days' , current_timestamp , interval '1 day' ) as f(d) ; -- UPDATE: add this for index tests: -- create index t_d_idx on t (d); select count(*) , sum( case when now() - d > interval '60 days' then 0 else 1 end ) as records_to_keep , sum( case when now() - d > interval '60 days' then 1 else 0 end ) as records_to_dump from t; delete from t where now() - d > interval '60 days' ; select count(*) , sum( case when now() - d > interval '60 days' then 0 else 1 end ) as records_to_keep , sum( case when now() - d > interval '60 days' then 1 else 0 end ) as records_to_dump from t; " | psql -X