/ db / test / sql /
/db/test/sql/groups_a_n_s_intervals_e
1 -- Copyright (C) 2013 The Meme Factory, Inc., http://www.meme.com/
2 --
3 -- This file is part of Gombe-MI.
4 --
5 -- Gombe-MI is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with Gombe-MI. If not, see <http://www.gnu.org/licenses/>.
17 --
18 -- Cannot be in group when not in study population,
19 -- enters late: update of intervals.
20 --
21 -- All data appearing in this work are fictitious. Any resemblance to
22 -- actual data, living or archived, is purely coincidental.
23 --
24 -- Karl O. Pinc <kop@meme.com>
25 --
26 -- Bugs:
27 -- This only happens to work because the intervals trigger checks
28 -- departdate before checking other stuff, like whether there
29 -- is a mom. The right way is probably to copy an existing follow
30 -- to another date and to move the group surveys' to it.
31 --
32 -- The interval.intid value needs to be filtered out of the pass test.
33
34 -- We have all the intervals for follows 1-4, but only the 2nd day
35 -- of follows (followid 3 and 4) of groups.
36
37 -- Change the entrydate of FE2 (young female) so that she is born
38 -- on the follow date, then switch the intervals to the follow of
39 -- the day earlier.
40
41 update biography_data
42 set entrydate = (select follows.date
43 from follows
44 where followid = 4)
45 where animid = 'FE2';
46
47 commit;
48 begin;
49
50 do $$
51 begin
52
53 create temp table foo
54 on commit drop
55 as select intervals.gid, intervals.time
56 from intervals
57 where intervals.followid = 4;
58
59 update intervals
60 set gid = null
61 where followid = 4;
62
63 update intervals
64 set gid = foo.gid
65 from foo
66 where intervals.followid = 2
67 and intervals.time = foo.time;
68
69 end;
70 $$;
71
72