X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id E2CC6D1D876 for ; Thu, 15 Jan 2004 03:30:40 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 21109-01 for ; Wed, 14 Jan 2004 23:30:13 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 795C8D1B528 for ; Wed, 14 Jan 2004 23:30:06 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id i0F3U9pH019113; Wed, 14 Jan 2004 22:30:10 -0500 (EST) To: Jeffrey Tenny Cc: pgsql-sql@postgresql.org Subject: Re: Atomic query and update of sequence generators In-reply-to: <4005E425.2070706@comcast.net> References: <4005E425.2070706@comcast.net> Comments: In-reply-to Jeffrey Tenny message dated "Wed, 14 Jan 2004 19:51:49 -0500" Date: Wed, 14 Jan 2004 22:30:09 -0500 Message-ID: <19112.1074137409@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/127 X-Sequence-Number: 16520 Jeffrey Tenny writes: > If I want to allocate a block of adjacent values from a sequence generator, > is the following statement atomic with respect to the time between > when the call to nextval() and setval()? > SELECT setval('foo', nextval()+20) ... Nope. > The goal is to get a sequence of 20 values that are all +1 from each other. Do you always want to pull exactly 20 values? If so you could set the sequence's "cache" parameter to 20 (see the CREATE SEQUENCE man page for details). I don't think there's any way at present to get varying sizes of consecutively-allocated blocks. If you need that, it would likely not be real hard to implement a "next_n_vals(seq, n)" variant of nextval() to grab N consecutive values and return the first. But it's not there at the moment. regards, tom lane