Sequence question

From: Eric E <whalesuit(at)bonbon(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Sequence question
Date: 2004-10-19 15:19:05
Message-ID: 41753069.3000406@bonbon.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I have a question about sequences. I need a field to have values
with no holes in the sequence. However, the values do not need to be in
order.

My users will draw a number or numbers from the sequence and write to
the field. Sometimes, however, these sequence numbers will be discarded
(after a transaction is complete), and thus available for use. During
the transaction, however, any drawn numbers need to be unavailable.
I would like the next user who draws a number to draw the lowest number
she can, starting with the holes in the sequence.

This continuous sequence is absolutely required by our company, as the
fact that the sequence has no holes is used to check for much more
serious problems.

So my question is:
what's the most effective way to get the next available number?

My present method is to do a query that finds the first and last number
in each of the holes, step through those holes, and then start
generating new numbers. Unfortunately, this involves doing a table scan
each time - before I generate the number, and does not produce the
transaction-safety I want.

Does anyone have any better ideas? Places I should look?

Thanks,

Eric

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Devrim GUNDUZ 2004-10-19 15:26:10 Re: code in docs gives me an error
Previous Message Tom Lane 2004-10-19 15:05:36 Re: About upper() and lower to handle multibyte char