pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Erik Jones <erik@myemma.com>
To: Marcin Stępnicki <mstepnicki@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Finding gaps in scheduled events
Date: Tue, 12 Dec 2006 17:58:37 -0600
Message-ID: <457F422D.2000204@myemma.com> (raw)
In-Reply-To: <20061212222308.GP22782@alvh.no-ip.org>
References: <pan.2006.12.12.09.08.15.137773@gmail.com>
	<20061212222308.GP22782@alvh.no-ip.org>

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 <erik@myemma.com>
software development
emma(r)




view thread (5+ messages)

Message-ID: <457F422D.2000204@myemma.com>
Permalink:  ../457F422D.2000204@myemma.com/
Also on:    postgresql.org/message-id/457F422D.2000204@myemma.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: erik@myemma.com, mstepnicki@gmail.com
  Subject: Re: Finding gaps in scheduled events
  In-Reply-To: <457F422D.2000204@myemma.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox