Re: About sequences that works BAD !!!!

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: About sequences that works BAD !!!!
Дата
Msg-id 44905556.2060506@archonet.com
обсуждение исходный текст
Ответ на About sequences that works BAD !!!!  ("Alexis Palma Espinosa" <apalma@uci.cu>)
Список pgsql-sql
Alexis Palma Espinosa wrote:
> Hello everyone:
>
>
>
> We are working with serials fields and we found a problem with then:
> When we insert in a table that has e unique restrict, and this makes
> insert fails, the sequence increments anyway...¿What we can do about
> it?

Nothing. The whole point of sequences is that they don't lock. They *do*
guarantee unique numbers, but they *do not* guarantee no gaps.

If you really want a series of ID numbers with no gaps you'll want to do
something like:

1. Begin transaction
2. Lock table exclusively
3. Find highest existing ID (...ORDER BY id DESC LIMIT 1)
4. Add one to it
5. Store new row.
6. commit transaction, freeing the lock

--   Richard Huxton  Archonet Ltd



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

Предыдущее
От: "Alexis Palma Espinosa"
Дата:
Сообщение: About sequences that works BAD !!!!
Следующее
От: Terry Lee Tucker
Дата:
Сообщение: Re: About sequences that works BAD !!!!