From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Gerhard Heift <ml-postgresql-20081012-3518(at)gheift(dot)de> |
Cc: | PostgreSQL general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: unique index for periods |
Date: | 2009-08-20 14:14:57 |
Message-ID: | 13502.1250777697@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Gerhard Heift <ml-postgresql-20081012-3518(at)gheift(dot)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
> WHEN $2.next <= $1.first THEN 1
> ELSE 0
> END;
This does not work as a btree compare function, because it fails to
satisfy the basic requirements of a total order. In particular it
doesn't satisfy the transitive law that A=B and B=C must imply A=C.
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.
It'd be really nice to have uniqueness support in gist indexes someday
...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-08-20 14:20:15 | Re: ERROR: could not access file "$libdir/xxid": No such file or directory |
Previous Message | Scott Marlowe | 2009-08-20 13:45:45 | Re: ERROR: could not access file "$libdir/xxid": No such file or directory |