Re: Sequences without blank holes

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: Sequences without blank holes
Дата
Msg-id Pine.LNX.4.44.0311060956080.9763-100000@peter.localdomain
обсуждение исходный текст
Ответ на Sequences without blank holes  (MaRcElO PeReIrA <gandalf_mp@yahoo.com.br>)
Список pgsql-general
MaRcElO PeReIrA writes:

> How can I assure a ''sequence WITHOUT holes''?

> $ SELECT max(prod_id)+1 FROM products;

You can do that, but

SELECT prod_id FROM products ORDER BY prod_id DESC LIMIT 1;

will be faster.  In fact, if you have a B-tree index on prod_id (which you
should), it will be nearly constant time.

Also, make sure if you do a SELECT, then some client application logic,
then an UPDATE, to do it in one transaction and use the appropriate
isolation level, locking, etc.

--
Peter Eisentraut   peter_e@gmx.net


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

Предыдущее
От: MaRcElO PeReIrA
Дата:
Сообщение: Sequences without blank holes
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: PostgreSQL v7.4 Release Candidate 1 compile errors