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 0B73AD1B229 for ; Thu, 5 Aug 2004 03:54:51 -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 35587-05 for ; Thu, 5 Aug 2004 06:54:43 +0000 (GMT) Received: from web41808.mail.yahoo.com (web41808.mail.yahoo.com [66.218.93.142]) by svr1.postgresql.org (Postfix) with SMTP id 6F67CD1B17B for ; Thu, 5 Aug 2004 03:54:40 -0300 (ADT) Message-ID: <20040805065440.53274.qmail@web41808.mail.yahoo.com> Received: from [82.83.34.55] by web41808.mail.yahoo.com via HTTP; Wed, 04 Aug 2004 23:54:40 PDT Date: Wed, 4 Aug 2004 23:54:40 -0700 (PDT) From: Prabu Subroto Subject: Re: Sequence Question To: pgsql-general@postgresql.org In-Reply-To: <20040805041942.0D6513953@sitemail.everyone.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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/120 X-Sequence-Number: 63675 kv=# create sequence sales_salesid_seq; CREATE SEQUENCE kv=# select setval('sales_salesid_seq', (select max(salesid) from sales)+1); setval -------- 16 (1 row) kv=# alter table sales alter column salesid set default nextval('sales_serialid_ seq'); ALTER TABLE Oscar Tuscon wrote: > 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 > > ---------------------------(end of > broadcast)--------------------------- > TIP 2: you can get off all lists at once with the > unregister command > (send "unregister YourEmailAddressHere" to > majordomo@postgresql.org) > __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail