note 29566 deleted from function.pg-last-oid by jsheets
| From: | jsheets@php.net | Date: | Tue, 18 Feb 2003 00:17:04 +0000 |
| Subject: | note 29566 deleted from function.pg-last-oid by jsheets | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-44119@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 ?