Re: recasting to timestamp from varchar

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: recasting to timestamp from varchar
Date: 2013-01-05 05:53:40
Message-ID: 50E7BFE4.7070803@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/4/2013 9:28 AM, Kirk Wythers wrote:
> ALTER TABLE sixty_min ALTER COLUMN time2 TYPE timestamp;
> ERROR: column "time2" cannot be cast to type timestamp without time zone

you need to give it some hints as to how to do that casting.

ALTER TABLE sixty_min ALTER COLUMN time2 TYPE timestamp USING
to_timestamp(time2, 'YYYY-MM-DD HH24-MI-SS');

I would use timezone with time zone as the type here. Effectively, this
type converts all input times to UTC from either the specified or
client's default TZ, and converts all time output to either the
specified or client's TZ. it behaves properly, while 'timestamp'
without timezone doesn't..

In response to

Browse pgsql-general by date

  From Date Subject
Next Message ERR ORR 2013-01-05 18:20:41 Question on Trigram GIST indexes
Previous Message Jeff Janes 2013-01-05 05:24:41 Re: PostgreSQL run as process in windows