[GENERAL] Converting between varchar and float when updating

2011-04-28 Thread Thomas Larsen Wessel
I have a table with the following schema: CREATE TABLE foo (bar VARCHAR(32)); Every bar value has a format like a float, e.g. "2.5". Now I want that value multiplied by two and saved again as varchar. I was hoping to do smth like: UPDATE foo SET bar = TO_VARCHAR( TO_FLOAT(bar) * 2); -- INCORRECT!

Re: [GENERAL] Converting between varchar and float when updating

2011-04-28 Thread Thomas Larsen Wessel
Thanks a lot :) Both of the following work UPDATE foo SET bar = (bar::float * 2); removes trailing zeros on the decimal side, if no decimals dont show any "." UPDATE foo SET bar = (bar::numeric * 2); keeps decimals, i.e. 2.000 * 2 -> 4.000 That leads me to two additional questions: 1) Can I sp

Re: [GENERAL] Converting between varchar and float when updating

2011-04-28 Thread Thomas Larsen Wessel
I appreciate the advice. But in this particular case, other people have decided for me that I should not change the schema. I guess they have their reasons :) On Thu, Apr 28, 2011 at 5:40 PM, Alban Hertroys < dal...@solfertje.student.utwente.nl> wrote: > On 28 Apr 2011, at 15:26, Thom