Re: Get last id in postgresql

From: Date: Wed, 18 Jun 2003 19:54:46 +0000
Subject: Re: Get last id in postgresql
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-28721@lists.php.net to get a copy of this message
On Mon, 16 Jun 2003 21:13:14 -0500, Norma Ramirez - Tecnosoft <norma.ramirez@tecnosoft.com.co> wrote:
Hi all, I´m starting with posgresql and i trying to use pg_last_oid to get the last id in a insert query, but this function returns me a big number like 21318 and bigger, but the table just have 3 or 4 records. Could some one help? Any ideas? This is the script i´m using $insert = "insert into test(name) values('myname')"; $test = pg_exec($insert); echo $id = pg_last_oid($test); Norma Ramirez norma.ramirez@tecnosoft.com.co
Try this: "SELECT currval('" . $tablename . '_' . $columnname . "_seq') AS lastinsertid" The pg_last_oid() is used to determine the unique address within the entire database of a particular entry, not within a particular table, which is why the number is so huge. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

« previous php.db (#28721) next »