Re: foreign key is from different tables - what to do?

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Cyril Samovskiy <cyril_s31(at)yahoo(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: foreign key is from different tables - what to do?
Date: 2002-02-21 08:19:02
Message-ID: 1014279542.13240.115.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-novice

On Wed, 2002-02-20 at 18:23, Cyril Samovskiy wrote:
> hi. i'm rookie in postgres, so here is my question:

Therefore your question should have gone to pgsql-novice. (Reply-To set
there.)

> i have foreign key consisting of 2 fields (a and b). a is foreign key from
> table aaa, b is FK from table bbb. how to create table is that complex
> foreign key consisiting of fields from different tables?
> thank you

You seem to have two foreign keys, not one. I'm guessing that you
actually have a multi-field primary key, each field of which is a
foreign key to another table:

CREATE TABLE aaa (id INTEGER PRIMARY KEY, ...)
CREATE TABLE bbb (id INTEGER PRIMARY KEY, ...)
CREATE TABLE ccc (a INTEGER REFERENCES aaa(id),
b INTEGER REFERENCES bbb(id),
...,
PRIMARY KEY (a, b))

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C

"My sheep hear my voice, and I know them, and they
follow me; And I give unto them eternal life; and they
shall never perish, neither shall any man pluck them
out of my hand." John 10:27,28

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Turbo Fredriksson 2002-02-21 08:58:53 Error with a SQL query 'between .. and .. and'
Previous Message Samik Raychauhduri 2002-02-21 07:34:57 Re: Which newsgroup is best for PostgreSQL under Cygwin?

Browse pgsql-novice by date

  From Date Subject
Next Message Cyril Samovskiy 2002-02-21 09:39:22 Re: [HACKERS] foreign key is from different tables - what to do?
Previous Message Tuna Chatterjee 2002-02-20 22:43:55 Re: 7.2 upgrade