PostgreSQL中复合类型列子列的外键约束

PostgreSQL中复合类型列子列的外键约束,sql,postgresql,foreign-keys,composite-types,Sql,Postgresql,Foreign Keys,Composite Types,有没有办法将复合类型列的子列设置为外键 我尝试的是: Create Type info_typ_ AS ( category integer , title text , actor text , price double precision ); Create Table Products_typobj ( prod_id integer, info info_typ_, primary key(prod_id), Category references Categories

有没有办法将复合类型列的子列设置为外键

我尝试的是:

Create Type info_typ_ AS (
  category integer ,
  title text ,
  actor text ,
  price double precision );

Create Table Products_typobj (
prod_id integer,
info info_typ_,
primary key(prod_id),
Category references Categories(Category)
);
但它不起作用。

这对我来说很有效

Create Type info_typ_ AS (
  category integer ,
  title text ,
  actor text ,
  price double precision );

Create Table Products_typobj (
prod_id integer,
info info_typ_,
primary key(prod_id)
);
我删除了带有
引用的行
,所以使用
类型
是可行的。

如果需要外键,请尝试以下代码:

Create Type info_typ_ AS (
  category integer ,
  title text ,
  actor text ,
  price double precision );

Create Table Categories (
  Category int,
  primary key(Category)
);  

Create Table Products_typobj (
prod_id integer,
info info_typ_,
Category int references Categories(Category),  
primary key(prod_id),
FOREIGN KEY (Category) REFERENCES Categories (Category)
);

类别
将同时位于
信息类型
类别
?信息类型中不需要类别。这实际上是一种替代表设计的解决方案。在外键中引用复合类型的元素在AFAIC中是不可能的。