pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedForeign Key Question
3+ messages / 3 participants
[nested] [flat]
* Foreign Key Question
@ 2004-02-09 07:59 Tuan Luu <tuanluu@gmx.ch>
2004-02-13 00:31 ` Re: Foreign Key Question Stephan Szabo <sszabo@megazone.bigpanda.com>
2004-02-13 00:45 ` Re: Foreign Key Question Bruno Wolff III <bruno@wolff.to>
0 siblings, 2 replies; 3+ messages in thread
From: Tuan Luu @ 2004-02-09 07:59 UTC (permalink / raw)
To: pgsql-admin
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?
Thanks for any answer
Tuan
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Foreign Key Question
2004-02-09 07:59 Foreign Key Question Tuan Luu <tuanluu@gmx.ch>
@ 2004-02-13 00:31 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
1 sibling, 0 replies; 3+ messages in thread
From: Stephan Szabo @ 2004-02-13 00:31 UTC (permalink / raw)
To: Tuan Luu <tuanluu@gmx.ch>; +Cc: 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).
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Foreign Key Question
2004-02-09 07:59 Foreign Key Question Tuan Luu <tuanluu@gmx.ch>
@ 2004-02-13 00:45 ` Bruno Wolff III <bruno@wolff.to>
1 sibling, 0 replies; 3+ messages in thread
From: Bruno Wolff III @ 2004-02-13 00:45 UTC (permalink / raw)
To: Tuan Luu <tuanluu@gmx.ch>; +Cc: pgsql-admin
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.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-02-13 00:45 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-02-09 07:59 Foreign Key Question Tuan Luu <tuanluu@gmx.ch>
2004-02-13 00:31 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2004-02-13 00:45 ` Bruno Wolff III <bruno@wolff.to>
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