The result of the following query irritates me:
select
char(coalesce(1, cast(5 as decimal(2,0)))) as a,
char(1 * cast(5 as decimal(2, 0))) as b
from sysibm.sysdummy1;
a = ' 00000000001.'
b = ' 0000005.'
The returned value of the first selection is clearly of type decimal(11,0). The type unification of the coalesce function is documented here (see numeric operands). Following these instructions and resolving the decimal(11,0) backwards means that the literal 1 is interpreted as a large integer.
The return type of the second selection is a decimal(7,0). How DB2 behaves on multiplication can be read here (the precision of the result is the sum of the precision of both operands). In this case, this means that the literal 1 is interpreted as a small integer.
Note that the char(..)
function has only been applied to show the precision and scale of the returned value.
When having an integer literal (like 1
in the example above), how do I know how DB2 interprets it (smallint, largeint, bigint)?
I'm using DB2 for z/OS v11.