Why is the serial primary key incrementing despite a using "On Conflict Do Nothing?
11
votes
2
answers
9523
views
I have the below table in PostgreSQL 13:
### table name: newtable
field type
----- ----
Seq bigserial
code varchar
Seq
is the primary key (auto-increment)
Code
is a unique key index
Insert Into newtable (Code) Values ('001') On Conflict(Code) Do Nothing --> Seq value is 1
Insert Into newtable (Code) Values ('001') On Conflict(Code) Do Nothing
Insert Into newtable (Code) Values ('001') On Conflict(Code) Do Nothing
Insert Into newtable (Code) Values ('002') On Conflict(Code) Do Nothing --> Seq value is 4
Why is Seq 4? Is there any way to increase value on successful inserts only?
Asked by Don2
(559 rep)
Jul 7, 2021, 09:25 AM
Last activity: Jan 18, 2024, 07:45 AM
Last activity: Jan 18, 2024, 07:45 AM