Re: GetLastInsertID ?

From: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane)
Cc: kleptog(at)svana(dot)org, db(at)zigo(dot)dhs(dot)org (Dennis Bjorklund), spinel(at)noos(dot)fr (Stephane Pinel), pgsql-general(at)postgresql(dot)org
Subject: Re: GetLastInsertID ?
Date: 2004-01-04 22:14:59
Message-ID: 200401042215.i04MF0Xo000964@gw.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> If you are using persistent connections in PHP you have to be very
> careful, because independent bits of PHP script may re-use the same
> database connection, and thereby will see a common currval value.
> After doing a nextval, you have to be sure to fetch currval before
> releasing the connection back to the pool.

I don't think I was using persistent connections at the time, as I have
security concerns about them.

It sound to me like there's the potential for a second web program sharing
the persistent connection to do something in between the nextval and
the currval.

Is currval for each process maintained at the front end (e.g., the PHP or
psql connection) or at the back end? If the latter, isn't there always
the potential for memory overflows or other high-demand situations causing
the pairing of nextval/currval to get corrupted or lost, in which case
RELYING upon it for the last key value could be a source of problems.
--
Mike Nolan

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Doug McNaught 2004-01-04 23:04:30 Re: GetLastInsertID ?
Previous Message Paul Ganainm 2004-01-04 21:46:58 Re: Is my MySQL Gaining ?