Subject Re: [firebird-support] Execute statement and sum
Author Martijn Tonies

> I ran into a strange problem and I'm trying to understand why it works
> like this. What should be the data type of SUM() function over an
> integer column?
> I thought that SUM(integer) yields integer, but it looks like it is
> not the case as "execute statement" fails with error about
> incompatible types. Consider this simple example:

bigint, I believe. Kinda makes sense, given that summing up ints
can go beyond the int range.

> create table t1
> (
> x integer
> );
> commit;
> set term !! ;
> execute block
> as
> DECLARE VARIABLE sumx integer;
> begin
> execute statement 'select sum(x) from t1'
> into :sumx;
> end!!
> I get this error:
> Variable type (position 0) in EXECUTE STATEMENT 'select sum(x) from
> t1' INTO does not match returned column type.
> I know I can work around it by casting the SUM to integer, but I'd
> like to know why it works this way. Perhaps this is a question for
> devel list?

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
My thoughts:
Database development questions? Check the forum!