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

Поиск
Список
Период
Сортировка
От Rod Taylor
Тема Re: About "Alter table... alter column.. TYPE ... "
Дата
Msg-id 1113858586.3859.526.camel@home
обсуждение исходный текст
Ответ на About "Alter table... alter column.. TYPE ... "  (Ying Lu <ying_lu@cs.concordia.ca>)
Список 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.
-- 



В списке pgsql-sql по дате отправления:

Предыдущее
От: Ying Lu
Дата:
Сообщение: About "Alter table... alter column.. TYPE ... "
Следующее
От: Oleg Bartunov
Дата:
Сообщение: Re: tsearch2