Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 2359B6335EA for ; Thu, 29 Apr 2010 00:39:31 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 20794-07 for ; Thu, 29 Apr 2010 03:39:24 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 108086335CB for ; Thu, 29 Apr 2010 00:39:23 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o3T3d3dw000854; Wed, 28 Apr 2010 23:39:03 -0400 (EDT) To: Edward Ross cc: pgsql-sql@postgresql.org Subject: Re: problem converting strings to timestamps with time zone In-reply-to: <4BD8FCA6.1020901@gmail.com> References: <4BD8FCA6.1020901@gmail.com> Comments: In-reply-to Edward Ross message dated "Wed, 28 Apr 2010 20:27:34 -0700" Date: Wed, 28 Apr 2010 23:39:03 -0400 Message-ID: <853.1272512343@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.826 tagged_above=-10 required=5 tests=AWL=0.084, BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201004/110 X-Sequence-Number: 34037 Edward Ross 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 > 2009-08-14 16:47:40+0500 > 2010-03-22 22:45:59-0400 > 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