[GENERAL] unique index for periods

2009-08-20 Thread Gerhard Heift
Hello, I try to create an unique index for a (time)period, and my goal is to prevent two overlapping periods in a row. For this I created a type with following command: CREATE TYPE period AS (first timestamp with time zone, next timestamp with time zone); To use the btree index I added

Re: [GENERAL] unique index for periods

2009-08-20 Thread Harald Fuchs
In article 20090820065819.ga2...@gheift.kawo1.rwth-aachen.de, Gerhard Heift ml-postgresql-20081012-3...@gheift.de writes: Hello, I try to create an unique index for a (time)period, and my goal is to prevent two overlapping periods in a row. ... Is there another solution to solve my

Re: [GENERAL] unique index for periods

2009-08-20 Thread Tom Lane
Gerhard Heift ml-postgresql-20081012-3...@gheift.de writes: I try to create an unique index for a (time)period, and my goal is to prevent two overlapping periods in a row. To use the btree index I added a compare function: return CASE WHEN $1.next = $2.first THEN -1

Re: [GENERAL] unique index for periods

2009-08-20 Thread Greg Stark
On Thu, Aug 20, 2009 at 3:14 PM, Tom Lanet...@sss.pgh.pa.us wrote: I don't believe it is possible to use a btree index for this purpose, because there just isn't a way to express overlaps as a total order. That's true for the general case of indexing ranges but I don't think that's true for the

Re: [GENERAL] unique index for periods

2009-08-20 Thread Tom Lane
Greg Stark gsst...@mit.edu writes: On Thu, Aug 20, 2009 at 3:14 PM, Tom Lanet...@sss.pgh.pa.us wrote: I don't believe it is possible to use a btree index for this purpose, because there just isn't a way to express overlaps as a total order. That's true for the general case of indexing ranges

Re: [GENERAL] unique index for periods

2009-08-20 Thread Jeff Davis
On Thu, 2009-08-20 at 13:35 +0200, Harald Fuchs wrote: Have a look at http://pgfoundry.org/projects/temporal The temporal project on pgfoundry only provides the time period type, which is (hopefully) useful, but it does not help with a non-overlapping constraint. Please see my other project