Thread: FOREIGN KEY composite_type.its_field REFERENCES ....

FOREIGN KEY composite_type.its_field REFERENCES ....

From
Belka Lambda
Date:
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

Re: FOREIGN KEY composite_type.its_field REFERENCES ....

From
Tom Lane
Date:
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