Re: Converting between varchar and float when updating

From: Dmitriy Igrishin <dmitigr(at)gmail(dot)com>
To: Thomas Larsen Wessel <mrvelle(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Converting between varchar and float when updating
Date: 2011-04-28 09:57:41
Message-ID: BANLkTimj1A=-tgUFAKcD_mAh_i-xSUz9jw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2011/4/28 Thomas Larsen Wessel <mrvelle(at)gmail(dot)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!!!!
>
> 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
>
> Btw, why are you store numeric values in varchar instead of numeric?

--
// Dmitriy.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vibhor Kumar 2011-04-28 10:11:26 Re: Converting between varchar and float when updating
Previous Message Dmitriy Igrishin 2011-04-28 09:52:18 Re: Converting between varchar and float when updating