有没有办法将复合类型列的子列设置为外键?
我试过的是:
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)
);
但它不起作用。
答案 0 :(得分:1)
这项工作对我来说
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)
);
我删除了references
行,因此使用type
有效。
的 SQL Fiddle DEMO 强>
如果您需要外键,请尝试以下代码:
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)
);
<强> SQL Fiddle DEMO 强>