is there a way to avoid calling nextval() if the insert fails in PostgreSQL?

前端 未结 3 479
夕颜
夕颜 2021-01-12 05:20

In a PostgreSQL database I have a table with a primary key and another field which needs to be unique.

  CREATE TABLE users (
    id      INTEGER PRIMARY KEY         


        
3条回答
  •  灰色年华
    2021-01-12 06:01

    I don't think so: a basic feature of sequences is that gaps are possible (think of two concurrent transactions, with one performing a ROLLBACK). You should ignore gaps. Why are they a problem in your case?

提交回复
热议问题