我正在尝试创建以 Bigserial 数据类型作为主键的 Postgres 表。创建表后,表定义将更改为 bigint NOT NULL DEFAULT nextval('transactions.transaction_id_seq'::regclass),
。请告诉我为什么会这样?
提前致谢, 桑纳特
最佳答案
如 the documentation 中所述,序列不是“真正的”数据类型,而是方便的包装器。如果你创建一个序列列,你会自动得到
- 一个新序列('tablename_columnname_seq`)
- 一个适当类型的整数列,它从序列中获取默认值。
- 列的设置以使用序列。
引用:
The data types smallserial, serial and bigserial are not true types, but merely a notational convenience for creating unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases).
CREATE TABLE table (BIGSERIAL id PRIMARY KEY);
与
相同CREATE SEQUENCE table_id_seq;
CREATE TABLE table (
id bigint NOT NULL DEFAULT nextval('table_id_seq')
);
ALTER SEQUENCE table_id_seq OWNED BY table.id;
与您得到的匹配。
关于java - Postgres Bigserial 数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43689254/