0

I am getting a value "1574799549227" is out of range for type integer error when trying to insert into a brand new table on a brand new database. I am using node with the pg module.

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);
});

This is the table

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)
)

I have also tried reseting the sequence number for the id field

4
  • Use bigserial or bigint instead of serial or uuid Commented Nov 26, 2019 at 20:42
  • @nacho I have switched it to bigserial, it doesn't fix the issue. It also shouldn't be an issue as the database and table are brand new.. Commented Nov 26, 2019 at 20:44
  • What value do you have at $1?? Commented Nov 27, 2019 at 7:32
  • Related: stackoverflow.com/questions/24308239/… Commented Dec 24, 2024 at 11:17

2 Answers 2

2

I ended up figuring it out. Turns out that it was the timestamps I had. I was using to_timestamp($4 / 1000) when I should of been using to_timestamp($4 / 1000.0)

Sign up to request clarification or add additional context in comments.

Comments

1

Please see the official documentation for Numeric types. Serial datatype has a range of 1 to 2147483647.

SERIAL columns are stored as INTEGERs, giving them a maximum value of 231-1. So after ~2 billion inserts, your new id values will no longer fit therefore please ensure that you are inserting that many rows during the lifetime of the table.

If you are altering table, please remember to use BIGINT rather than BIGSERIAL.

ALTER TABLE users ALTER COLUMN id TYPE BIGINT;

Most likely cause is that the value in id column is out of this range.

3 Comments

Maybe I didnt express it clearly. The table is new, there is no data in it already. Id is serial so it auto increments so theoretically it should be at 1
Have you tried recreating the table with col id as BIGSERIAL or altering the table to change the id col to BIGINT?
Yes, as I explained to nacho above. I have tried switching them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.