How to reset sequence in postgres and fill id column with new data?

If you don’t want to retain the ordering of ids, then you can

ALTER SEQUENCE seq RESTART WITH 1;
UPDATE t SET idcolumn=nextval('seq');

I doubt there’s an easy way to do that in the order of your choice without recreating the whole table.

Leave a Comment