Daniel Farina <drfarina@acm.org> writes:
> Here are some weaknesses in the SUM aggregate that run up against the
> type system. Maybe they'll help crystallize some discussion:
> SUM(int2) => int4
> SUM(int4) => int8
> SUM(int8) => numeric
> Some weaknesses:
> SUM, of any precision, assumes that the precision being accumulated
> into (which is also the return-precision) is enough to avoid overflow.
This is not a flaw of the type system, it's just an implementation
choice in the SUM() aggregates. We could easily have chosen wider
accumulation and/or result types.
regards, tom lane