Subject Execute statement and sum
Author Milan Babuskov

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:

create table t1
x integer

set term !! ;
execute block
DECLARE VARIABLE sumx integer;
execute statement 'select sum(x) from t1'
into :sumx;

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?