-- 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 . -- -- Add to groups (but not groupmembers) for all (9am to 5pm) -- intervals of follows 1-2, the first day's follows. -- -- All data appearing in this work are fictitious. Any resemblance to -- actual data, living or archived, is purely coincidental. -- -- Karl O. Pinc -- -- -- Main tables. -- do $$ declare this_time time; this_min int; this_diff int; this_gid int[]; begin this_time := '9:00'; while this_time <= '17:00' loop this_min := extract('minute' from this_time); this_diff := this_min % 5; for fid in 1 .. 2 loop -- Give each of the follows' intervals a group. if this_diff = 0 then -- 5 minute mark, new group -- groups insert into groups (gid) values(nextval('groups_gid_seq'::regclass)); this_gid[fid] := currval('groups_gid_seq'::regclass); end if; -- Connect the group to an interval. update intervals set gid = this_gid[fid] where followid = fid and time = this_time; end loop; this_time := this_time + '1 minute'::interval; end loop; end; $$;