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

From Joshua D. Drake
Subject Re: Cast char to number
Date
Msg-id 1267043902.17525.136.camel@jd-desktop.iso-8859-1.charter.com
Whole thread Raw
In response to Re: Cast char to number  (Scott Marlowe <scott.marlowe@gmail.com>)
List pgsql-general
On Wed, 2010-02-24 at 13:35 -0700, Scott Marlowe wrote:

> >> You might want to clean up the values before doing this.
> >
> > That won't work in this case. char() can't be cast to int/numeric. Not
> > only that it isn't possible to clean up the data in table because char
> > automatically pads.
> >
> > postgres=# alter table foo alter column id type numeric;
> > ERROR:  column "id" cannot be cast to type "pg_catalog.numeric"
> > postgres=#
>
> The example given works fine for me:
>
> smarlowe=# create table abc (c char(10));
> CREATE TABLE
> smarlowe=# insert into abc values ('0010'),('90'),('66');
> INSERT 0 3
> smarlowe=# alter table abc alter column c type numeric using c::numeric;
> ALTER TABLE
>

Well that is interesting. I would have thought it would have failed
because of the padding...

Joshua D. Drake


--
PostgreSQL.org Major Contributor
Command Prompt, Inc: http://www.commandprompt.com/ - 503.667.4564
Consulting, Training, Support, Custom Development, Engineering
Respect is earned, not gained through arbitrary and repetitive use or Mr. or Sir.


pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: Cast char to number
Next
From: Terry
Date:
Subject: select issue with order v8.1