From: Bruno Wolff III <bruno@wolff.to>
To: Jodi Kanter <jkanter@virginia.edu>
Cc: Postgres Admin List <pgsql-admin@postgresql.org>
Subject: Re: psql sequence question
Date: Mon, 16 Jun 2003 11:04:10 -0500
Message-ID: <20030616160410.GA29057@wolff.to> (raw)
In-Reply-To: <3EEDE12C.30401@virginia.edu>
References: <3EEDE12C.30401@virginia.edu>
On Mon, Jun 16, 2003 at 11:24:28 -0400,
Jodi Kanter <jkanter@virginia.edu> wrote:
> If I'm using transactions (not autocommit), are sequences atomic?
Yes.
> In other words, after inserting a record to a table that
> uses sequence A, am I guaranteed that select last_value on
> sequence A is atomic, and cannot be interfered with by other
> transactions using that same sequence? Sequence A is used by
> several tables.
Probably not in the way you mean. Every transaction is going to see
a consistant view of the sequence table. However transactions proceeding
in parallel may seem the same value for the last value. To make this
work you would need to use serializable mode to do any updates based
on the value of the last value or lock the table exclusively to prevent
concurrent updates. This defeats the function of sequences providing
unique values using light weight locking.
The right way to use sequences is to use nextval to get new values
and use currval to reuse the value you got from the latest call to
nextval in the same session.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: bruno@wolff.to, jkanter@virginia.edu
Subject: Re: psql sequence question
In-Reply-To: <20030616160410.GA29057@wolff.to>
References: <3EEDE12C.30401@virginia.edu> <20030616160410.GA29057@wolff.to>
* 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