pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
About "Alter table... alter column.. TYPE ... "
2+ messages / 2 participants
[nested] [flat]

* About "Alter table... alter column.. TYPE ... "
@ 2005-04-18 20:38  Ying Lu <ying_lu@cs.concordia.ca>
  0 siblings, 1 reply; 2+ messages in thread

From: Ying Lu @ 2005-04-18 20:38 UTC (permalink / raw)
  To: pgsql-sql

Hello,

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"

Tks,
Emi




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: About "Alter table... alter column.. TYPE ... "
@ 2005-04-18 21:09  Rod Taylor <pg@rbt.ca>
  parent: Ying Lu <ying_lu@cs.concordia.ca>
  0 siblings, 0 replies; 2+ messages in thread

From: Rod Taylor @ 2005-04-18 21:09 UTC (permalink / raw)
  To: Ying Lu <ying_lu@cs.concordia.ca>; +Cc: 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.
-- 




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-04-18 21:09 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-18 20:38 About "Alter table... alter column.. TYPE ... " Ying Lu <ying_lu@cs.concordia.ca>
2005-04-18 21:09 ` Rod Taylor <pg@rbt.ca>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox