pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Itai Zukerman <zukerman@math-hat.com>
To: Andreas Tille <tillea@rki.de>
Cc: PostgreSQL SQL <pgsql-sql@postgresql.org>
Subject: Re: Foreign key problem
Date: 25 Jun 2001 10:07:21 -0400
Message-ID: <878zig1wme.fsf@matt.w80.math-hat.com> (raw)
In-Reply-To: <Pine.LNX.4.33.0106250933390.905-100000@wr-linux02.rki.ivbb.bund.de>
References: <Pine.LNX.4.33.0106250933390.905-100000@wr-linux02.rki.ivbb.bund.de>

Je Mon, 25 Jun 2001 09:34:01 +0200 (CEST),
Andreas Tille <tillea@rki.de> scribis:

> CREATE TABLE ResKulturDetail
> (
>     IdLabNr   int,
>     IdIndex   smallint
> );
> 
> CREATE TABLE ResKulturDetailDay
> (
>     IdLabNr int,
>     IdIndex smallint
> );
> 
> CREATE INDEX IX_IdLabNr_KulturDetail ON ResKulturDetail(IdLabNr) ;
> 
> ALTER TABLE ResKulturDetailDay ADD CONSTRAINT FK_ResKulturDetailDay
>   FOREIGN KEY (IdLabNr,IdIndex)
>   REFERENCES ResKulturDetail (IdLabNr,IdIndex) ;

> Can anybody explain, why the foreign key constraint fails?

According to the documentation for CREATE TABLE:

  In addition, the referenced columns are supposed to be the columns
  of a UNIQUE constraint in the referenced table, however Postgres
  does not enforce this.

Well, it looks like PostgreSQL *does* enforce it.  Try it with:

  CREATE UNIQUE INDEX IX_IdLabNr_KulturDetail
  ON ResKulturDetail(IdLabNr, IdIndex) ;

I'm not sure why this restriction is necessary...

-- 
Itai Zukerman  <http://www.math-hat.com/~zukerman/;



view thread (11+ messages)  latest in thread

Message-ID: <878zig1wme.fsf@matt.w80.math-hat.com>
Permalink:  ../878zig1wme.fsf@matt.w80.math-hat.com/
Also on:    postgresql.org/message-id/878zig1wme.fsf@matt.w80.math-hat.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: zukerman@math-hat.com, tillea@rki.de
  Subject: Re: Foreign key problem
  In-Reply-To: <878zig1wme.fsf@matt.w80.math-hat.com>

* 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