gpt4 book ai didi

postgresql - 身份不适用于继承表

转载 作者:行者123 更新时间:2023-12-05 06:26:35 24 4
gpt4 key购买 nike

我正在使用 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是 fiddle

我做错了什么?
是bug吗?

最佳答案

我尝试了 id_t7 serial PRIMARY KEY 而不是 id_t7 int GENERATED BY 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);

关于postgresql - 身份不适用于继承表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55979456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com