From: | Chris Browne <cbbrowne(at)acm(dot)org> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Relational database design book |
Date: | 2008-12-15 15:09:42 |
Message-ID: | 8763lleaq1.fsf@dba2.int.libertyrms.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
rshepard(at)appl-ecosys(dot)com (Rich Shepard) writes:
>
> [2] Strangely enough -- to me, at least -- the lack of full support for
> date- and time-based SQL in database tools such as PostgreSQL is puzzling.
> Virtually all business-related databases (think accounting systems as a
> prime example) depend on dates. So do many scientific databases.
The support for temporality in PostgreSQL seems above average as far
as I can see...
PostgreSQL has pretty nice time types between the timestamptz type and
interval.
What strikes me as being missing is the ability to create
temporally-aware foreign keys.
That is, suppose the schema is:
create table1 (
nearly_pk integer not null,
from_date timestamptz not null default now(),
to_date timestamptz not null default 'Infinity',
constraint dating_t1 check (from_date < to_date)
-- probably some other data...
);
I'd like to be able to do two more things:
a) Treat the date range as part of the primary key (which isn't
forcibly hard),
b) Have references to table1 that point to the time range for the
"nearly_pk" value but which are a little more liberal with the dates.
create table2 (
t2pk integer primary key,
nearly_pk integer not null,
from_date timestamptz not null default now(),
to_date timestamptz not null default 'Infinity',
-- And have a "foreign key" that requires that
-- for tuple in table2 the combination (nearly_pk, from_date, to_date)
-- is *contained* by relevant ranges of (nearly_pk, from_date, to_date)
-- on table1
foreign key (nearly_pk) references
table1(nearly_pk) with temporal (table2.from_date, table2.to_date)
contained_by (table1.from_date, table1.to_date)
);
I don't think the syntax there is necessarily quite right; I'm just
hoping to express the idea successfully.
I could presumably do this with a trigger; have been trying to avoid
that thus far.
There are, of course, other ways of treating temporality; that is part
of why it's early to treat this approach as worth putting into syntax.
--
output = ("cbbrowne" "@" "acm.org")
http://cbbrowne.com/info/finances.html
"When the grammar checker identifies an error, it suggests a
correction and can even makes some changes for you."
-- Microsoft Word for Windows 2.0 User's Guide, p.35:
From | Date | Subject | |
---|---|---|---|
Next Message | Ketema Harris | 2008-12-15 16:14:20 | View vs Constantly Updated Table |
Previous Message | Merlin Moncure | 2008-12-15 14:26:21 | Re: PostgreSQL installation |