我正在使用 postgres 9.5。作为应用程序初始化的一部分,我在应用程序启动时使用随机 id 在数据库中进行了一些插入。像insert into student values(1,'abc'),insert into student values(10,'xyz')。然后我开发了一些其他 API,它们以编程方式插入新行。有什么方法可以告诉 postgres 跳过已经使用的 id?
它试图占用已经使用的 ID。我注意到它没有更新序列以考虑初始插入
这是我创建表格的方式
CREATE TABLE student(
id SERIAL PRIMARY KEY,
name VARCHAR(64) NOT NULL UNIQUE
);