'RETURNING acts as a SELECT statement and changes ROW_COUNT()
I am trying to ensure only the precise numbers of rows are updated/inserted during a transaction by using ROW_COUNT(), however i also need to know the id of the row changed in certain circumstances.
e.g:
>>> INSERT INTO TABLE (name,drink,food) VALUES ('Jack', 'Coke', 'Pizza');
>>> SELECT ROW_COUNT();
>>> ROW_COUNT | 1
>>> INSERT INTO TABLE (name,drink,food) VALUES ('Jill', 'Pepsi', 'Hotdog') RETURNING id;
>>> ID | 25
>>> SELECT ROW_COUNT();
>>> ROW_COUNT | -1
Is there a way I can check ROW_COUNT() before returning the id or keep the ROW_COUNT() correct after the RETURNING statement ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
