Reputation: 688
I did create a table in PostgreSQL, with a column id serial Primary Key. Looking at the properties of the column in pgAdmin I can see:
Datatype: Integer
Default: nextval('items_id_seq'::regclass)
(So if I'm not mistaking i did create it using the 'serial' key-word.)
Now in my backend-code I'm using the method: jpaRepository.deleteAllInBatch(), which 'truncates' my whole table.
When after this call I do add records to the table again, i can see that the id of the following record continues from the id of the last record I had in the table.
Is there a way to reinitialize the id-serial when doing the jpaRepository.deleteAllInBatch() so that records begin with id = 0 again?
Upvotes: 0
Views: 2032
Reputation: 231
This may help you
ALTER SEQUENCE seq RESTART WITH 1;
UPDATE t SET idcolumn=nextval('seq');
For more detail
How to reset sequence in postgres and fill id column with new data?
Upvotes: 1