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