3

I am applying sum over an integer column which has some really large values.

I am constantly getting int64 overflow . Is there any way to avoid this overflow error

abhishek jha
  • 1,065
  • 4
  • 21
  • 41
  • wondering... what kind of problem are you working with that requires numbers above 5 quintillions? – Felipe Hoffa Aug 15 '16 at 21:08
  • Hey I have migrated some data into BigQuery tables and am trying to validate that data. It has an integer type column which basically consists of IDs having 12 digits. So I am getting these error in calculating basic statistical metrics like mean, max, sum avg etc You have any other approach of data validation in mind? :) – abhishek jha Aug 16 '16 at 03:32
  • just curiosity :) (did it work?) – Felipe Hoffa Aug 16 '16 at 04:09

2 Answers2

3

Not sure if it was possible at the time that this question was asked, but now there is another option:

Casting the Int64 to a Numeric type will do the trick:

// Will overflow
sum(largeInteger) as sumLargeInteger

// Will work
sum(cast(largeInteger as numeric)) as sumLargeInteger
ivospijker
  • 702
  • 1
  • 7
  • 22
2

It depends on how you want to handle the error, but either way it seems like you'll need some form of approximation.

One approximation is to cast to a FLOAT64 before summing. Another is to divide by some suitable amount before summing. Which one you choose depends on what sort of input you have and what sort of precision you need from the output.

Jeremy Condit
  • 6,766
  • 1
  • 28
  • 30