hi. i'm rookie in postgres, so here is my question:
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

-------------------
Best regards,
Cyril Samovskiy
cyril_s31@yahoo.com
cyril@somiconline.org




Wed, 20 Feb 2002 20:23:27 +0200
"Cyril Samovskiy" <cyril_s31@yahoo.com>
foreign key is from different tables - what to do?
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.Elphick@lfix.co.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 


21 Feb 2002 08:19:02 +0000
Oliver Elphick <olly@lfix.co.uk>
Re: foreign key is from different tables - what to do?
>> hi. i'm rookie in postgres, so here is my question:

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

oh, i'm sorry i didn't know that

>> 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

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

no my primary key is only one field, another one. actually i found how
to make multi-FK from different tables using ALTER TABLE stuff.
anyway thanks a lot for your support
and sorry again for disturbing you
bye


-------------------
Best regards,
Cyril Samovskiy
cyril_s31@yahoo.com
cyril@somiconline.org



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Thu, 21 Feb 2002 11:39:22 +0200
Cyril Samovskiy <cyril_s31@yahoo.com>
Re: [HACKERS] foreign key is from different tables - what to do?
You have to create 2 foreign keys

alter table YourTable
ALTER TABLE "YourTable" ADD CONSTRAINT "my_a_fk" FOREIGN KEY (a) REFERENCES
aaa(a) MATCH FULL;
ALTER TABLE "YourTable" ADD CONSTRAINT "my_b_fk" FOREIGN KEY (b) REFERENCES
bbb(b) MATCH FULL;

Hope this Helps

http://www.pgexplorer.com
Postgres GUI tool



----- Original Message -----
From: "Cyril Samovskiy" <cyril_s31@yahoo.com>
To: "Oliver Elphick" <pgsql-novice@postgresql.org>
Sent: Thursday, February 21, 2002 11:39 AM
Subject: Re: [NOVICE] [HACKERS] foreign key is from different tables - what
to do?


> >> hi. i'm rookie in postgres, so here is my question:
>
> OE> Therefore your question should have gone to pgsql-novice.  (Reply-To
set
> OE> there.)
>
> oh, i'm sorry i didn't know that
>
> >> 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
>
> OE> You seem to have two foreign keys, not one.  I'm guessing that you
> OE> actually have a multi-field primary key, each field of which is a
> OE> foreign key to another table:
>
> no my primary key is only one field, another one. actually i found how
> to make multi-FK from different tables using ALTER TABLE stuff.
> anyway thanks a lot for your support
> and sorry again for disturbing you
> bye
>
>
> -------------------
> Best regards,
> Cyril Samovskiy
> cyril_s31@yahoo.com
> cyril@somiconline.org
>
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)


Thu, 21 Feb 2002 22:40:10 +0200
"PG Explorer" <pgmail@pgexplorer.com>
Re: [HACKERS] foreign key is from different tables - what to do?