Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 0FC87632718 for ; Fri, 13 Mar 2009 14:10:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 29718-06 for ; Fri, 13 Mar 2009 14:10:03 -0300 (ADT) X-Greylist: delayed 00:24:45.986483 by SQLgrey-1.7.6 Received: from mx.astrofoto.org (mx.astrofoto.org [216.254.78.156]) by mail.postgresql.org (Postfix) with ESMTP id EFDF063246F for ; Fri, 13 Mar 2009 14:10:03 -0300 (ADT) Message-ID: <49BA8D93.4010901@astrofoto.org> Date: Fri, 13 Mar 2009 12:45:07 -0400 From: Roland Roberts User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: ResultSet.getTimestamp(Calendar) off by one-hour Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SA-Exim-Version: 4.2 (built Tue, 02 May 2006 07:36:10 -0400) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/68 X-Sequence-Number: 19398 I'm using Hiberate and JBoss with PostgreSQL as my backend. I have a column which is set by a database trigger CREATE FUNCTION security_biur_trg() RETURNS trigger AS $$ BEGIN -- Check that empname and salary are given -- Remember who changed the payroll when NEW.active_on := CURRENT_TIMESTAMP at time zone 'UTC'; RETURN NEW; END; $$ LANGUAGE plpgsql; CREATE TRIGGER security_bur BEFORE INSERT OR UPDATE ON drpg.security FOR EACH ROW EXECUTE PROCEDURE security_biur_trg(); I'm running this in New York, USA where the current offset is -4 hours (daylight savings in effect). After the insert of a row, I can query and confirm that the timestamp is +4 hours from my local time. But, when I query to retrieve a row, I end up with a timestamp which is -1 from local. The query looks like this: public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException { Calendar utcCalendar = (Calendar) UTC_CALENDAR.clone(); return rs.getTimestamp(names[0], utcCalendar); } where UTC_CALENDAR is intialized like so private static final TimeZone TZ_UTC; private static final Calendar UTC_CALENDAR; static { TZ_UTC = TimeZone.getTimeZone("UTC"); UTC_CALENDAR = Calendar.getInstance(TZ_UTC); } If I drop the Calendar from the getTimestamp, I get exactly what is in the database, the actual insert time +4 hours, as expected. But with the Calendar, I'm getting what I would expect during standard time, not DST. Since the inserted date is today's date and today is DST, this is simply wrong. I'm trying to figure out if I'm missing something here or if this is a real bug. Can someone comment? Is there something else I need to look at? roland -- PGP Key ID: 66 BC 3B CD Roland B. Roberts, PhD RL Enterprises roland@rlenter.com 6818 Madeline Court roland@astrofoto.org Brooklyn, NY 11220