From: | "Harald Armin Massa" <haraldarminmassa(at)gmail(dot)com> |
---|---|
To: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | challenging constraint situation - how do I make it real in SQL? |
Date: | 2006-05-24 07:36:57 |
Message-ID: | 7be3f35d0605240036q6d633fa1t35bcf2bbdb409a92@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I have a business rule which gives me rahter big challenges to "melt in SQL":
At one "point in time" only one version may be active.
Simplified:
CREATE TABLE sample
(
id_field int4,
value text,
validfrom timestamp,
validto timestamp
)
within one timespan, every id_field has to be unique.
so, this is a set of legal data:
1, 'fire', -infinity , 2005-09-01 21:02:15.078
1, 'water', 2005-09-01 21:02:15.078, infinity
this is an illegal set of data:
1, 'fire', -infinity , 2005-09-01 21:02:15.078
1, 'water', 2005-05-01 12:15:15.078, infinity
because between 2005-05-01 12:15:15.078 and 2005-09-01 21:02:15.078
there are 2 values for id_field 1
As a first measure I have made a unique key on (id_field ,
validfrom), because the "timespans" are created by update rules of a
view, so that I am quite sure that there are no overlapping ... as
long as nobody touches the table by himself.
But it is not really fitting; and manual editing of the table can
disturb it. So, ist there some constraint creatable to make sure that
"in each point of time" each id only exists once?
Harald
--
GHUM Harald Massa
persuadere et programmare
Harald Armin Massa
Reinsburgstraße 202b
70197 Stuttgart
0173/9409607
-
PostgreSQL - supported by a community that does not put you on hold
From | Date | Subject | |
---|---|---|---|
Next Message | Gavin Hamill | 2006-05-24 08:02:35 | Clearing out old idle connections |
Previous Message | Dave Page | 2006-05-24 07:13:10 | Re: More confirmation: pgadmin3 freezeup fixed by wxgtk |