Re: How to create "auto-increment" field WITHOUT a sequence object?

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: How to create "auto-increment" field WITHOUT a sequence object?
Дата
Msg-id 7DA4501A-28CF-4BAD-8C14-BF950DC353F8@solfertje.student.utwente.nl
обсуждение исходный текст
Ответ на Re: How to create "auto-increment" field WITHOUT a sequence object?  (Dmitriy Igrishin <dmitigr@gmail.com>)
Ответы Re: How to create "auto-increment" field WITHOUT a sequence object?
Список pgsql-general
On 3 Jul 2011, at 16:10, Dmitriy Igrishin wrote:

> "you MUST lock on insert to get gapless sequences"
> Not me :-). The OP must do it. So, what problem here? Deadlocks?
> Again, if deadlocks are so dangerous, why the LOCK command exists?

It's not deadlocks, it's concurrent updates that are the trouble. If you don't lock, you run the risk for two records
beingassigned the same number concurrently. 

With a unique constraint added into the mix (and there should be one) that means that one of the transactions will fail
theunique constraint check on commit. 

It's possible to catch that in the client and redo the transaction with a new ID, but if that's not acceptable (for
examplebecause it matters which transaction got the ID first) then you need to lock records. 

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:737,4e109f6e12092079216178!



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

Предыдущее
От: Alban Hertroys
Дата:
Сообщение: Re: out of memory error
Следующее
От: Dmitriy Igrishin
Дата:
Сообщение: Re: How to create "auto-increment" field WITHOUT a sequence object?