postgresql7.1
select r.reservation_id
from acs_events e join timespans s
on (e.timespan_id = s.timespan_id)
join time_intervals t
on (s.interval_id = t.interval_id)
join rr_reservations r
on (e.event_id = r.reservation_id)
where end_date < (now() - to_number(:expiry_days,'999'));
select rr_reservations__delete(:reservation_id)