Sequence question

From: Oscar Tuscon <obtuse(at)bmwe30(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Sequence question
Date: 2004-08-04 23:20:18
Message-ID: 20040804232018.DD88F394A@sitemail.everyone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Browse pgsql-general by date

  From Date Subject
Next Message Mark Harrison 2004-08-04 23:25:31 most idiomatic way to "update or insert"?
Previous Message Scott Marlowe 2004-08-04 22:41:10 Re: enforcing a join type