postgres如何重置或更新表的索引(序列) [英] postgres how to reset or update index(sequence) of table

查看:1472
本文介绍了postgres如何重置或更新表的索引(序列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我删除了表中的2000行,然后插入了相同的2000条记录,但是它们的索引(id自动增量字段)从2001年开始,
现在我想将那些索引2001-4000更新为1-2000

i deleted 2000 row in my table and then i inserted same 2000 records but their index(id auto increment field) starting from 2001, now i want to update those index 2001 - 4000 to 1-2000

推荐答案

要更新您的ID,请运行以下命令。

To update your id run the following command.

UPDATE table SET id = id-2000;

这将更新表中记录的ID,然后您需要更新表的顺序

This will update the id of records in your table and then you need update the table's sequence

ALTER SEQUENCE table_id_seq从2001开始;

这将允许您插入ID为 2001

This will allow you to insert the data with the id 2001

另一种方法是,删除表中的所有记录并更新序列

Another way, delete all the records from the table and update the sequence of the table and reinsert the data.

希望这会有所帮助。

这篇关于postgres如何重置或更新表的索引(序列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆