pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bryan White <bryan@arcamax.com>
Cc: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: How to best grab a chunk of Ids from a sequence
Date: Thu, 15 Nov 2001 13:25:24 -0500
Message-ID: <18275.1005848724@sss.pgh.pa.us> (raw)
In-Reply-To: <00a801c16df3$e06d6230$2ed260d1@bryan>
References: <00a801c16df3$e06d6230$2ed260d1@bryan>

"Bryan White" <bryan@arcamax.com> writes:
> My question is is there a way to grab 4 million IDs from a sequence without
> calling nextval once for each ID.  Note, this sequence is being actively
> drawn on by other processes.

I can't think of any really clean way, but you could do something like

	select setval('seq', nextval('seq') + 4000000 + 100);

and then use the 4m IDs just before the returned value.  Because the
nextval and setval aren't an atomic operation, it's possible that
some other processes will get in and do nextval in between.  The extra
100 advance of the sequence should provide an adequate buffer for that
... but of course it could theoretically be insufficient...

			regards, tom lane



view thread (3+ messages)  latest in thread

Message-ID: <18275.1005848724@sss.pgh.pa.us>
Permalink:  ../18275.1005848724@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18275.1005848724@sss.pgh.pa.us

 · 

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-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, bryan@arcamax.com
  Subject: Re: How to best grab a chunk of Ids from a sequence
  In-Reply-To: <18275.1005848724@sss.pgh.pa.us>

* 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