pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15935: Auto increment column changes on error while inserting (violating unique constraint)
2+ messages / 2 participants
[nested] [flat]

* BUG #15935: Auto increment column changes on error while inserting (violating unique constraint)
@ 2019-07-31 11:30 PG Bug reporting form <noreply@postgresql.org>
  2019-07-31 13:36 ` RE: BUG #15935: Auto increment column changes on error while inserting (violating unique constraint) David Raymond <David.Raymond@tomtom.com>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2019-07-31 11:30 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: muhammadalinazarov@gmail.com

The following bug has been logged on the website:

Bug reference:      15935
Logged by:          Muhammadali Nazarov
Email address:      muhammadalinazarov@gmail.com
PostgreSQL version: 11.1
Operating system:   Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-96-generic x86
Description:        

I have seen one interesting behavior.
Let me show on example.

create table tmp (
id serial,
user_id int unique not null);

insert into tmp(user_id)
select 1;

our id => 1, autoincrement value 2;
insert into tmp(user_id)
select 1;

violating unique constraint, autoincrement value 3;
insert into tmp(user_id)
select 2;

select id, user_id
from tmp;
id | user_id 
----+---------
  1 |       1
  3 |       2

Is this a bug or no?
Thank you for your attention.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* RE: BUG #15935: Auto increment column changes on error while inserting (violating unique constraint)
  2019-07-31 11:30 BUG #15935: Auto increment column changes on error while inserting (violating unique constraint) PG Bug reporting form <noreply@postgresql.org>
@ 2019-07-31 13:36 ` David Raymond <David.Raymond@tomtom.com>
  0 siblings, 0 replies; 2+ messages in thread

From: David Raymond @ 2019-07-31 13:36 UTC (permalink / raw)
  To: muhammadalinazarov@gmail.com <muhammadalinazarov@gmail.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

That's expected. You can see the note here:
https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL


Note

Because smallserial, serial and bigserial are implemented using sequences, there may be "holes" or gaps in the sequence of values which appears in the column, even if no rows are ever deleted. A value allocated from the sequence is still "used up" even if a row containing that value is never successfully inserted into the table column. This may happen, for example, if the inserting transaction rolls back. See nextval() in Section 9.16 for details.



-----Original Message-----
From: PG Bug reporting form <noreply@postgresql.org> 
Sent: Wednesday, July 31, 2019 7:30 AM
To: pgsql-bugs@lists.postgresql.org
Cc: muhammadalinazarov@gmail.com
Subject: BUG #15935: Auto increment column changes on error while inserting (violating unique constraint)

The following bug has been logged on the website:

Bug reference:      15935
Logged by:          Muhammadali Nazarov
Email address:      muhammadalinazarov@gmail.com
PostgreSQL version: 11.1
Operating system:   Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-96-generic x86
Description:        

I have seen one interesting behavior.
Let me show on example.

create table tmp (
id serial,
user_id int unique not null);

insert into tmp(user_id)
select 1;

our id => 1, autoincrement value 2;
insert into tmp(user_id)
select 1;

violating unique constraint, autoincrement value 3;
insert into tmp(user_id)
select 2;

select id, user_id
from tmp;
id | user_id 
----+---------
  1 |       1
  3 |       2

Is this a bug or no?
Thank you for your attention.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2019-07-31 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-31 11:30 BUG #15935: Auto increment column changes on error while inserting (violating unique constraint) PG Bug reporting form <noreply@postgresql.org>
2019-07-31 13:36 ` David Raymond <David.Raymond@tomtom.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox