postgresql generate sequence with no gap

前端 未结 4 746
失恋的感觉
失恋的感觉 2020-11-28 15:37

I must / have to create unique ID for invoices. I have a table id and another column for this unique number. I use serialization isolation level. Using

  var         


        
4条回答
  •  爱一瞬间的悲伤
    2020-11-28 15:53

    You either lock the table to inserts, and/or need to have retry code. There's no other option available. If you stop to think about what can happen with:

    1. parallel processes rolling back
    2. locks timing out

    you'll see why.

提交回复
热议问题