1
I have a column where the strings are in the following format: "12.05%"
I need to do some calculations with these values, and I am formatting the values that are acceptable for the float/double format etc.
I have the following line in my query:
cast(replace(replace(replace(campo, '%', ''), '.', ''), ',', '.') as float)
It runs as expected without problems, but this column has null values or no value, in this case have no number so that can be converted to float and this ends up generating an error, I need to treat these values to receive "0".
ERROR: invalid input syntax for type double precision: ""
For something more elegant, I tried to use the function
to_number()
, but I couldn’t get anything more "clean" than that. Someone ?– Lacobus
That was really good and it worked perfectly! Thank you very much.
– Rafael Araujo