java - Postgres Bigserial 数据类型

标签 java postgresql bigint

我正在尝试创建以 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/

相关文章:

node.js - 用大整数 Sequelize js

javascript - 为什么 `+0n` 会抛出错误,而 `-0n` 不会?

java - 从 GCMBaseIntentService 调用异步任务?

java - 我应该使用什么来代替已弃用的 Date.getHours()

postgresql - utf8 字符集中 Postgres Ltree 标签中的有效字符

pointers - Go中的BigInt指针

java - 将 ArrayList 转换为对象数组

java - 从 Tomcat 项目创建 java 安装程序 (war)

postgresql - 如何更改postgres中的列类型

performance - 无法写入散列连接临时文件 : No space left on device