我使用的是PostgreSQL 11最新版本,在继承表的PK身份方面存在问题。
假设您有一个简单的父表,例如:
CREATE TABLE test7
(
id_t7 int GENERATED always AS IDENTITY PRIMARY KEY,
folio int GENERATED always AS IDENTITY,
client int
);
具有任何继承的表,例如:
CREATE TABLE test7_detail1
(
-- uuid uuid DEFAULT uuid_generate_v4(), <-- fiddle doesn't support it
in_process boolean,
id_corte integer,
ts_captura timestamp(6) without time zone DEFAULT (now())::timestamp without time zone
) INHERITS (test7);
如果我尝试像这样插入:
insert into test7_detail1 (client,in_process, id_corte)
values (20797,'t',101)
它返回:
ERROR: null value in column "id_t7" violates not-null constraint
DETAIL: Failing row contains (null, null, 20797, t, 101, 2019-05-03 22:27:54.823894).
here是小提琴
我做错了什么?
是虫子吗?
答案 0 :(得分:0)
我尝试使用id_t7 serial PRIMARY KEY
而不是id_t7 int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
,但似乎可以正常工作。
CREATE TABLE test7 (
id_t7 serial PRIMARY KEY,
folio serial,
client int
);
CREATE TABLE test7_detail1 (
-- uuid uuid DEFAULT uuid_generate_v4(),
in_process boolean,
id_corte integer,
ts_captura timestamp(6) without time zone DEFAULT (now())::timestamp without time zone
) INHERITS (test7);
insert into test7_detail1 (client,in_process, id_corte)
values (20797,'t',101);
答案 1 :(得分:0)