尝试插入全新数据库中的全新表时,出现value "1574799549227" is out of range for type integer
错误。我在pg模块上使用了node。
db
.query(`INSERT INTO users (uuid, email, password, created_at, updated_at) VALUES ($1, $2, $3, to_timestamp($4 / 1000), to_timestamp($4 / 1000))`,
[uuid, email, password, Date.now()])
.catch((err) => {
console.log(err);
});
这是桌子
CREATE TABLE public.users
(
id serial,
uuid uuid,
email character varying,
password character varying,
created_at timestamp with time zone,
updated_at timestamp with time zone,
CONSTRAINT user_id_pk PRIMARY KEY (id)
)
我也尝试过重置ID字段的序列号
答案 0 :(得分:0)
请参阅Numeric types的官方文档。串行数据类型的范围为1到2147483647。
SERIAL列存储为INTEGER,使它们的最大值为231-1。因此,在大约20亿次插入之后,您的新id值将不再适合,因此请确保在表的生存期内插入了这么多行。
如果要更改表格,请记住使用BIGINT
而不是BIGSERIAL
。
ALTER TABLE users ALTER COLUMN id TYPE BIGINT;
最可能的原因是id
列中的值超出此范围。
答案 1 :(得分:0)
我最终弄清楚了。原来那是我的时间戳。本应使用to_timestamp($4 / 1000)
to_timestamp($4 / 1000.0)