postgresql - integer out of range

后端 未结 1 515
一整个雨季
一整个雨季 2021-02-03 22:19

Not the slightest idea why the hell this is happening..

I\'ve set up a table accordingly:

CREATE TABLE raw (
    id          SERIAL,
    regtime     floa         


        
相关标签:
1条回答
  • 2021-02-03 22:59

    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.

    If you expect this many inserts over the life of your table, create it with a BIGSERIAL (internally a BIGINT, with a maximum of 263-1).

    If you discover later on that a SERIAL isn't big enough, you can increase the size of an existing field with:

    ALTER TABLE raw ALTER COLUMN id TYPE BIGINT;
    

    Note that it's BIGINT here, rather than BIGSERIAL (as serials aren't real types). And keep in mind that, if you actually have 2 billion records in your table, this might take a little while...

    0 讨论(0)
提交回复
热议问题