Postgres添加身份导致ERROR START值(0)不能小于MINVALUE(1)

Postgres add identity results in ERROR START value (0) cannot be less than MINVALUE (1)

尝试 运行 这是因为我希望自动生成的 ID 从 0

开始
alter table gender
alter column gender_id ADD GENERATED ALWAYS AS IDENTITY (START WITH 0 INCREMENT BY 1)

出现错误: START value (0) cannot be less than MINVALUE (1)

我还不擅长 PostgreSQL,所以不确定如何让它从 0 开始递增。

所有标识列在后端创建一个序列。在您的身份列的 sequence_option 中,您没有提供 MINVALUE,这就是为什么默认情况下它将 MINVALUE 视为 1。所以你必须明确定义 MINVALUE 如下:

ALTER TABLE gender
ALTER COLUMN gender_id ADD GENERATED ALWAYS AS IDENTITY (MINVALUE  0 START WITH 0 INCREMENT BY 1)