pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Tuan Luu <tuanluu@gmx.ch>
Cc: pgsql-admin@postgresql.org
Subject: Re: Foreign Key Question
Date: Thu, 12 Feb 2004 18:45:20 -0600
Message-ID: <20040213004520.GA22135@wolff.to> (raw)
In-Reply-To: <40273DD0.6030004@gmx.ch>
References: <40273DD0.6030004@gmx.ch>

On Mon, Feb 09, 2004 at 08:59:12 +0100,
  Tuan Luu <tuanluu@gmx.ch> wrote:
> Example:
> 
> Table 1:
> Inventory, Productnr, Productserial
> (PK Inventory, Prouctnr)
> 
> Table 2:
> Pruductnr, Produktdesc, Productversion
> (PK Productnr; FK Productnr)
> 
> This Construct gives me an error during the creation in Postgresql 
> (saying there is no unique constraint matching given keys for referenced 
> table xxxx). The Primary Key in table 1 consists of two columns. In the 
> second table there is a foreign key refencing to the first table. 
> 
> A unique constraint doesn't make sense on table one. Am I missing 
> something here?

Having typos in what you show us doesn't help.

Inventory, Productnr being unique does not imply Productnr is unique.
If Productnr in table 1 is unique, you should make a unique constraint
on it. If it isn't unique you can't use a foreign key reference and you
will need to write your own trigger functions to do whatever makes sense
for your problem.



view thread (3+ messages)

Message-ID: <20040213004520.GA22135@wolff.to>
Permalink:  ../20040213004520.GA22135@wolff.to/
Also on:    postgresql.org/message-id/20040213004520.GA22135@wolff.to

 · 

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-admin@postgresql.org
  Cc: bruno@wolff.to, tuanluu@gmx.ch
  Subject: Re: Foreign Key Question
  In-Reply-To: <20040213004520.GA22135@wolff.to>
  References: <40273DD0.6030004@gmx.ch> <20040213004520.GA22135@wolff.to>

* 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