Prof. Falken
Prof. Falken

Reputation: 549

PostgreSQL: Set MAX Value for Sequence to a Higher Value

Currently I am importing data from a RabbitMQ worker to a table in postgreSQL. In doing so I received this error:

4|tiq-work | error: nextval: reached maximum value of sequence "table_id_seq" (2147483647)

table.id has a data type of int8 (bigint) which has a range of 9223372036854775807

I tried to set the max value using this command from the postgreSQL documentation:

alter sequence schema.table_id_seq maxvalue 9223372036854775807;

But then receive this error:

SQL Error [22023]: ERROR: MAXVALUE (9223372036854775807) is out of range for sequence data type

This appears to be because the range for sequence data type is the same as the integer data type (2147483647).

Is there a way to force this to go higher? I still have a lot of data to load.

Upvotes: 12

Views: 14668

Answers (1)

Marcel
Marcel

Reputation: 1280

You also need to convert the sequence to a bigint. Try this:

ALTER SEQUENCE "table_id_seq" AS bigint MAXVALUE 9223372036854775807;

Upvotes: 16

Related Questions