Re: Script to clean out old records
In case it is of use to anyone (or me in the future!) here is a script that can be run against postgreSQL to remove records entered into a survey before a specified date:
delete from occurrence_attribute_values where id in (
select oav.id
from occurrence_attribute_values oav
inner join occurrences o on o.id=oav.occurrence_id
inner join samples s on s.id=o.sample_id
where s.survey_id=7
and s.created_on < '2010-04-22');
delete from sample_attribute_values where id in (
select sav.id
from sample_attribute_values sav
inner join samples s on s.id=sav.sample_id
where s.survey_id=7
and s.created_on < '2010-04-22');
delete from occurrences
where sample_id in
(select id from samples where survey_id=7
and created_on < '2010-04-22');
delete from samples where survey_id=7
and created_on < '2010-04-22';
Biodiverse IT