[英]SERIAL works with NULL, GENERATED ALWAYS AS IDENTITY not
Postgres 12: Postgres 12:
CREATE TABLE l_table (
id INT generated always as identity,
w_id int NOT null references w_table(id),
primary key (w_id, id)
)PARTITION BY LIST (w_id);
CREATE table l1 PARTITION OF l_table FOR VALUES IN (1);
insert into l1 (w_id) values (1);
I'm getting:我越来越:
ERROR: null value in column "id" violates not-null constraint
If I replace INT generated always as identity
with SERIAL
it works .如果我将始终生成的 INT 替换为
SERIAL
INT generated always as identity
,它就可以工作。 This is odd as in another table the generated always as identity works with null.这很奇怪,因为在另一个表中生成的身份总是与 null 一起使用。 Using
default
as value does not work either.使用
default
作为值也不起作用。
GAAI is supposed to be the SQL standard way of replacing SERIAL, even It's the suggested one. GAAI应该是SQL替换SERIAL的标准方式,甚至是建议的方式。 What am I missing here?
我在这里想念什么?
Thanks.谢谢。
What am I missing here?
我在这里想念什么?
You're trying to insert into the partition table l1
directly, instead of the partitioned l_table
.您正在尝试直接插入分区表
l1
,而不是分区表l_table
。 This ignores the identity column on the parent table, tries to insert the default null
, and fails the non-null constraint that every identity column has.这会忽略父表上的标识列,尝试插入默认的
null
,并使每个标识列具有的非空约束失败。 If you instead do如果你改为
insert into l_table (w_id) values (1);
it will work and route the inserted row into the right partition.它将起作用并将插入的行路由到正确的分区中。
Using
default
as value does not work either.使用
default
作为值也不起作用。
Apparently it's quite hard to do that.显然,要做到这一点相当困难。 How to DEFAULT Partitioned Identity Column?
如何默认分区标识列? over at dba.SE discusses some workarounds.
在 dba.SE 上讨论了一些解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.