当在postgres中删除行时不减少串行pk吗? [英] When delete row in postgres doesn't decrement serial pk?

查看:85
本文介绍了当在postgres中删除行时不减少串行pk吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Postgres的新手. 如果在sqlserver中,我们有一个具有自动增量的表,并且有10行...而最后一行的id为10. 删除最后一行时,插入的下一行也将获得id = 10 ...确定吗?

i'm new to postgres. if in sqlserver we have a table with auto-increment, and 10 rows... and the last row have id = 10. when you delete the last row, the next you insert will get the id = 10 too... sure?

但是在postgres中,使用bigserial作为pk,当我删除具有最大ID的行并插入新行时,它会不断增加pk数.

but in postgres, using bigserial as pk, when i delete the row with the max Id, and insert a new row, it keeps incrementing more and more the pk number..

这是对的吗?

推荐答案

是的. 阅读有关序列的手册.

bigserialserial 只是在创建bigint/integer列(默认设置为 nextval() 来自连接的序列.

bigserial and serial are just notational convenience for creating a bigint / integer column with the default set to nextval() from a connected sequence.

为了安全并发使用,必须采用这种方式.

And it needs to be that way for safe concurrent use.

这篇关于当在postgres中删除行时不减少串行pk吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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