BUG #14126: INSERT ON CONFLICT DO NOTHING auto increments serial primary key when no insert happens. - Mailing list pgsql-bugs

From cwire4@gmail.com
Subject BUG #14126: INSERT ON CONFLICT DO NOTHING auto increments serial primary key when no insert happens.
Date
Msg-id 20160506065528.2693.64808@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #14126: INSERT ON CONFLICT DO NOTHING auto increments serial primary key when no insert happens.
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      14126
Logged by:          Casey Wireman
Email address:      cwire4@gmail.com
PostgreSQL version: 9.5.2
Operating system:   Windows 7
Description:

It's unclear to me if this is desired behavior or not, but when doing the
following:

insert into table(column) values (value) on conflict DO NOTHING

the first time a new entry is inserted it works as expected and
autoincrements the serial primary key as normal, however if I try to insert
this again the on conflict correctly detects that the value already exists,
but internally seems to autoincrement the serial key as many times as you
try to do the failed insert since on the next insert of a new value the key
value is

(previous successful key value + number of failed inserts)

It seems to me that intuitively the key should only increment on a
successful insert, not just an insert statement being executed.  For one,
this unnecessarily reduces the keyspace available for the column.

pgsql-bugs by date:

Previous
From: Marco Giraldo
Date:
Subject: R: BUG #14121: Constraint UNIQUE
Next
From: Francisco Olarte
Date:
Subject: Re: BUG #14126: INSERT ON CONFLICT DO NOTHING auto increments serial primary key when no insert happens.