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 BDF75329EC2 for ; Tue, 19 Oct 2004 16:19:13 +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 26559-06 for ; Tue, 19 Oct 2004 15:19:12 +0000 (GMT) Received: from mail3.speakeasy.net (mail3.speakeasy.net [216.254.0.203]) by svr1.postgresql.org (Postfix) with ESMTP id B45FD329E4C for ; Tue, 19 Oct 2004 16:19:10 +0100 (BST) Received: (qmail 31361 invoked from network); 19 Oct 2004 15:18:04 -0000 Received: from static-151-201-137-153.pitt.east.verizon.net (HELO [192.168.1.108]) (eeric@[151.201.137.153]) (envelope-sender ) by mail3.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 19 Oct 2004 15:18:04 -0000 Message-ID: <41753069.3000406@bonbon.net> Date: Tue, 19 Oct 2004 11:19:05 -0400 From: Eric E User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-general@postgresql.org Subject: Sequence question Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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/900 X-Sequence-Number: 67423 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