From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jeffrey Tenny <jeffrey.tenny@comcast.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Atomic query and update of sequence generators
Date: Wed, 14 Jan 2004 22:30:09 -0500
Message-ID: <19112.1074137409@sss.pgh.pa.us> (raw)
In-Reply-To: <4005E425.2070706@comcast.net>
References: <4005E425.2070706@comcast.net>
Jeffrey Tenny <jeffrey.tenny@comcast.net> 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
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, jeffrey.tenny@comcast.net
Subject: Re: Atomic query and update of sequence generators
In-Reply-To: <19112.1074137409@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