pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Prabu Subroto <prabu_subroto@yahoo.com>
To: pgsql-general@postgresql.org
Subject: Re: Sequence Question
Date: Wed, 4 Aug 2004 23:54:40 -0700 (PDT)
Message-ID: <20040805065440.53274.qmail@web41808.mail.yahoo.com> (raw)
In-Reply-To: <20040805041942.0D6513953@sitemail.everyone.net>

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 <obtuse@bmwe30.net> 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 



view thread (27+ messages)  latest in thread

Message-ID: <20040805065440.53274.qmail@web41808.mail.yahoo.com>
Permalink:  ../20040805065440.53274.qmail@web41808.mail.yahoo.com/
Also on:    postgresql.org/message-id/20040805065440.53274.qmail@web41808.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-general@postgresql.org
  Cc: prabu_subroto@yahoo.com
  Subject: Re: Sequence Question
  In-Reply-To: <20040805065440.53274.qmail@web41808.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox