Integer or Smallint for numeric literal
<p>The result of the following query irritates me:</p>

<pre><code>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.'
</code></pre>

<p>The returned value of the first selection is clearly of type decimal(11,0). The type unification of the coalesce function is documented <a href="https://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/com.ibm.db2z11.doc.sqlref/src/tpc/db2z_rules4resultdatatypes.html" rel="nofollow">here</a> (see numeric operands). Following these instructions and resolving the decimal(11,0) backwards means that the literal <strong>1 is interpreted as a large integer</strong>.</p>

<p>The return type of the second selection is a decimal(7,0). How DB2 behaves on multiplication can be read <a href="https://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/com.ibm.db2z11.doc.sqlref/src/tpc/db2z_decimalmultiplication.html" rel="nofollow">here</a> (the precision of the result is the sum of the precision of both operands). In this case, this means that the literal <strong>1 is interpreted as a small integer</strong>.</p>

<p>Note that the <code>char(..)</code> function has only been applied to show the precision and scale of the returned value.</p>

<p>When having an integer literal (like <code>1</code> in the example above), how do I know how DB2 interprets it (smallint, largeint, bigint)?</p>

<p>I'm using DB2 for z/OS v11.</p>