简体   繁体   中英

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:

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.

I tried getLastInsertedId with the fieldName value and the return value of the call itself but no luck. 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.

To retrieve the data after an update with returning in postgres you must execute the query like this:

$statement = $conn->executeQuery($sql, $params);
$statement->fetchAll();

This way with only one query you do the update and get the last value updated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM