title: Postgres - how to typecast sum(bigint) to bigint?
body: <p>I have a Postgres 8.2 table with columns defined as <code>bigint</code> datatype.</p>
  
  <p>When I do <code>sum(column)</code> the return type is <code>numeric</code>. I want to force type cast the summation to be <code>bigint</code> since I know for sure that the result will not exceed the max value of <code>bigint</code>. I was able to achieve this using a subquery like this:</p>
  
  <p><code>select T.big_col_total::bigint from (select sum(big_col) as big_col_total from big_table) T;</code></p>
  
  <p>Is there a way to do this without using the subquery, i.e., can I typecast the <code>sum</code> directly somehow? I tried a couple of ways and both result in a syntax error.</p>
  
  <p>(background: I'm running this query from Hibernate so it is important for me the keep the return data type from the query limited to BigInteger. bigint + bigint = numeric (BigDecimal on the Java side)</p>