When delete row in postgres doesn't decrement serial pk? [duplicate]

大城市里の小女人 提交于 2020-01-06 18:08:03

问题


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?

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..

this is right?


回答1:


That's right. Read the manual about sequences.

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.



来源:https://stackoverflow.com/questions/16908432/when-delete-row-in-postgres-doesnt-decrement-serial-pk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!