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 09D5FD1B38E for ; Thu, 5 Aug 2004 01:21:43 -0300 (ADT) 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 99811-10 for ; Thu, 5 Aug 2004 04:20:47 +0000 (GMT) Received: from omta06.mta.everyone.net (sitemail3.everyone.net [216.200.145.37]) by svr1.postgresql.org (Postfix) with ESMTP id 9ACBBD1B385 for ; Thu, 5 Aug 2004 01:19:57 -0300 (ADT) Received: from sitemail.everyone.net (bigip1-snat [216.200.145.29]) by omta06.mta.everyone.net (Postfix) with ESMTP id 5ECF67B8B7 for ; Wed, 4 Aug 2004 21:19:44 -0700 (PDT) Received: by sitemail.everyone.net (Postfix, from userid 99) id 0D6513953; Wed, 4 Aug 2004 21:19:42 -0700 (PDT) Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 7bit Mime-Version: 1.0 X-Mailer: MIME-tools 5.41 (Entity 5.404) Date: Wed, 4 Aug 2004 21:19:41 -0700 (PDT) From: Oscar Tuscon To: pgsql-general@postgresql.org Subject: Sequence Question Reply-To: obtuse@bmwe30.net X-Originating-Ip: [24.107.197.126] X-Eon-Sig: AQHrDFBBEbVdAA1yZwEAAAAB,9a4e1fdb1db812602745c5a8545e4047 Message-Id: <20040805041942.0D6513953@sitemail.everyone.net> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.1 tagged_above=0.0 required=5.0 tests=NO_DNS_FOR_FROM X-Spam-Level: * X-Archive-Number: 200408/117 X-Sequence-Number: 63672 I'm looking at ways to get batches of sequence values s faster. I don't want to set cache or increment to a large number for a variety of reasons. I need to grab id's in batches of varying numbers at various times, from 1 to several thousand at once. Doing it 1 at a time works, but more time goes into it than I'd like. I tried setting cache_value high but the database roundtrips were eating more time that I wanted to see; I only saw a 25% improvement in average time. SO... is the following approach safe? That is, will this be atomic, or is there a possibility that another connection could squeeze in a select nextval() between the select nextval() and the setval below? If it's safe I'd do this and take the sequences as the new currval - #I asked for (1500 or whatever). mydb=# select setval('my_id_seq', (select nextval('my_id_seq')+1500)); Thanks Oscar _____________________________________________________________ The BMW E30 community on the web---> http://www.bmwe30.net