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

前端 未结 13 2107
星月不相逢
星月不相逢 2020-11-27 10:47

I have a table with over million rows. I need to reset sequence and reassign id column with new values (1, 2, 3, 4... etc...). Is any easy way to do that?

相关标签:
13条回答
  • 2020-11-27 11:33

    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.

    0 讨论(0)
提交回复
热议问题