Integer out of range problem

18 views
Skip to first unread message

Javier

unread,
Nov 17, 2008, 6:59:23 AM11/17/08
to H2 Database
Hi all,

I'm facing a 90110-103 error with H2 when performing an statement like
select avg(int_field) from some_table.

I've tried run the statement by replacing max(int_field), min
(int_field) and it works. The max value of int_field is 997920 and its
lowest value is 1. The table has 6 million records (1.5 gb database
and 950 M of index file).

Of course, int_field is defined as INTEGER NOT NULL.

Thoughts ?

Regards

Javier

unread,
Nov 17, 2008, 7:45:33 AM11/17/08
to H2 Database
Solved.

The solution is change the statement to select avg(cast(int_field as
bigint)) from some_table.

Is this an expected condition ? If int_field is defined as integer....
while cast to bigint ?

Thoughts ?

Thomas Mueller

unread,
Nov 18, 2008, 3:49:13 PM11/18/08
to h2-da...@googlegroups.com
Hi,

> The solution is change the statement to select avg(cast(int_field as
> bigint)) from some_table.
>
> Is this an expected condition ? If int_field is defined as integer....
> while cast to bigint ?

It's not nice... Some database solve this problem (HSQLDB as far as I
know) while others don't (MS SQL Server, not sure what version). I
will try to solve this for the next release, but I'm not sure yet if I
can for all data types.

Regards,
Thomas

Thomas Mueller

unread,
Nov 20, 2008, 9:17:33 AM11/20/08
to h2-da...@googlegroups.com
Hi,

The problem for AVG will be fixed in the next release. There is a
problem for SUM as well: it can overflow when using large values. In
the next release, SUM will return a data type that is safe. I hope
this will not break applications that call ResultSet.getObject and
expect the old data type.

Regards,
Thomas

Javier

unread,
Nov 21, 2008, 12:25:55 PM11/21/08
to H2 Database
Ok. Sounds ok for me.

My solution was change int_field from integer type to bigint type. The
cast is not needed anymore.

Thanks.

On Nov 20, 12:17 pm, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages