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

前端 未结 3 445
夕颜
夕颜 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:07

    If you need gapless sequences - there are ways to do it, but it's not trivial, and definitely much slower.

    Also - if you worry about "using too many ids" - just define id as bigserial.

提交回复
热议问题