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 0A976D1B1DF for ; Wed, 4 Aug 2004 20:20:29 -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 11808-04 for ; Wed, 4 Aug 2004 23:20:22 +0000 (GMT) Received: from omta08.mta.everyone.net (sitemail3.everyone.net [216.200.145.37]) by svr1.postgresql.org (Postfix) with ESMTP id 640CCD1B19F for ; Wed, 4 Aug 2004 20:20:16 -0300 (ADT) Received: from sitemail.everyone.net (bigip1-snat [216.200.145.29]) by omta08.mta.everyone.net (Postfix) with ESMTP id 100D44DEC0 for ; Wed, 4 Aug 2004 16:20:19 -0700 (PDT) Received: by sitemail.everyone.net (Postfix, from userid 99) id DD88F394A; Wed, 4 Aug 2004 16:20:18 -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 16:20:18 -0700 (PDT) From: Oscar Tuscon To: pgsql-general@postgresql.org Subject: Sequence question Reply-To: obtuse@bmwe30.net X-Originating-Ip: [192.94.149.1] X-Eon-Sig: AQHrDFBBEW8yAAwiwAEAAAAB,e7fabab2629a6380b11e32d29948f4b2 Message-Id: <20040804232018.DD88F394A@sitemail.everyone.net> 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: 200408/182 X-Sequence-Number: 63737 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 T _____________________________________________________________ The BMW E30 community on the web---> http://www.bmwe30.net