Re: Non-Overlaping date interval index

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Non-Overlaping date interval index
Date: 2006-02-18 09:31:35
Message-ID: 20060218093135.GA7415@webserv.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

am 18.02.2006, um 10:03:11 +0100 mailte Pailloncy Jean-Gerard folgendes:
> Hi,
>
> I wonder how to have a sort of "uniq" index on date interval, such that
> there is no date interval overlaping in the table.
>
> exemple:
> create table test (start timestamp, end timestamp);
> with the constraint: end > start

You can write a trigger to check the count of records which overlaps
(start,end):

Example:

test=# select * from foo;
id | s | e
----+---------------------+---------------------
1 | 2006-01-01 00:00:00 | 2006-01-02 00:00:00
2 | 2006-01-02 00:00:00 | 2006-01-03 00:00:00
3 | 2006-01-03 00:00:00 | 2006-01-04 00:00:00
(3 rows)

test=# select count(*) from foo where (s,e) overlaps ('2006/01/05'::date, '2006/01/06'::date);
count
-------
0
(1 row)

test=# select count(*) from foo where (s,e) overlaps ('2006/01/01'::date, '2006/01/06'::date);
count
-------
3
(1 row)

Perhaps there are other solutions...

HTH, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47215, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2006-02-18 10:05:05 Re: Converting an ASCII database to an UTF-8 database
Previous Message Martijn van Oosterhout 2006-02-18 09:18:23 Re: Non-Overlaping date interval index