Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 1D15219964F2 for ; Fri, 16 Mar 2012 18:14:07 -0300 (ADT) Received: from mail-iy0-f174.google.com ([209.85.210.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S8eTN-0006Dz-RT for pgsql-general@postgresql.org; Fri, 16 Mar 2012 21:14:06 +0000 Received: by iagz16 with SMTP id z16so5934844iag.19 for ; Fri, 16 Mar 2012 14:13:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding :x-gm-message-state; bh=OITBIu0olIxZJm70MLBmYFZiilfNkVWnNgi9P+ySiDQ=; b=ODB6wlnu2MV6FgvSnuPnAGXyrsB7OQkkR0d23y6wZbctEbvUcq8AyW6W5NPbHY6ju2 3poMw1ooSz67VCbQWPPSAEYq/GAp7cVpYWGQ4Q/Mrh22mY0x+WDirQZ8QyoqTiCcJXRX n32OYvfKyqZARq/+NF5fa1YMEgQxC5suOZYm9dul4OKxvabGiifGZmFYJWccFdoYcys+ viBC462iNx3wVhKjOrrNrtaPQgz8mQrHVyPK+qFkJa4XvS9dWY4a7JWJg1z9fj1mP387 IXAuOL3V3rGDO1djUOPp2VSYKcUaBqMq5rDt6SdT2OMyS97ViSQQcOJo9XGesh4+KSyo JjZw== Received: by 10.50.45.234 with SMTP id q10mr515525igm.54.1331932432614; Fri, 16 Mar 2012 14:13:52 -0700 (PDT) Received: from ?IPv6:::1? (li224-40.members.linode.com. [173.255.214.40]) by mx.google.com with ESMTPS id cu4sm568956igc.15.2012.03.16.14.13.50 (version=SSLv3 cipher=OTHER); Fri, 16 Mar 2012 14:13:51 -0700 (PDT) Subject: Re: Temporal foreign keys From: Jeff Davis To: Andreas Kretschmer Cc: pgsql-general@postgresql.org In-Reply-To: <20120316141350.GA5716@tux> References: <1331848387.26127.33.camel@sussancws0025> <20120316141350.GA5716@tux> Content-Type: text/plain; charset="ISO-8859-1" Date: Fri, 16 Mar 2012 14:13:48 -0700 Message-ID: <1331932428.5271.124.camel@sussancws0025> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQk70Q/MAYVb1F1525jmEgorTqdpf1ysQSRabms0VTEKGqNHivnztHzdwZ1T2Exdhu89n0cw X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201203/495 X-Sequence-Number: 185821 On Fri, 2012-03-16 at 15:13 +0100, Andreas Kretschmer wrote: > > On Fri, 2012-02-03 at 07:58 +0100, Matthias wrote: > > > how can I implement temporal foreign keys with postgresql? Is writing > > > triggers the only way to enforce temporal referential integrity > > > currently? > > > 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". If I understand what he was asking for, it was a kind of "range foreign key" which means that the following query should succeed: insert into y values ('[2012-01-02,2012-01-04)'); because that range is contained in a value in the table x. So it's slightly different semantics than a normal foreign key. But yes, normal foreign keys (based on equality) work fine over range types. Regards, Jeff Davis