note 29566 added to function.pg-last-oid

From: Date: Mon, 17 Feb 2003 20:23:32 +0000
Subject: note 29566 added to function.pg-last-oid
Groups: php.notes 
Request: Send a blank email to php-notes+get-44110@lists.php.net to get a copy of this message
RE: [Editor's Note: If another record is inserted after the nextval is obtained and before you the INSERT query this code will fail. This should not be done on busy sites.] I don't know why it can fail <? pg_query($conn, 'CREATE TABLE foo (key SERIAL, foo TEXT)'); $res=pg_query("SELECT nextval('foo_key_seq') as key"); $key=pg_fetch_array($res, 0); $key=$key[key]; $res2=pg_query("SELECT nextval('foo_key_seq') as key"); $key2=pg_fetch_array($res2, 0); $key2=$key[key]; // now we have the serial value in $key, let's do the insert pg_query("INSERT INTO foo (key, foo) VALUES ($key2, 'blah blah 2')"); pg_query("INSERT INTO foo (key, foo) VALUES ($key, 'blah blah')"); ?> $key -> 1 $key2 -> 2 I can insert tupla with key =2 before than tupla with key=1 What is the problem ? -- http://www.php.net/manual/en/function.pg-last-oid.php http://master.php.net/manage/user-notes.php?action=edit+29566 http://master.php.net/manage/user-notes.php?action=delete+29566 http://master.php.net/manage/user-notes.php?action=reject+29566

« previous php.notes (#44110) next »