dinesh <dinesh@vssod.com> writes:
> I get an error saying cannot use aggregate function in RETURNING.
> Is this a bug or a feature?
Well, it's not a bug. RETURNING is defined as returning one row per
row inserted/updated/deleted, so aggregates are nonsensical there.
In recent versions you could put the UPDATE RETURNING inside a WITH,
and then do the aggregation in a SELECT over that.
regards, tom lane