1

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?

dsolimano
  • 8,600
  • 3
  • 47
  • 62
jean
  • 11
  • 2
  • Even if you don't delete from the table there can still be gaps in the numbering. The ID is just that - an ID. It doesn't tell you anything about the order rows were inserted or committed in, or much else really. – Craig Ringer Jun 04 '13 at 02:09

1 Answers1

4

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.

Erwin Brandstetter
  • 539,169
  • 125
  • 977
  • 1,137