[英]How to get the value of an UPDATE … RETURNING query in postgreSQL in Doctrine DBAL
I'm trying to use this correct postgreSQL query working with Doctrine DBAL but so far I'm not succeeding, the query is: 我正在尝试使用与Doctrine DBAL一起使用的正确的postgreSQL查询,但到目前为止,我没有成功,查询是:
UPDATE table SET field = field + 1 WHERE id = ? RETURNING field AS fieldName;
The query works ok but trying to recover the value from the RETURNING clause I found no way to get this value from the query result in DBAL. 该查询工作正常,但尝试从RETURNING子句恢复该值,但我找不到从DBAL的查询结果中获取此值的方法。
I tried getLastInsertedId with the fieldName value and the return value of the call itself but no luck. 我试图getLastInsertedId与字段名值和调用的返回值本身,但没有运气。 Anyone knows a way to do that?
有人知道这样做的方法吗?
Thanks 谢谢
Ok, after fighting a little and with the help of @daniel-v%c3%a9rit%c3%a9 I found the way to do that. 好吧,经过一番搏斗并在@ daniel-v%c3%a9rit%c3%a9的帮助下,我找到了解决方法。
To retrieve the data after an update with returning in postgres you must execute the query like this: 要在更新后返回postgres来检索数据,必须执行以下查询:
$statement = $conn->executeQuery($sql, $params);
$statement->fetchAll();
This way with only one query you do the update and get the last value updated. 这样,只有一个查询就可以执行更新并获取最新的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.