Re: guaranteeing that a sequence never skips

Поиск
Список
Период
Сортировка
От Andre Maasikas
Тема Re: guaranteeing that a sequence never skips
Дата
Msg-id DBD47D010A455B46A6446A1A89D1393F6134B6@ogalik.corp.abs.ee
обсуждение исходный текст
Ответ на guaranteeing that a sequence never skips  (David Garamond <lists@zara.6.isreserved.com>)
Список pgsql-general
>Sometimes a business requirement is that a serial sequence
>never skips,
>e.g. when generating invoice/ticket/formal letter numbers. Would an
>INSERT INTO t (id, ...) VALUES (SELECT MAX(col)+1 FROM t, ...)
>suffice,
>or must I install a trigger too to do additional checking?
>

If id is defined unique it should be ok but if two of those statments
happen
to run concurrently you could get duplicate key violations and be
prepared
to retry the transaction. Savepoints in 8.0 will probably come on handy.

Of course concurrency is determined by the length of time you
insert a new value and commit. So it would help if you had all
other values/statements ready/done by the time you
insert into this table, and can do commit straight after
this statement.

Andre

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

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: current transaction is aborted, commands ignored until end of transaction block
Следующее
От: "ruben20@superguai.com"
Дата:
Сообщение: Re: current transaction is aborted, commands ignored until