Cast syntax to convert a sum to float

MAK picture MAK · Feb 26, 2015 · Viewed 78.1k times · Source

Using PostgreSQL 9.3, I want to convert the calculated values to data type float.

My first attempt:

SELECT float(SUM(Seconds))/-1323 AS Averag;

Gives me this error:

syntax error at or near "SUM"

My second attempt:

SELECT to_float(SUM(Seconds))/-1323 AS Averag;

Gives me this error:

 function to_float(bigint) does not exist

Answer

Erwin Brandstetter picture Erwin Brandstetter · Mar 18, 2015

There is also the shorthand cast syntax:

SELECT sum(seconds)::float / -1323 AS averag;