Re: Cast char to number - Mailing list pgsql-general

From Richard Huxton
Subject Re: Cast char to number
Date
Msg-id 4B858A6F.3070206@archonet.com
Whole thread Raw
In response to Re: Cast char to number  (Raymond O'Donnell <rod@iol.ie>)
Responses Re: Cast char to number  ("Joshua D. Drake" <jd@commandprompt.com>)
Re: Cast char to number  ("Joshua D. Drake" <jd@commandprompt.com>)
List pgsql-general
On 24/02/10 20:06, Raymond O'Donnell wrote:
> However, to address your immediate problem, you could try something like
> this:
>
> (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.

Or, in any recent version of PG you can do this via ALTER TABLE
   http://www.postgresql.org/docs/8.4/static/sql-altertable.html

ALTER TABLE t ALTER COLUMN c TYPE integer USING c::integer;

You might want to clean up the values before doing this.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: Cast char to number
Next
From: "Daniel Verite"
Date:
Subject: Re: Cast char to number