Postgresql的mysql_insert_id()相当于? [重复]

时间:2023-01-31 14:25:10

Possible Duplicate:
mysql_insert_id alternative for postgresql

可能重复:postgresql的mysql_insert_id替代方法

Is there a Postgresql equivalent of mysql_insert_id() to get the ID generated in the last query ??

是否有一个Postgresql等效的mysql_insert_id()来获取上一个查询中生成的ID?

1 个解决方案

#1


4  

If you are using PostgreSQL 8.2 or newer then the simplest way is to use RETURNING:

如果您使用的是PostgreSQL 8.2或更新版本,那么最简单的方法是使用RETURNING:

$result = pg_query($db, "INSERT INTO foo (bar) VALUES (123) RETURNING foo_id");
$insert_row = pg_fetch_row($result);
$insert_id = $insert_row[0];

For other alternatives see this duplicate.

对于其他替代品,请参阅此副本

#1


4  

If you are using PostgreSQL 8.2 or newer then the simplest way is to use RETURNING:

如果您使用的是PostgreSQL 8.2或更新版本,那么最简单的方法是使用RETURNING:

$result = pg_query($db, "INSERT INTO foo (bar) VALUES (123) RETURNING foo_id");
$insert_row = pg_fetch_row($result);
$insert_id = $insert_row[0];

For other alternatives see this duplicate.

对于其他替代品,请参阅此副本