FOREIGN KEY composite_type.its_field REFERENCES ....

Started by Belka Lambdaabout 16 years ago2 messagesgeneral
Jump to latest
#1Belka Lambda
lambda-belka@yandex.ru

Hi everyone!

Is there a way to construct FOREIGN KEYs from parts of composite-typed field?

The code returns an error:
-----------------------------------------
create table aaa (
a_id integer primary key,
a_str varchar)
;
create type content_of_bbb (a_id integer, b_str varchar);

create table bbb (
b_id integer primary key,
bbb_content content_of_bbb,
foreign key (bbb_content.a_id) references aaa(a_id)
);
-----------------------------------------
, so I suspect it's impossible. Is it?

Belka

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Belka Lambda (#1)
Re: FOREIGN KEY composite_type.its_field REFERENCES ....

Belka Lambda <lambda-belka@yandex.ru> writes:

Is there a way to construct FOREIGN KEYs from parts of composite-typed field?

No, and even if the system let you do it, the performance would probably
suck. Composite-type fields are not something to be used with abandon.
To me your example looks like a design pattern to avoid.

regards, tom lane