Re: How to best grab a chunk of Ids from a sequence - Mailing list pgsql-sql

From Tom Lane
Subject Re: How to best grab a chunk of Ids from a sequence
Date
Msg-id 18275.1005848724@sss.pgh.pa.us
Whole thread Raw
In response to How to best grab a chunk of Ids from a sequence  ("Bryan White" <bryan@arcamax.com>)
List pgsql-sql
"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


pgsql-sql by date:

Previous
From: "Bryan White"
Date:
Subject: How to best grab a chunk of Ids from a sequence
Next
From: Jason Earl
Date:
Subject: Re: INSERT question