-1

If two clients simultaneously insert into a table that has a unique sequenced column, can one client get a unique_violation? In other words, can both clients get the same result from calling nextval() ?

I did a quick google search, but couldn't find anything.

ryanrhee
  • 2,550
  • 4
  • 23
  • 25
  • https://stackoverflow.com/questions/12481448/currval-has-not-yet-been-defined-this-session-how-to-get-multi-session-sequence – MUY Belgium Dec 06 '17 at 10:31

1 Answers1

4

As is covered in detail in the PostgreSQL documentation for sequences:

no two nextval calls on the same sequence may ever return the same value, even in concurrent transactions. In other words two separate nextval calls for the same sequence can never return the same value. This results in some other anomalies, like "holes" in the sequence values appearing where a transaction rolls back, which are again described in the documentation.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • @IgorRomanchenko While well-intentioned that correction made the statement incorrect. I wrote it poorly and used a somewhat odd construction ("No two ... may ever"). You changed it to "No two ... may never" which doesn't make sense and is a double negative that could even be read as saying that they *can* get the same ID. The correct version would be "Two ... may never". – Craig Ringer Feb 24 '13 at 23:36