Re: Sequences without blank holes - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: Sequences without blank holes
Date
Msg-id Pine.LNX.4.44.0311060956080.9763-100000@peter.localdomain
Whole thread Raw
In response to Sequences without blank holes  (MaRcElO PeReIrA <gandalf_mp@yahoo.com.br>)
List 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 by date:

Previous
From: MaRcElO PeReIrA
Date:
Subject: Sequences without blank holes
Next
From: Peter Eisentraut
Date:
Subject: Re: PostgreSQL v7.4 Release Candidate 1 compile errors