3

I have a 'cities' point layer. I want to compute a table with the coordinates of the geometries which works fine with that expression:

select
    name,
    ST_X(geom) as x_coordinate,
    ST_Y(geom) as y_coordinate
from
    cities 

Now I want to round the values because there are many digits after the comma. I only want to have 2 digits after the comma. Why does the following expression doesn't work for me?

select
    name,
    round(ST_X(geom),2) as x_coordinate,
    round(ST_Y(geom),2) as y_coordinate
from
    cities 

The error message I get is:

ERROR: function round(double precision, integer) does not exist

0

1 Answer 1

5

Via Round ST_Distance you need to cast the values to a numeric:

select
  name,
  round(ST_X(geom)::numeric, 2) as x_coordinate,
  round(ST_Y(geom)::numeric, 2) as y_coordinate
from cities

You could also use ST_ReducePrecision but I am not sure how that handles the funny bits about floating-point value representation.

0

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