I am looking for a possibillity to round the result of ST_Distance on two digits. If I try

select g.id ,round(ST_Distance(g.geom, p.geom), 2) dist_m

I get:

Funktion round(double precision, integer) existiert nicht

function round(double precision, integer) does not exist


The first place to look is always the PostgreSQL docs (i.e. Mathematical Functions)!

When using the two parameter signature of ROUND(), the function expects a NUMERIC type as its first input; you can simply cast the value (::):

SELECT g.id,
       ROUND(ST_Distance(g.geom, p.geom)::NUMERIC, 2) AS dist_m
FROM   ...
  • Naturally, the second step would be to check the return type of ST_DIstance; it's FLOAT, which is SQL standard for DOUBLE PRECISION – geozelot Nov 19 '19 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.