RE: [PEAR] MDB - insert query

From: Date: Fri, 07 Mar 2003 17:46:02 +0000
Subject: RE: [PEAR] MDB - insert query
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-4095@lists.php.net to get a copy of this message
> From: Alexey Borzov [mailto:borz_off@cs.msu.su] > Sent: Friday, March 07, 2003 6:34 PM > > Lukas Smith wrote: > >>Looks like you've found another bug as well. > >>SELECT last_value is a Bad Way of getting current value of PostgreSQL > >>sequence, there are possible concurrency problems. > >>The query should be "SELECT currval('$seqname')" > Connection 1 established > Connection 2 established > > Connection 1: SELECT nextval('foo_seq') ---> 5 > Connection 2: SELECT currval('foo_seq') ---> error, we didn't do nextval > Connection 2: SELECT last_value FROM foo_seq ---> 5 > > Connection 2: SELECT nextval('foo_seq') ---> 6 > Connection 1: SELECT currval('foo_seq') ---> 5 (this is the value for > this connection) > Connection 1: SELECT last_value FROM foo_seq ---> 6 (this is the > concurrency problem I talked about) > Connection 2: SELECT currval('foo_seq') ---> 6 Seems to me that I want to use last_value(), since I want to get the current ID independent of the connection. Regards, Lukas

« previous php.pear.general (#4095) next »