Re: Converting between varchar and float when updating - Mailing list pgsql-general

From Dmitriy Igrishin
Subject Re: Converting between varchar and float when updating
Date
Msg-id BANLkTinAxwKOzHc3Z8DVPwUDENYvAqMkfw@mail.gmail.com
Whole thread Raw
In response to Converting between varchar and float when updating  (Thomas Larsen Wessel <mrvelle@gmail.com>)
List pgsql-general


2011/4/28 Thomas Larsen Wessel <mrvelle@gmail.com>
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!!!!
Try UPDATE foo SET bar = (bar::numeric * 2);

How is that done?

I know that the bar attribute ought to have type FLOAT, but I have to work with this legacy database. And anyway this table will rarely be updated.

Sincerely, Thomas




--
// Dmitriy.


pgsql-general by date:

Previous
From: Thomas Larsen Wessel
Date:
Subject: Converting between varchar and float when updating
Next
From: Szymon Guz
Date:
Subject: Re: Converting between varchar and float when updating