X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E8E22D7A42 for ; Fri, 2 Sep 2005 11:26:56 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 59570-03 for ; Fri, 2 Sep 2005 14:26:55 +0000 (GMT) Received: from postfix4-2.free.fr (postfix4-2.free.fr [213.228.0.176]) by svr1.postgresql.org (Postfix) with ESMTP id 941C9D7769 for ; Fri, 2 Sep 2005 11:26:53 -0300 (ADT) Received: from nordine.ateur (main.librelogiciel.com [82.232.68.73]) by postfix4-2.free.fr (Postfix) with ESMTP id 4B6C2323544; Fri, 2 Sep 2005 16:26:58 +0200 (CEST) Received: from jerome by nordine.ateur with local (Exim 3.36 #1 (Debian)) id 1EBCVN-0003UM-00; Fri, 02 Sep 2005 16:26:57 +0200 Date: Fri, 2 Sep 2005 16:26:57 +0200 To: Achilleus Mantzios Cc: pgsql-sql@postgresql.org Subject: Re: not sure about constraints Message-ID: <20050902142657.GE10284@mail.librelogiciel.com> References: <20050902132356.GD10284@mail.librelogiciel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i From: Jerome Alet X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.617 required=5 tests=[AWL=0.360, FORGED_RCVD_HELO=0.05, UPPERCASE_25_50=0.207] X-Spam-Level: X-Archive-Number: 200509/14 X-Sequence-Number: 22561 On Fri, Sep 02, 2005 at 04:43:15PM +0300, Achilleus Mantzios wrote: > O Jerome Alet ?????? ???? Sep 2, 2005 : > > > I've got 4 tables : > > > > CREATE TABLE tableA (id SERIAL PRIMARY KEY NOT NULL, > > blahA TEXT); > > > > CREATE TABLE tableB (id SERIAL PRIMARY KEY NOT NULL, > > blahB TEXT); > > > > CREATE TABLE tableC (id SERIAL PRIMARY KEY NOT NULL, > > ida INT4 REFERENCES tableA(id), > > idb INT4 REFERENCES tableB(id), > > blahC TEXT); > > > > CREATE TABLE tableD > > (id SERIAL PRIMARY KEY NOT NULL, > > ida INT4, > > idb INT4, > > blahC TEXT, > > CONSTRAINT checkAB FOREIGN KEY (ida, idb) REFERENCES tableC(ida, idb)); > > The above statement is in error. > In order to create FK to another table (tableC), you must do this > on tableC's PK (id) or some UNIQUE key in general. sorry, while adapting the code for the purpose of posting here, I've forgotten that I've this line in my real script : CREATE UNIQUE INDEX tableCindex ON tableC (ida, idb); So I think tableD should be OK (BTW I don't have any error) Thanks for your help bye Jerome Alet