Thursday, May 8, 2008

[SQL] Index to enforce non-overlapping ranges?

Academic question here:

Given a table with a pair of any sort of line-segment-esqe range
delimiter columns, is it possible to build a unique index to enforce
non-overlapping ranges? Such as:

create table test
(
id int not null primary key,
low_value int not null,
high_value int not null
);

Can one build an index to enforce a rule such that no (low_value,
high_value) range is identical or overlaps with another (low_value,
high_value) range described by the table? And, more interestingly,
what about for ranges of dates / timestamps as opposed to simple
integers?

I can see how a trigger on insert or update could enforce such a
constraint [ probe the table for an existing overlapping row, and
raise exception one exists ], but can such an activity be performed
with fewer lines using some sort of r-tree index?

----
James Robinson
Socialserve.com


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

No comments: