Re: Last ID Problem - Mailing list pgsql-novice

From Tom Lane
Subject Re: Last ID Problem
Date
Msg-id 10519.1107237380@sss.pgh.pa.us
Whole thread Raw
In response to Re: Last ID Problem  (Michael Fuhr <mike@fuhr.org>)
Responses Re: Last ID Problem  (Michael Fuhr <mike@fuhr.org>)
List pgsql-novice
Michael Fuhr <mike@fuhr.org> writes:
> On Mon, Jan 31, 2005 at 08:55:22PM -0500, Mitch Pirtle wrote:
>> 'Common', unfortunately, is relative; and in this matter might only
>> apply to ADOdb ;-)

> The world's bigger than a couple of PHP modules :-)  Calling currval()
> after an INSERT is a common way to get the sequence value when using
> PostgreSQL, regardless of the programming language or API being
> used.

His point stands though: if you are accessing Postgres through some kind
of connection-pooling software, currval() cannot be trusted across
transaction boundaries, since the pool code might give your connection
to someone else.  In this situation the nextval-before-insert paradigm
is the only way.

(But in most of the applications I can think of, your uses of currval
subsequent to an INSERT ought to be in the same transaction as the
insert, so are perfectly safe.  If your connection pooler takes control
away from you within a transaction block, you need a less broken
pooler...)

            regards, tom lane

pgsql-novice by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Last ID Problem
Next
From: Michael Fuhr
Date:
Subject: Re: Last ID Problem