Re: recasting to timestamp from varchar

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Kirk Wythers <kirk(dot)wythers(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: recasting to timestamp from varchar
Date: 2013-01-04 17:27:42
Message-ID: CAFj8pRAk7NZYHF5o9w70nVKLOyXiXdOMaLsZo2XR4kE6vSxapw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

2013/1/4 Kirk Wythers <kirk(dot)wythers(at)gmail(dot)com>

> I am trying to re-cast a column as a timestamp>
>
> ALTER TABLE sixty_min ALTER COLUMN time2 TYPE timestamp;
> ERROR: column "time2" cannot be cast to type timestamp without time zone
>
> The column time2 is currently a varchar. I actually do not want to mess
> with time zones, but it seems that postgres will not let me do this. The
> actual values in the column time2 look like this:
>
> 7/15/08 12:00
> Is this possible?
>

yes. it is possible
postgres=# create table foo(a timestamp);
CREATE TABLE

postgres=# insert into foo values(now());
INSERT 0 1
postgres=#

postgres=# alter table foo alter column a type varchar;
ALTER TABLE
postgres=# alter table foo alter column a type timestamp;
ERROR: column "a" cannot be cast automatically to type timestamp without
time zone
HINT: Specify a USING expression to perform the conversion.
postgres=# alter table foo alter column a type timestamp using a::timestamp;
ALTER TABLE
postgres=#

Regards

Pavel Stehule

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kirk Wythers 2013-01-04 17:28:36 recasting to timestamp from varchar
Previous Message Kirk Wythers 2013-01-04 17:16:57 recasting to timestamp from varchar