Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 26EF09FA49E for ; Tue, 12 Dec 2006 19:58:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 07617-04-3 for ; Tue, 12 Dec 2006 19:58:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from myemma.com (db1.e2ma.net [66.179.147.163]) by postgresql.org (Postfix) with ESMTP id 4DF8B9FA380 for ; Tue, 12 Dec 2006 19:58:40 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by myemma.com (Postfix) with ESMTP id 0051423CD0; Tue, 12 Dec 2006 17:58:38 -0600 (CST) Received: from myemma.com ([127.0.0.1]) by localhost (velma [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 20769-01; Tue, 12 Dec 2006 17:58:38 -0600 (CST) Received: from [10.0.23.54] (unknown [209.149.59.218]) by myemma.com (Postfix) with ESMTP id 2498623CCA; Tue, 12 Dec 2006 17:58:38 -0600 (CST) Message-ID: <457F422D.2000204@myemma.com> Date: Tue, 12 Dec 2006 17:58:37 -0600 From: Erik Jones User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: =?UTF-8?B?TWFyY2luIFN0xJlwbmlja2k=?= , pgsql-sql@postgresql.org Subject: Re: Finding gaps in scheduled events References: <20061212222308.GP22782@alvh.no-ip.org> In-Reply-To: <20061212222308.GP22782@alvh.no-ip.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at myemma.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/97 X-Sequence-Number: 27053 Alvaro Herrera wrote: > Marcin Stępnicki wrote: > > >> Now I need to create a query to find hours at which each of the type can >> start. So, if it's event A (which take 15 minutes) it can start at: >> >> 8:00 (to 8:15) >> 8:15 (to 8:30) >> ( 8:30 to 8:45 is already taken ) >> 8:45 (to 9:00) >> 9:00 (to 9:15) >> 9:15 (to 9:30) >> ( 9:30 to 10:00 (9:30-9:45 and 9:45-10:00) is already taken)) >> 10:00 (to 10:15) >> > > I think something like this should help you: > > select my_hour > from test_events right join test_timeline on > ((start, finish) overlaps (my_hour, my_hour + 15 * '1 minute'::interval)) > where start is null; > > With your test data, it shows all the times except for 8:30, 9:30 and > 9:45. > Nice! And, he can run that query again, flipping the 15 to 30, to get the list of available 30 minute gaps. That's a heck-of-a lot simpler than the stuff I discussed earlier. -- erik jones software development emma(r)