pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Edward Ross <efrossuhl@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: problem converting strings to timestamps with time zone
Date: Thu, 29 Apr 2010 00:59:09 -0700
Message-ID: <4BD93C4D.20807@gmail.com> (raw)
In-Reply-To: <853.1272512343@sss.pgh.pa.us>
References: <4BD8FCA6.1020901@gmail.com>
	<853.1272512343@sss.pgh.pa.us>

Tom Lane wrote:
> Edward Ross <efrossuhl@gmail.com> writes:
>> Here is a sandbox example of what I mean.
> 
>> CREATE TABLE test_0
>> (
>>     string_value varchar(2047),
>>     timestamp_value timestamp with time zone
>> );
> 
>> insert into test_0
>>        (string_value)
>>     values
>>        ('2010-03-12 17:06:21-0800'),
>>        ('2009-08-14 16:47:40+0500'),
>>        ('2010-03-22 22:45:59-0400');
> 
>> As expected, select * from test_0; , produces the following:
> 
>> string_value	            timestamp_value
>> 2010-03-12 17:06:21-0800	<null>
>> 2009-08-14 16:47:40+0500	<null>
>> 2010-03-22 22:45:59-0400	<null>
> 
>> I would like to parse the strings into their equivalent timestamps
>> and put them in the timestamp_value column.
> 
>> My attempt, so far, to update the table:
> 
>> update value
>>     set
>>     timestamp_value =
>>     to_timestamp(string_value, 'YYYY-MM-DD HH24:MI:SS-XXXX');
> 
> Forget to_timestamp; just cast the string to timestamptz.  The
> regular timestamp input converter will handle that format fine.
> 
> 			regards, tom lane
> 

That worked great.

Thanks very much,

Edward Ross



view thread (4+ messages)  latest in thread

Message-ID: <4BD93C4D.20807@gmail.com>
Permalink:  ../4BD93C4D.20807@gmail.com/
Also on:    postgresql.org/message-id/4BD93C4D.20807@gmail.com

 · 

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: efrossuhl@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: problem converting strings to timestamps with time zone
  In-Reply-To: <4BD93C4D.20807@gmail.com>

* 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