X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D256D52AC4 for ; Fri, 15 Jul 2005 14:44:05 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15357-03 for ; Fri, 15 Jul 2005 17:43:58 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.207]) by svr1.postgresql.org (Postfix) with ESMTP id C781452AB9 for ; Fri, 15 Jul 2005 14:43:56 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i31so680847wra for ; Fri, 15 Jul 2005 10:43:57 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=qJ4x8n3cPX7rhrcQ+C4Hl0RKRObDnb/gA2UwFsl4bD+VMU6mSj4YETNJl9qtviIGwiytoN1oHm9lbS6/NEd9iMqNV0M1xTiYgNbmCLA76iwoqBobpfaulMcL9BGvdZwy8bMMbs5vQjJJpMHaexAriTW/eKDLj3pImf+Ky+V3PL8= Received: by 10.54.68.6 with SMTP id q6mr1194248wra; Fri, 15 Jul 2005 10:43:57 -0700 (PDT) Received: by 10.54.86.16 with HTTP; Fri, 15 Jul 2005 10:43:57 -0700 (PDT) Message-ID: <90876a9e050715104310fc0802@mail.gmail.com> Date: Fri, 15 Jul 2005 11:43:57 -0600 From: Christian Cryder Reply-To: Christian Cryder To: pgsql-jdbc@postgresql.org Subject: Re: Timezone conversion woes In-Reply-To: <90876a9e0507151015343cad99@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <90876a9e0507141122463cb054@mail.gmail.com> <138BE1E1-0639-4C3A-AE65-0997000E5613@fastcrypt.com> <90876a9e0507141225196ea488@mail.gmail.com> <75FDBC4A-48CC-4917-96B3-06A181AA1F5F@fastcrypt.com> <90876a9e0507151015343cad99@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 tagged_above=0 required=5 tests=RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200507/99 X-Sequence-Number: 13247 And just in case that example wasn't clear enough, I've tried using rs.getTimestamp(i) or rs.getTimestamp(i, cal) instead of rs.getObject(i). Neither of those have any effect. The heart of the problem here seems to be that the millis value is really getting changed on the way to the DB... inserting: 2005-04-03 00:06:02.000 (millis: 1112511962000) inserting: 2005-04-03 02:29:43.000 (millis: 1112520583000) inserting: 2005-04-03 03:02:09.000 (millis: 1112522529000) [UID]:16 [TrxTime]:2005-04-03 00:06:02.000 (millis: 1112511962000) [UID]:17 [TrxTime]:2005-04-03 03:29:43.000 (millis: 1112524183000) [UID]:18 [TrxTime]:2005-04-03 04:02:09.000 (millis: 1112526129000) So I write one thing and get something different back out. That doesn't seem correct. Surely there is a way to tell Postgres "to mess with my data" when you insert it? Christian On 7/15/05, Christian Cryder wrote: > Ok, I think I've got a piece of code that dupes my problem: >=20 > Here's how I'm creating my table (doesn't seem to matter whether I use > 'with time zone' or not)... > CREATE TABLE Foo ( > UID SERIAL, > TrxTime timestamp without time zone NOT NULL > , PRIMARY KEY (UID) > ); >=20 > And here's the code that illustrates the problem... > //change our timezone so that we are not operating in DST (this allow= s us to > //get un-munged timestamp values from src db) > TimeZone curTz =3D TimeZone.getDefault(); > TimeZone.setDefault(new SimpleTimeZone(curTz.getRawOffset(), > curTz.getID())); > System.out.println("current tz:"+TimeZone.getDefault()); >=20 > //now we're going to write some sample data > SimpleDateFormat sdf =3D new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS= S"); > ObjectRepository or =3D ObjectRepository.getGlobalRepository(); > DataSource ds =3D (DataSource) or.getState(AppKeys.DB_SYNC_TARGET); > Connection conn =3D null; > Statement stmt =3D null; > PreparedStatement pstmt =3D null; > Timestamp t =3D null; > try { > conn =3D ds.getConnection(); > stmt =3D conn.createStatement(); >=20 > //clean up the table > stmt.execute("DELETE FROM Foo"); >=20 > //insert some sample data > pstmt =3D conn.prepareStatement("INSERT INTO Foo (TrxTime) VALUES= (?)"); > t =3D new Timestamp(1112511962000L); //2005-04-03 00:06:02 > System.out.println("inserting: "+sdf.format(t)); > pstmt.setObject(1, t); > pstmt.executeUpdate(); > t =3D new Timestamp(1112520583000L); //2005-04-03 02:29:43 > System.out.println("inserting: "+sdf.format(t)); > pstmt.setObject(1, t); > pstmt.executeUpdate(); > t =3D new Timestamp(1112522529000L); //2005-04-03 03:02:09 > System.out.println("inserting: "+sdf.format(t)); > pstmt.setObject(1, t); > pstmt.executeUpdate(); > if (!conn.getAutoCommit()) conn.commit(); >=20 > //now read the values back out > ResultSet rs =3D stmt.executeQuery("SELECT * FROM Foo"); > while (rs.next()) { > System.out.println("[UID]:"+rs.getObject(1)+" > [TrxTime]:"+rs.getObject(2)); > } > rs.close(); > } catch (SQLException e) { > System.out.println("Unexpected SQLException: "+e); > e.printStackTrace(); >=20 > } finally { > if (stmt!=3Dnull) try {stmt.close();} catch (SQLException e) {} > if (pstmt!=3Dnull) try {pstmt.close();} catch (SQLException e) {} > if (conn!=3Dnull) try {conn.close();} catch (SQLException e) {} > } >=20 > Note that I am running in MST as my default system setting. I modify > this at runtime so that I am NOT using daylight savings. Here's what I > get for output: >=20 > inserting: 2005-04-03 00:06:02.000 > inserting: 2005-04-03 02:29:43.000 > inserting: 2005-04-03 03:02:09.000 >=20 > [UID]:7 [TrxTime]:2005-04-03 00:06:02.0 > [UID]:8 [TrxTime]:2005-04-03 03:29:43.0 > [UID]:9 [TrxTime]:2005-04-03 04:02:09.0 >=20 > See how the data is getting changed when its written into the DB (the > last 2 timestamps are bumped by an hour). Manually querying the DB > confirms that it got written in wrong >=20 > What appears to be happening is that either the JDBC driver or > Postgres itself is munging the data on the way in, saying - "since > Postgres is running in MST w/ DST, I'd better adjust these times". And > that's what I'm trying to avoid - I want it to write exactly what I > put in, with no adjustments. >=20 > Any suggestions? >=20 > tia, > Christian >=20 >=20 >=20 > On 7/15/05, Dave Cramer wrote: > > Christian, > > > > Can you send me a snippet of code that shows me what you are trying > > to do ? > > > > Dave > > On 14-Jul-05, at 3:25 PM, Christian Cryder wrote: > > > > > On 7/14/05, Dave Cramer wrote: > > > > > >> Yeah, create your timestamps without timezones and they will not be > > >> converted. > > >> > > > > > > Dave, how exactly do you do this? Especially if I am trying to read a > > > date out of the db (there is no timezone info there, but by the time = I > > > access the data via ps.getDate() its already there). > > > > > > Any suggestions would be greatly appreciated. > > > > > > Thanks, > > > Christian > > > > > > ---------------------------(end of > > > broadcast)--------------------------- > > > TIP 6: explain analyze is your friend > > > > > > > > > > >