title: Redshift Divide By Zero Puzzler
body: <p>I was getting a divide by 0 error with this code:</p>
  
  <pre><code>CASE
  WHEN DENOMINATOR &gt;= 0
  THEN SUM(INT1 * INT2 / DENOMINATOR)
  ELSE 0
  END AS RATIO
  </code></pre>
  
  <p>However when I changed to the following code, it worked.</p>
  
  <pre><code>CASE
  WHEN DENOMINATOR &gt;= 0
  THEN SUM(INT1) * INT2 / DENOMINATOR
  ELSE 0
  END AS RATIO
  </code></pre>
  
  <p>Could someone help me understand the reason so I can avoid this in the future?  BTW, the first sample worked in Vertica.  I realize summing just what needs to be summed rather than doing the calculation before the summation is a better programming practice.  However still am curious.</p>