Search Postgresql Archives

Re: Unable To Change Data Type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In response to Carlos Mennens <carlos.mennens@xxxxxxxxx>:

> On Fri, Jun 10, 2011 at 1:57 PM, Bill Moran <wmoran@xxxxxxxxxxxxxxxxx> 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/

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux