Re: Unable To Change Data Type - Mailing list pgsql-general

From Bill Moran
Subject Re: Unable To Change Data Type
Date
Msg-id 20110610141819.523bec6b.wmoran@potentialtech.com
Whole thread Raw
In response to Re: Unable To Change Data Type  (Carlos Mennens <carlos.mennens@gmail.com>)
List pgsql-general
In response to Carlos Mennens <carlos.mennens@gmail.com>:

> On Fri, Jun 10, 2011 at 1:57 PM, Bill Moran <wmoran@potentialtech.com> wrote:
> > I don't think ALTER COLUMN TYPE will implicitly convert from varchar
> > to INT.
> >
> > Try:
> > ALTER TABLE reference
> >  ALTER COLUMN color
> >    TYPE INT
> >    USING CAST(color AS INT);
>
> Your command suggestion worked perfect but can you explain why yours
> worked and mine didn't? I've never used 'USING CAST' command before.

Apparently, PostgreSQL isn't sure of how to do the conversion, so you
have to tell it.  You could just as easily given any valid expression
to the USING clause -- if your conversion was more complex than simply
a cast.

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

pgsql-general by date:

Previous
From: Carlos Mennens
Date:
Subject: Re: Unable To Change Data Type
Next
From: John R Pierce
Date:
Subject: Re: Unable To Change Data Type