Resetting PostgreSQL Sequence

Published on February 21, 2015 by

Okay folks, this is going to be a short one! Sometimes you may want to reset a PostgreSQL sequence, for instance after removing data from a tabel. You can do this very easily by executing the following statement:

ALTER SEQUENCE company_id_seq RESTART WITH 1;

company_id_seq is the name of the sequence that you want to reset, and 1 is the value that you want the sequence to start at.

That is all there is to it. Happy coding!

Author avatar
Bo Andersen

About the Author

I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!

Leave a Reply

Your e-mail address will not be published.