Referencing multiple primary keys from a single table.

From: Daniel Staal <DStaal(at)usa(dot)net>
To: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Referencing multiple primary keys from a single table.
Date: 2003-09-22 21:34:11
Message-ID: 26865494.1064248451@[192.168.1.52]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


What is the best way to reference (use as foreign key) a table with
multiple primary keys?

Here's what I have:
Table1:
field1
field2
field3
...
primary key (field1, field2, field3)

Then I have another table that needs to reference Table1 with a
foreign key. What I really want to do is:
Table2:
field1 Primary key
field2 references table1
...

But that doesn't work. I haven't yet tried the option of giving
Table2 all three fields of Table1, partly because I'm not really sure
how to write that... (I did try linking it to the implicit field
generated when I created Table1. Didn't work.) The option I'm sure
would work is shoving all three key fields of Table1 into one field,
but that's a bit messy with the data. (Though it is doable.)

Is there any really good way to do this that I'm just missing?

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author. Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes. This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Stephan Szabo 2003-09-22 22:05:50 Re: Referencing multiple primary keys from a single table.
Previous Message Bryan Irvine 2003-09-22 16:47:29 Replication