Re: About "Alter table... alter column.. TYPE ... "

From: Rod Taylor <pg(at)rbt(dot)ca>
To: Ying Lu <ying_lu(at)cs(dot)concordia(dot)ca>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: About "Alter table... alter column.. TYPE ... "
Date: 2005-04-18 21:09:46
Message-ID: 1113858586.3859.526.camel@home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> To alter table column from varchar(32) to date. "Alter table" command
> does not seem to work:
>
> alter table test alter column col type date ;
> ERROR: column "col1" cannot be cast to type "date"

Alter table will not automatically throw away information. That is, in
cases where it believes you may lose data, it will not perform it.

That said, you can coax it into doing so.

ALTER TABLE test ALTER COLUMN col TYPE date USING CAST(col AS date);

USING is an arbitrary expression capable of doing most things you can do
in an UPDATE.
--

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Dan Feiveson 2005-04-18 21:19:36 tsearch2
Previous Message Ying Lu 2005-04-18 20:38:49 About "Alter table... alter column.. TYPE ... "