title: PostgreSQL, SELECT CASE COALESCE
body: <p>I need to 'name' categories: <code>mycat</code> is a <code>text</code> column with possible values <code>'0'</code> to <code>'4'</code>.</p>
  
  <pre><code>SELECT CASE mycat                                       
         WHEN '0' THEN 'ZERO'                         
         WHEN '1' THEN 'ONE'                      
         WHEN '2' THEN 'TWO'                      
         WHEN '3' THEN 'THREE'                        
         WHEN '4' THEN 'OTHER'        
     END AS my_category,
     COALESCE(SUM(col1), 0), 
     COALESCE(SUM(col2), 0), 
     COALESCE(SUM(col3), 0) 
     FROM mytable 
  GROUP BY mycat 
  ORDER BY mycat;
  </code></pre>
  
  <p>That works OK, but I have some an error in my program which very rarely writes <code>null</code> (or <code>''</code> as I can see in pgAdmin). In such cases I have to treat that <code>''</code> the same as <code>'0'</code>.
  But I can't get that!</p>
  
  <p>I try like this:</p>
  
  <pre><code>SELECT CASE COALESCE(mycat, '0')
  </code></pre>
  
  <p>But this doesn't solve it at all.<br>
  How to get that <code>''</code> will be summed and grouped together with <code>'0'</code> category?</p>
  
  <p>PostgreSQL 9.3, Windows.</p>