PDA

View Full Version : how to reset value of a sequence?


zdeh98
02-08-02, 05:09
Good day!

How do I reset the value of a sequence without dropping the table?

Could you help me out? :)

eperich
02-08-02, 06:09
you can do this by updateing one of the system tables

It's a long time ago since I've done this.

I will look it up and post it.

But this is a very dangerous procedure to reset the sequence.

I've forgotten the easy method to reset the sequence is to pg_dumpall of your database
and then search fpr the sequence in the ascii file and you can change the setting also there
and then import your data in den dbserver and theen the sequence is changed

with this method you can change the sequence to any value you want.

BUT NOTICE THIS DANGERAOUS DEALING WITH SUCH THINGS ON A PRODUCTION SYSTEM.

eperich
02-08-02, 08:54
use \d [sequence]

and use setval to change the value of the sequence

kalman
02-13-02, 15:49
Originally posted by zdeh98
Good day!

How do I reset the value of a sequence without dropping the table?

Could you help me out? :)

Is enough:

DROP SEQUENCE sequence_name;

and after the first increment will be recreated.