X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3BCE332A2DA for ; Tue, 19 Oct 2004 00:20:20 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64795-08 for ; Mon, 18 Oct 2004 23:20:08 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 385CE32A20D for ; Tue, 19 Oct 2004 00:20:10 +0100 (BST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i9INK7J7067893 for ; Mon, 18 Oct 2004 23:20:07 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i9INFgN8066844 for pgsql-general@postgresql.org; Mon, 18 Oct 2004 23:15:42 GMT Date: Mon, 18 Oct 2004 19:16:46 -0400 From: Eric E User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 X-Newsgroups: comp.databases.postgresql.general Subject: Sequence question Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <3sydnUgMwqQ80-ncRVn-uA@speakeasy.net> Lines: 29 X-Complaints-To: abuse@speakeasy.net X-DMCA-Complaints-To: abuse@speakeasy.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.20 To: pgsql-general@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/897 X-Sequence-Number: 67420 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