postgresql generate sequence with no gap

前端 未结 4 756
失恋的感觉
失恋的感觉 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 16:10

    You could create a sequence with no cache , then get the next value from the sequence and use that as your counter.

    CREATE SEQUENCE invoice_serial_seq START 101 CACHE 1;
    SELECT nextval('invoice_serial_seq');
    

    More info here

提交回复
热议问题