The current manual is more explicit than it used to be in 2013:
sum
( integer
) → bigint
If your column myvalue
indeed has the type integer
like you say, then the result is bigint
anyway, and the added cast in sum(myvalue)::bigint
is just noise.
Either way, to get an "out of range" error, the result would have to be bigger than what bigint
can hold:
-9223372036854775808 to +9223372036854775807
One would have to aggregate a huge number of big integer
values (>= 2^32 * 2^31). If so, cast the base column to bigint
, thereby forcing the result to be numeric
:
SELECT sum(myvalue::int8) ...
The more likely explanation is that your column has, in fact, a different data type, or the error originates from something else. Not enough detail in the question.