X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8E292533B8 for ; Mon, 18 Apr 2005 18:11:57 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 89425-06 for ; Mon, 18 Apr 2005 21:11:55 +0000 (GMT) Received: from tht.net (vista.tht.net [216.126.88.2]) by svr1.postgresql.org (Postfix) with ESMTP id 4A9425339B for ; Mon, 18 Apr 2005 18:11:54 -0300 (ADT) Received: from dyn-70-66.tor.dsl.tht.net (dyn-70-66.tor.dsl.tht.net [134.22.70.66]) by tht.net (Postfix) with ESMTP id 44EB276A21; Mon, 18 Apr 2005 17:11:58 -0400 (EDT) Subject: Re: About "Alter table... alter column.. TYPE ... " From: Rod Taylor To: Ying Lu Cc: pgsql-sql@postgresql.org In-Reply-To: <42641AD9.60708@cs.concordia.ca> References: <42641AD9.60708@cs.concordia.ca> Content-Type: text/plain Date: Mon, 18 Apr 2005 17:09:46 -0400 Message-Id: <1113858586.3859.526.camel@home> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/257 X-Sequence-Number: 21150 > 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. --