首页 > 解决方案 > Postgres 整数超出范围

问题描述

value "1574799549227" is out of range for type integer尝试插入全新数据库上的全新表时出现错误。我正在使用带有 pg 模块的节点。

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 字段的序列号

标签: sqlnode.jsdatabasepostgresql

解决方案


我最终弄清楚了。原来这是我拥有的时间戳。我在to_timestamp($4 / 1000)应该使用的时候使用to_timestamp($4 / 1000.0)


推荐阅读