note 7855 deleted from function.pg-exec by nlopess

From: Date: Sat, 26 Jun 2004 19:18:38 +0000
Subject: note 7855 deleted from function.pg-exec by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71823@lists.php.net to get a copy of this message
Note Submitter: ronabop@php.net ---- On pg_getlastoid vs. SELECT currval('some_table_seq'); One or the other may work better, depending on usage. Currval() has a recovery problem, however. If two users hit a database at close to the same time, _after_ an insert (say, 2-10 milliseconds of eachother), they may both get the same currval, as the web front-end is running as one user (or, more usually, several of them, so this is rare, but theoretically possible). This means that they *may* not get the right value for the last serial number, unless youir lookup is performed on something returned from the last statement (such as an OID). It's not a bug, or a race condition, it's *expected behavior* that it wouldn't give an old number after the web process asked for a new number. There is a similar issue with nextval(). If two users get one at similar times, but one abandons the session/pageload/whatever, you can wind up with holes in the serial numbers. Set up two windows with the following script, and reload on a few times.... and watch your serial sequence gain holes. <? $conn = pg_connect("dbname=common"); $result=pg_exec($conn,"SELECT nextval('contact_seq');"); echo pg_result($result,0,nextval); ?> Hence, pg_getlastoid.

« previous php.notes (#71823) next »