I would like to query an aggregate of values that get updated. For a simple and contrived example, if this were legal syntax I would do :
update mytable set mynumber = mynumber + 1 returning sum(mynumber);
An aggregate function is not allowed in the returning
clause. If this is possible, what is the best way to achieve this?
Best Answer
Use a CTE: