pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-general@postgresql.org
Subject: Re: Temporal foreign keys
Date: Fri, 16 Mar 2012 15:13:50 +0100
Message-ID: <20120316141350.GA5716@tux> (raw)
In-Reply-To: <1331848387.26127.33.camel@sussancws0025>
References: <CACECd8i4P4iNqUii4Lqsw0qSthawhh3gE=AtmBDSJN25qrx15g@mail.gmail.com>
	<1331848387.26127.33.camel@sussancws0025>

Jeff Davis <pgsql@j-davis.com> wrote:

> On Fri, 2012-02-03 at 07:58 +0100, Matthias wrote:
> > Hey,
> > 
> > how can I implement temporal foreign keys with postgresql? Is writing
> > triggers the only way to enforce temporal referential integrity
> > currently?
> 
> Yes, currently that's the only way. Look at CREATE CONSTRAINT TRIGGER.

It works in 9.2devel ;-)

test=# create table x (d daterange primary key);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "x_pkey"
for table "x"
CREATE TABLE
test=*# create table y (d daterange references x);
CREATE TABLE
test=*# insert into x values ('[2012-01-01,2012-01-10)');
INSERT 0 1
test=*# insert into y values ('[2012-01-01,2012-01-10)');
INSERT 0 1
test=*# insert into y values ('[2012-01-01,2012-01-20)');
ERROR:  insert or update on table "y" violates foreign key constraint "y_d_fkey"
DETAIL:  Key (d)=([2012-01-01,2012-01-20)) is not present in table "x".



Jeff: thx for YOUR work!


Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°



view thread (6+ messages)  latest in thread

Message-ID: <20120316141350.GA5716@tux>
Permalink:  ../20120316141350.GA5716@tux/
Also on:    postgresql.org/message-id/20120316141350.GA5716@tux

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: akretschmer@spamfence.net
  Subject: Re: Temporal foreign keys
  In-Reply-To: <20120316141350.GA5716@tux>
  References: <CACECd8i4P4iNqUii4Lqsw0qSthawhh3gE=AtmBDSJN25qrx15g@mail.gmail.com> <1331848387.26127.33.camel@sussancws0025> <20120316141350.GA5716@tux>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox