Re: Foreign Key Question

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
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:31:13
Message-ID: 20040212162906.U99905@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin


On Mon, 9 Feb 2004, Tuan Luu 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?

What are the semantics you are looking for? Foreign keys only can refer
to unique things, because except for a few odd cases involving nulls and
match partial, it's intended that one particular row is being referenced.
If there are multiple rows in table1 with a particular productnr, how do
you want a reference to that to act (esp in the case of delete or update
to table 1).

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Bruno Wolff III 2004-02-13 00:45:20 Re: Foreign Key Question
Previous Message Tom Lane 2004-02-13 00:29:35 Re: No space left on device