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)
Список
Дерево обсуждения
About sequences that works BAD !!!! "Alexis Palma Espinosa" <apalma@uci.cu>
Re: About sequences that works BAD !!!! Terry Lee Tucker <terry@esc1.com>
Re: About sequences that works BAD !!!! Richard Huxton <dev@archonet.com>
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
Дата:
От: Terry Lee Tucker
Дата:
FAQ