MAK MAK - 5 months ago 28
SQL Question

PostgreSQL 9.3: Convert to float

I want to convert the calculated values into

float
.

My try 1:

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


Gives me an error:

syntax error at or near "SUM"


My try 2:

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


Gives me an error:

function to_float(bigint) does not exist

Answer

You need to use the cast syntax:

SELECT CAST (SUM(Seconds) AS FLOAT)/-1323 AS Averag;