From: | Michael Glaesemann <grzm(at)myrealbox(dot)com> |
---|---|
To: | Michael Fuhr <mike(at)fuhr(dot)org> |
Cc: | Andreas <maps(dot)on(at)gmx(dot)net>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: How to check date-interval constraints |
Date: | 2006-03-03 05:25:47 |
Message-ID: | 1B741D25-BFC8-4150-81C7-2705AF50D21B@myrealbox.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Mar 3, 2006, at 14:13 , Michael Fuhr wrote:
> On Fri, Mar 03, 2006 at 04:28:01AM +0100, Andreas wrote:
>> How can I have a constraint, that prohibits nesting or overlapping
>> intervals?
>>
>> 1 7 2006-1-1 2006-1-31
>> 2 9 2006-2-1 2006-2-28 OK
>> 3 5 2006-1-10 2006-1-20 BAD lies within line 1
>> 4 3 2006-1-20 2006-2-10 BAD starts within
>> line 1
>> and ends in line 2
>
> This is just a brainstorm, but what about creating a composite type,
> a comparison function, and an operator class, then declaring a
> unique index on that composite type?
Another way is presented in Snodgrass' "Developing Time-Oriented
Database Applications in SQL", out of print but available as a PDF
download from his website:
http://www.cs.arizona.edu/people/rts/tdbbook.pdf
You'll need to use CREATE CONSTRAINT TRIGGER rather than just CREATE
TRIGGER to apply the constraints you're looking for, as often you'll
need to wrap a multi-statement update in a transaction to ensure
integrity.
Michael Glaesemann
grzm myrealbox com
From | Date | Subject | |
---|---|---|---|
Next Message | Bryce Nesbitt | 2006-03-03 07:27:21 | Sequential scan where Index scan expected. |
Previous Message | Michael Fuhr | 2006-03-03 05:13:30 | Re: How to check date-interval constraints |