-- Copyright (C) 2013 The Meme Factory, Inc., http://www.meme.com/
--
-- This file is part of Gombe-MI.
--
-- Gombe-MI is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with Gombe-MI. If not, see .
--
-- Cannot be in group when not in study population,
-- enters late: update of intervals.
--
-- All data appearing in this work are fictitious. Any resemblance to
-- actual data, living or archived, is purely coincidental.
--
-- Karl O. Pinc
--
-- Bugs:
-- This only happens to work because the intervals trigger checks
-- departdate before checking other stuff, like whether there
-- is a mom. The right way is probably to copy an existing follow
-- to another date and to move the group surveys' to it.
--
-- The interval.intid value needs to be filtered out of the pass test.
-- We have all the intervals for follows 1-4, but only the 2nd day
-- of follows (followid 3 and 4) of groups.
-- Change the entrydate of FE2 (young female) so that she is born
-- on the follow date, then switch the intervals to the follow of
-- the day earlier.
update biography_data
set entrydate = (select follows.date
from follows
where followid = 4)
where animid = 'FE2';
commit;
begin;
do $$
begin
create temp table foo
on commit drop
as select intervals.gid, intervals.time
from intervals
where intervals.followid = 4;
update intervals
set gid = null
where followid = 4;
update intervals
set gid = foo.gid
from foo
where intervals.followid = 2
and intervals.time = foo.time;
end;
$$;