title: PSQL: Aggregate function (sum) not working
body: <p>I have this query (<code>artist_money</code> is of  <code>MONEY</code> type, e.g. <code>$30,456.11</code>.):</p>
  
  <pre><code>SELECT SUM(
  CASE
  WHEN end_date - date '2015-12-3' &lt;= 28 AND end_date - date '2015-12-3' &gt; 0 THEN artist_money
  END,
  CASE
  WHEN date '2015-12-3' - start_date &gt; 28 THEN artist_money
  END
  ) AS "gonorar"
  FROM peacecard 
  WHERE artist_id = 12345 AND contract IS NOT NULL
  </code></pre>
  
  <p>When I try to get the result, here's the error:</p>
  
  <pre><code>ERROR:  function sum(money, money) does not exist
  LINE 1: SELECT sum(
                 ^
  HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
  ********** Error **********
  </code></pre>
  
  <p>What's going on? According to <a href="http://www.postgresql.org/docs/9.2/static/functions-aggregate.html" rel="nofollow">Documentation</a>, <code>SUM</code> should take the parameters if it's <code>MONEY</code> type.</p>
  
  <p>Thanks a lot!</p>