Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 59B9D131F6D2 for ; Fri, 16 Mar 2012 11:14:11 -0300 (ADT) Received: from mailout01.ims-firmen.de ([213.174.32.96]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S8Xuu-0006yx-M7 for pgsql-general@postgresql.org; Fri, 16 Mar 2012 14:14:10 +0000 Received: from mailin02.ims-firmen.de ([192.168.1.142]) by mailout01.ims-firmen.de with esmtp (envelope-from ) id 1S8Xuh-0004rB-BW for pgsql-general@postgresql.org; Fri, 16 Mar 2012 15:13:51 +0100 Received: from [87.170.218.1] (helo=a-kretschmer.de) by mailin02.ims-firmen.de with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1S8XuL-0003rb-9w for pgsql-general@postgresql.org; Fri, 16 Mar 2012 15:13:29 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1S8Xug-0001fX-2e for pgsql-general@postgresql.org; Fri, 16 Mar 2012 15:13:50 +0100 Date: Fri, 16 Mar 2012 15:13:50 +0100 From: Andreas Kretschmer To: pgsql-general@postgresql.org Subject: Re: Temporal foreign keys Message-ID: <20120316141350.GA5716@tux> References: <1331848387.26127.33.camel@sussancws0025> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1331848387.26127.33.camel@sussancws0025> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201203/478 X-Sequence-Number: 185804 Jeff Davis 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°