UPDATE: Oops. You *did* mention the DBMS, in the title no less. I didn't see that. So this is a little off topic -- sorry about that.
In PostgreSQL:
delete from table where now() - column > interval '60 days';I wrote a little standalone bash to show that off. It creates 100 days worth of rows, shows some counts, DELETEs with an appropriate interval expression, then counts again:
(careful: it drops table t)
#!/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
Output:
DROP TABLE SELECT 100 count | records_to_keep | records_to_dump -------+-----------------+----------------- 100 | 60 | 40 (1 row) DELETE 41 count | records_to_keep | records_to_dump -------+-----------------+----------------- 60 | 60 | 0 (1 row)
In reply to Re: CGI Program To Delete Old Data From MySQL Table?
by erix
in thread CGI Program To Delete Old Data From MySQL Table?
by Milti
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |