Atomic query and update of sequence generators

From: Jeffrey Tenny <jeffrey(dot)tenny(at)comcast(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Atomic query and update of sequence generators
Date: 2004-01-15 00:51:49
Message-ID: 4005E425.2070706@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


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) ...

The goal is to get a sequence of 20 values that are all +1 from each other.

If the above isn't safe in concurrent environments, is there something
else I can
do to achieve the effect safely?

I saw a similar unanswered question on one of the PostgreSQL newsgroups,
and have a need to do the same thing from my JDBC app.

Tips appreciated.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Stuart Barbee 2004-01-15 03:17:12 Re: REPOST[GENERAL] Quoting for a Select Into - Please Help
Previous Message A E 2004-01-14 22:47:53 REPOST[GENERAL] Quoting for a Select Into - Please Help