Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fAFIPUm24813 for ; Thu, 15 Nov 2001 13:25:31 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id fAFIPOc18278; Thu, 15 Nov 2001 13:25:24 -0500 (EST) To: "Bryan White" cc: "pgsql-sql" Subject: Re: How to best grab a chunk of Ids from a sequence In-reply-to: <00a801c16df3$e06d6230$2ed260d1@bryan> References: <00a801c16df3$e06d6230$2ed260d1@bryan> Comments: In-reply-to "Bryan White" message dated "Thu, 15 Nov 2001 11:37:55 -0500" Date: Thu, 15 Nov 2001 13:25:24 -0500 Message-ID: <18275.1005848724@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200111/220 X-Sequence-Number: 5603 "Bryan White" 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