Re: Cast char to number

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Cast char to number
Date: 2010-02-24 20:25:35
Message-ID: ab530d33-abda-44c0-9548-6e1cef0a3c0a@mm
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Raymond O'Donnell wrote:

> (i) Create a new column of type numeric or integer as appropriate.
> (ii) update your_table set new_column = CAST(trim(both ' 0' from
> old_column) as numeric)
> (iii) Drop the old column, as well as any constraints depending on it.
> (iv) Rename the new column to the same name as the old column
> (v) Recreate any of the constraints dropped in step (iii).

Or try in a single step:
ALTER TABLE tablename ALTER column column_name
TYPE numeric USING column_name::numeric;
(replace numeric by the desired type if it's not numeric).

Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2010-02-24 20:27:46 Re: Cast char to number
Previous Message Richard Huxton 2010-02-24 20:22:07 Re: Cast char to number