Re: Finding gaps in scheduled events

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Marcin Stępnicki <mstepnicki(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Finding gaps in scheduled events
Date: 2006-12-12 22:23:08
Message-ID: 20061212222308.GP22782@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Erik Jones 2006-12-12 23:58:37 Re: Finding gaps in scheduled events
Previous Message Erik Jones 2006-12-12 22:14:08 Re: Finding gaps in scheduled events