Reset auto increment counter in postgres
Solution 1:
If you created the table product
with an id
column, then the sequence is not simply called product
, but rather product_id_seq
(that is, ${table}_${column}_seq
).
This is the ALTER SEQUENCE
command you need:
ALTER SEQUENCE product_id_seq RESTART WITH 1453
You can see the sequences in your database using the \ds
command in psql. If you do \d product
and look at the default constraint for your column, the nextval(...)
call will specify the sequence name too.
Solution 2:
The following command does this automatically for you: This will also delete all the data in the table. So be careful.
TRUNCATE TABLE someTable RESTART IDENTITY;
Solution 3:
Here is the command that you are looking for, assuming your sequence for the product table is product_id_seq:
ALTER SEQUENCE product_id_seq RESTART WITH 1453;