Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres: Update field and round it

I have huge table where occasionally one column got not rounded values, e.g. 16345.462500 instead of 16345.460000

I'm not that good in postgres - maybe it's possible to update table rounding those values?

I can't change field type, because some rows (cryptocurrencies) can contain not rounded numbers.

Easiest thing I can think about is PHP script to manually update all fields.

like image 899
Denis Matafonov Avatar asked Sep 16 '25 10:09

Denis Matafonov


1 Answers

You can use the round function to round to N decimal places - in your case, 2:

UPDATE mytable
SET    mycolumn = ROUND(mycolumn, 2)
like image 143
Mureinik Avatar answered Sep 19 '25 04:09

Mureinik