Re: ALTER TABLE with USING clause for timestamp

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Josh Trutwin <josh(at)trutwins(dot)homeip(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ALTER TABLE with USING clause for timestamp
Date: 2008-03-23 00:59:14
Message-ID: 25282.1206233954@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Josh Trutwin <josh(at)trutwins(dot)homeip(dot)net> writes:
> I have a column in a table defined as type TEXT and I'd like to
> convert to a TIME type - I tried this:
> ALTER TABLE t1 ALTER COLUMN tcol TYPE TIME WITHOUT TIME ZONE;
> which throws:
> ERROR: column "tcol" cannot be cast to type "pg_catalog.time"

You just need to cast it explicitly --- to prevent surprises, ALTER
COLUMN TYPE won't implicitly do anything there's no implicit cast for.

ALTER TABLE t1 ALTER COLUMN tcol TYPE TIME USING tcol::TIME;

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message James B. Byrne 2008-03-23 01:01:19 Re: MySQL to Postgres question
Previous Message Robert Treat 2008-03-23 00:03:17 Re: Postgres development