Lists: | pgsql-sql |
---|
From: | Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | diary constraints |
Date: | 2005-08-23 08:33:58 |
Message-ID: | 200508230933.59043.gary.stainburn@ringways.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Hi folks
I know this has been discussed in the past, but no amount of keywords
has returned anything from the archives.
I want to create a courtesy car diary diary system where I have a table
containing all of the cortesy cars in the pool, and then an allocation
table which has two timestamps, one for the start date/time and one for
the return date/time.
How do I go about creating constraints on inserts and updates to ensure
that
a) the finish is after the start
b) two allocations for a single vehicle don't overlap.
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
From: | Michael Glaesemann <grzm(at)myrealbox(dot)com> |
---|---|
To: | Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk> |
Cc: | postgresql sql list <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: diary constraints |
Date: | 2005-08-23 08:58:13 |
Message-ID: | 55E1EB3D-E2CF-41FD-86AD-B39007A48BF9@myrealbox.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
On Aug 23, 2005, at 5:33 PM, Gary Stainburn wrote:
> I want to create a courtesy car diary diary system where I have a
> table
> containing all of the cortesy cars in the pool, and then an allocation
> table which has two timestamps, one for the start date/time and one
> for
> the return date/time.
>
> How do I go about creating constraints on inserts and updates to
> ensure
> that
>
> a) the finish is after the start
> b) two allocations for a single vehicle don't overlap.
This is an interesting problem. You might want to take a look at this
book, previously mentioned on the one of the lists (by George Essig,
I believe):
> Developing Time-Oriented Database Applications in SQL
> by Richard T. Snodgrass
>
> The book is out of print, but the author has made the PDF available
> on his website at:
> http://www.cs.arizona.edu/people/rts/tdbbook.pdf
Hope this helps!
Michael Glaesemann
grzm myrealbox com
From: | Gnanavel S <s(dot)gnanavel(at)gmail(dot)com> |
---|---|
To: | Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: diary constraints |
Date: | 2005-08-23 09:00:10 |
Message-ID: | eec3b03c0508230200127dd262@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
On 8/23/05, Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk> wrote:
>
> Hi folks
>
> I know this has been discussed in the past, but no amount of keywords
> has returned anything from the archives.
>
> I want to create a courtesy car diary diary system where I have a table
> containing all of the cortesy cars in the pool, and then an allocation
> table which has two timestamps, one for the start date/time and one for
> the return date/time.
>
> How do I go about creating constraints on inserts and updates to ensure
> that
>
> a) the finish is after the start
check constraint like -> "finish_time > start_time" this will do
b) two allocations for a single vehicle don't overlap.
Use "overlaps" function in a trigger to validate the above.
--
> Gary Stainburn
>
> This email does not contain private or confidential material as it
> may be snooped on by interested government parties for unknown
> and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
--
with regards,
S.Gnanavel
Satyam Computer Services Ltd.
From: | PFC <lists(at)boutiquenumerique(dot)com> |
---|---|
To: | "Gary Stainburn" <gary(dot)stainburn(at)ringways(dot)co(dot)uk>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: diary constraints |
Date: | 2005-08-23 09:06:42 |
Message-ID: | op.svyd9g1mth1vuj@localhost |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
> a) the finish is after the start
well, finish > start
> b) two allocations for a single vehicle don't overlap.
this one is a bit tricky !
- Check that there is no allocation in the table whose time period start,
end includes either the start of the end of the reservation to insert, and
that the time period of the reservation to insert does not contain either
the start or end of any reservation in the table.
This is 4 selects, playing with order by limit 1 and indexes, it will be
fast.
From: | "A(dot) Kretschmer" <akretschmer(at)despammed(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: diary constraints |
Date: | 2005-08-23 09:12:38 |
Message-ID: | 20050823091238.GD24431@webserv.wug-glas.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
am 23.08.2005, um 9:33:58 +0100 mailte Gary Stainburn folgendes:
> Hi folks
>
> I know this has been discussed in the past, but no amount of keywords
> has returned anything from the archives.
>
> I want to create a courtesy car diary diary system where I have a table
> containing all of the cortesy cars in the pool, and then an allocation
> table which has two timestamps, one for the start date/time and one for
> the return date/time.
>
> How do I go about creating constraints on inserts and updates to ensure
> that
>
> a) the finish is after the start
with a check-constraint like this:
create table foobar (t1 timestamp, t2 timestamp check (t2>t1));
> b) two allocations for a single vehicle don't overlap.
possibly with a trigger.
Regards, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47212, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===