Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart id counting on a table in PostgreSQL after deleting some previous data?

I'm using PostgreSQL database on Rails 2.3.8 and I need to restart auto increment ID on my table. How can I do that?

like image 666
SL_User Avatar asked Sep 30 '11 05:09

SL_User


1 Answers

If you truncate the table you can use the RESTART IDENTITY clause on the end.

Example:

TRUNCATE TABLE foo RESTART IDENTITY;

TRUNCATE DOCUMENTATION

like image 172
Ketema Avatar answered Oct 03 '22 13:10

Ketema