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

前端 未结 13 2196
星月不相逢
星月不相逢 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:20

    Reset the sequence:

    SELECT setval('sequence_name', 0);
    

    Updating current records:

    UPDATE foo SET id = DEFAULT;
    

提交回复
热议问题