serial increments on failed insert

Поиск
Список
Период
Сортировка
От David Kammer
Тема serial increments on failed insert
Дата
Msg-id 41E86A6F.7010104@u.washington.edu
обсуждение исходный текст
Ответы Re: serial increments on failed insert  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: serial increments on failed insert  (Steve Atkins <steve@blighty.com>)
Re: serial increments on failed insert  (Michael Fuhr <mike@fuhr.org>)
Список pgsql-general
I've noticed what seems to be an odd effect in psql 7.3.  It works like
this:

1> Create a table:
CREATE TABLE foo
(
  sval serial,
  uval int UNIQUE
);

2> Run 3 inserts, the second of which fails because it fails the
   unique constraint:
INSERT INTO foo VALUES (DEFAULT,1);
INSERT INTO foo VALUES (DEFAULT,1);   <--- This fails
INSERT INTO foo VALUES (DEFAULT,2);

3> look at the table:
SELECT * FROM foo;
sval | uval
------+------
   1 |    1
   3 |    2   <--- look here
(2 rows)

Notice that even though the second insert failed, it still incremented
the serial value.  This seems counter intuative to the way that serial
should work.  Is this truly a bug, or is there a good work around?

Thanks,
Dave

В списке pgsql-general по дате отправления:

Предыдущее
От: "Jim C. Nasby"
Дата:
Сообщение: Re: OID Usage
Следующее
От: Tom Lane
Дата:
Сообщение: Re: serial increments on failed insert