Я использую пользовательский тип для первичного ключа в такой таблице
create type t_id as (
a int,
b int
);
create table test1 (
id int primary key
);
create table test2 (
id t_id primary key
);
insert into test1 values (1);
insert into test2 values ((1, 1)::t_id);
insert into test2 values ((1, 2)::t_id);
insert into test2 values ((2, 1)::t_id);
Я могу выбрать поля пользовательского типа согласно
select (id).a, b(id) from test2;
Однако я не могу добавить внешний ключ в поле пользовательского типа.
alter table test2 add constraint fk_test2 foreign key (a(id)) references test1 (id);
При попытке получить следующую ошибку:
ERROR: syntax error at or near "("
LINE 1: ...table test2 add constraint fk_test2 foreign key (a(id)) refe...
Есть ли способ достичь этого в PostgreSQL?