无法使用 PDO/PHP 获取最后插入的 UUID

Can't get the Last Insert UUID with PDO/PHP

我的主键是一个 UUID。当我制作新用户插图时,我需要获取插图 ID。

试过这样得到:

$insert=$connection->prepare("INSERT INTO db.schema.users (blocked) VALUES (false)")->execute();

var_dump($connection->lastInsertId('schema.users') );

但是报错如下:

SQLSTATE[42809]: Wrong object type: 7 ERROR:  \"users\" is not a sequence

这是我的 table 结构:


这样获取UUID有可能吗?

尝试使用 RETURNING 语法:

$stmt = $connection->prepare("INSERT INTO db.schema.users (blocked) VALUES (false) RETURNING usr_uuid");
$stmt->execute()

var_dump($stmt->fetchColumn());