ERROR 2616 Numeric overflow during computation while doing count(*)

user3055262 picture user3055262 · Jan 30, 2014 · Viewed 35.3k times · Source

I am trying to do a select count(*) from table from a table and I am not able to do it because of this error. I am not aware of the number of rows in the table.

I am not doing any other aggregation in my query apart from this.

I guess it has something to do with the count value which is too large to be stored in INTEGER.

What is the alternative?

Answer

dnoeth picture dnoeth · Jan 30, 2014

When your session runs in Teradata mode the result of a COUNT is INTEGER as you already noticed (in ANSI mode it will be a DECIMAL with at least 15 digits).

The workaround is simple, cast it to a bigint:

SELECT CAST(COUNT(*) AS BIGINT)...