Parse float to int in postgresql

postgresql, sql, sql-update

Solution

You would be better suited casting the columns that were text, to numeric, to integer, so that rounding is taken into consideration e.g.

`SELECT '25.3'::numeric::integer AS num1, '25.5'::numeric::integer AS num2`

which would return integers of 25 and 26 respectively.

If you were not concerned with the digits following the point, the `floor(column_name::numeric)::integer` function or a substring, as mentioned, should be fine.

Problem

I've a set of data in a postgresql DB, where one of these columns store string data in float format, but now I need remove the decimal component of the string. How can I do this using an sql update statement in my BD console? Is that possible? for example: ``` "25.3" -> "25" ``` If it does not possible how can I do this? Thanks in advance.

Original source