Re: Last Id? - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: Last Id?
Date
Msg-id 20050906041151.GA94992@winnie.fuhr.org
Whole thread Raw
In response to Re: Last Id?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
On Mon, Sep 05, 2005 at 11:51:15PM -0400, Tom Lane wrote:
> Jan Danielsson <jan.danielsson@gmail.com> writes:
> >    I have seen a few "currval", "last_value", tricks and such, but they
> > aren't good enough, AFAICT, since they only work when I can guarantee
> > that no one else will insert a new record between the time that I insert
> > one, and query for the last_value.
>
> You evidently do not understand how currval works.  It is session-local,
> so the race condition you are imagining does not exist.

...which is mentioned in both the PostgreSQL documentation and the FAQ:

http://www.postgresql.org/docs/8.0/static/functions-sequence.html
http://www.postgresql.org/docs/faqs.FAQ.html#4.11.3

It's trivial to test the behavior yourself by opening multiple
sessions to the database and seeing if currval() in one session is
affected by inserts in the other sessions (it isn't).

--
Michael Fuhr

pgsql-novice by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Last Id?
Next
From: Michael Fuhr
Date:
Subject: Re: ERROR: 42P01: relation "