Re: Foreign Key Question

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Tuan Luu <tuanluu(at)gmx(dot)ch>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Foreign Key Question
Date: 2004-02-13 00:45:20
Message-ID: 20040213004520.GA22135@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Mon, Feb 09, 2004 at 08:59:12 +0100,
Tuan Luu <tuanluu(at)gmx(dot)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.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Fred Moyer 2004-02-13 00:53:49 Re: Showing all groups
Previous Message Stephan Szabo 2004-02-13 00:31:13 Re: Foreign Key Question