Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing minvalue of Postgres's sequence

I am trying to change minimum value of an existing sequence.

First I tried

ALTER SEQUENCE product_id_seq MINVALUE 10000;

and I got ERROR: START value (1) cannot be less than MINVALUE (10000).

So I tried

ALTER SEQUENCE product_id_seq MINVALUE 10000 RESTART WITH 10000;

but got the same error.

Of course I could just drop it and create a new one, but I think there should be a way to do this. I am using Postgres 8.4.7.

like image 562
dasony Avatar asked Jan 26 '26 15:01

dasony


1 Answers

How about setting them all at once:

ALTER SEQUENCE product_id_seq
MINVALUE 10000
START 10000
RESTART 10000;

That should change the minimum, starting, and current values all to 10000 and thus make everything consistent.

like image 100
mu is too short Avatar answered Jan 29 '26 04:01

mu is too short



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!