Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 0B2006335CB for ; Thu, 29 Apr 2010 00:27:47 -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 18136-06 for ; Thu, 29 Apr 2010 03:27:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f196.google.com (mail-qy0-f196.google.com [209.85.221.196]) by mail.postgresql.org (Postfix) with ESMTP id D4C29632EA4 for ; Thu, 29 Apr 2010 00:27:39 -0300 (ADT) Received: by qyk34 with SMTP id 34so1594422qyk.10 for ; Wed, 28 Apr 2010 20:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=p1mtQ1HE+J6u3/oVD2V/vaJlpmCVX9uB+sAeR86N/ow=; b=vSdLgbNQwBZWf5It79PVTOWjN/H0ZFjpyJDW1XV4OSJnWum6mHuTgXrHIjGcMICEaM YWrWXilzy6M9ecwiK93rCtucp1tkLUXNqSCPxK04zZOvKXnIP/V0oSRSuSFvsIiFrvGU dfZunmtZPi6gMMfD+ajEIaJ+jFjZpzKMW0oOM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=n/01J28UKtANHsb857EYLPiugk9YdqB4HsS1qO8dwrS1nYbeas4ZMkMCrYo9FLY43I HdBOL+1ZB040CjZrAA1hYLrONuxvTA9OLQMT141GEdR4o/qiR2YrGfDk02Rh4IVl6F5h ebnGyRkbxqPa4OdkE6KNp9rr6d8fhCVKYTlfk= Received: by 10.229.182.4 with SMTP id ca4mr10352595qcb.90.1272511658780; Wed, 28 Apr 2010 20:27:38 -0700 (PDT) Received: from [137.110.118.107] (velerito.ucsd.edu [137.110.118.107]) by mx.google.com with ESMTPS id 31sm388926qci.19.2010.04.28.20.27.36 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 28 Apr 2010 20:27:38 -0700 (PDT) Message-ID: <4BD8FCA6.1020901@gmail.com> Date: Wed, 28 Apr 2010 20:27:34 -0700 From: Edward Ross User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: problem converting strings to timestamps with time zone Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.01 tagged_above=-10 required=5 tests=BAYES_20=-0.001, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201004/109 X-Sequence-Number: 34036 Hi, I have a table with varchar and timestamp with time zone columns, among others. Insertions into this table are usually done by a java program; and there are many tens of thousands of records in the table. Recently, after changes in the java software, many timestamps values inadvertently ended up in one of the varchar columns. Rather than writing some more java to rectify the situation, I was hoping it could be done with one update statement. However I'm having no luck constructing such a statement; I can't find a way to include the timezones in the update. It seems like this would be a rather common situation, but I've found no answers in the documentation nor the archives. If anyone knows how to do this, I would be most grateful. 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'); ^ | | The X's just mark where I would like to specify a time zone. But apprently to_timestamp has no way of inputting time zones. Does anyone know of another way? Thanks, Edward Ross