pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rod Taylor <pg@rbt.ca>
To: Ying Lu <ying_lu@cs.concordia.ca>
Cc: pgsql-sql@postgresql.org
Subject: Re: About "Alter table... alter column.. TYPE ... "
Date: Mon, 18 Apr 2005 17:09:46 -0400
Message-ID: <1113858586.3859.526.camel@home> (raw)
In-Reply-To: <42641AD9.60708@cs.concordia.ca>
References: <42641AD9.60708@cs.concordia.ca>

> 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.
-- 




view thread (2+ messages)

Message-ID: <1113858586.3859.526.camel@home>
Permalink:  ../1113858586.3859.526.camel@home/
Also on:    postgresql.org/message-id/1113858586.3859.526.camel@home

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pg@rbt.ca, ying_lu@cs.concordia.ca
  Subject: Re: About "Alter table... alter column.. TYPE ... "
  In-Reply-To: <1113858586.3859.526.camel@home>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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