0

我已经定义了我的表:

create table device (
id serial primary key,
manufacturerid integer references manufacturer(id) on delete restrict,
model text,
price real,
usagepros text,
usagecons text
);

create table robot (
numaxes integer,
capacity real,
reach real,
accuracy real,
installmethodid integer references installmethod(id) on delete restrict,
mass real
) inherits (device);

create table robotComplex(
id serial primary key,
name text
);

create table robotComplexDevice(
id serial primary key,
deviceId integer references device(id) on delete restrict,
robotcomplexid integer references robotcomplex(id) on delete cascade
);

etc...

运行 sql 命令时,我得到以下信息:

 id  | manufacturerid | model | price | usagepros | usagecons | numaxes | capacity | reach | accuracy | installmethodid | mass  
-----+----------------+-------+-------+-----------+-----------+---------+----------+-------+----------+-----------------+-------
 159 |            117 | Robot | 100.3 | OK        | NoOK      |       6 |     15.3 |  15.4 |  76.1234 |              45 | 100.1

> select * from device; 
 id  | manufacturerid | model | price | usagepros | usagecons 
-----+----------------+-------+-------+-----------+-----------
 159 |            117 | Robot | 100.3 | OK        | NoOK

> select * from robotcomplex;
 id |     name     
----+--------------
 27 | Complex


> insert into robotcomplexdevice (deviceid, robotcomplexid) values (159, 27);
ERROR:  insert or update on table "robotcomplexdevice" violates foreign key constraint        "robotcomplexdevice_deviceid_fkey"
DETAIL:  Key (deviceid)=(159) is not present in table "device".

出于某种原因,即使我已经定义了“机器人”表来继承“设备”表,我也无法引用它。也许我没有正确获得对象关系数据库模型。但是,如果您不能引用这些表,那么对象关系模型的意义何在?

4

1 回答 1

2

这是记录在案的行为:

http://www.postgresql.org/docs/current/static/ddl-inherit.html#DDL-INHERIT-CAVEATS

于 2012-04-06T16:52:15.587 回答