title: Is it possible to use a COALESCE function inside a SUM function?
body: <p>I'm trying to use COALESCE function at postgres in a query like this:</p>
  <pre><code>SELECT 
    id_school,
    SUM(COALESCE((student-&gt;'name'-&gt;&gt;'age'), '0')::numeric)
  FROM
    teachers
  GROUP BY 1;
  </code></pre>
  <p>The problem is at line:
  SUM(COALESCE((student-&gt;'name'-&gt;&gt;'age'), '0')::numeric)</p>
  <p>I tried to use COALESCE because I'm receiving some empty strings and the ERROR:  <em>invalid input syntax for type numeric: &quot;&quot;</em></p>
  <p>Shouldn't COALESCE solve this casting error? Can't I use COALESCE in a SUM function?</p>