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 89A3452B22 for ; Fri, 15 Jul 2005 18:28: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 42040-10 for ; Fri, 15 Jul 2005 21:28:02 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.198]) by svr1.postgresql.org (Postfix) with ESMTP id ADA5F52AB9 for ; Fri, 15 Jul 2005 18:28:01 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so715526wra for ; Fri, 15 Jul 2005 14:28:04 -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=BeD1/dkAop2bE6v1pxGG+DV82oxqCqKV9wS1Tyhuv6Z5Xtu8Nvh3bAqpHa6gaDw2FRkcLiY2nU8UAxNSSyWXdJPs5igw4EMKmGL1Cbw9fAtUJYsyuGjUqDMWF3YrnsBNZL74e74ga9LLU0zR4Lv/+amdiIfLgWgQ5/YkXsoAqgU= Received: by 10.54.115.3 with SMTP id n3mr1187729wrc; Fri, 15 Jul 2005 14:28:03 -0700 (PDT) Received: by 10.54.86.16 with HTTP; Fri, 15 Jul 2005 14:28:03 -0700 (PDT) Message-ID: <90876a9e050715142860580a5c@mail.gmail.com> Date: Fri, 15 Jul 2005 15:28:03 -0600 From: Christian Cryder Reply-To: Christian Cryder To: pgsql-jdbc@postgresql.org Subject: Re: Timezone conversion woes In-Reply-To: <90876a9e050715104310fc0802@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> <90876a9e050715104310fc0802@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.94 tagged_above=0 required=5 tests=AWL, RCVD_BY_IP, RCVD_IN_BL_SPAMCOP_NET X-Spam-Level: X-Archive-Number: 200507/100 X-Sequence-Number: 13248 And just a little bit more information. I downloaded the jdbc source, and poked around a little bit to see if I could determine exactly what's going across the wire. I get this... FE=3D> Bind(stmt=3Dnull,portal=3Dnull,$1=3D<2005-04-03 00:06:02.000000-0700= >) FE=3D> Bind(stmt=3Dnull,portal=3Dnull,$1=3D<2005-04-03 02:29:43.000000-0700= >) FE=3D> Bind(stmt=3Dnull,portal=3Dnull,$1=3D<2005-04-03 03:02:09.000000-0700= >) It would appear to me from this that the data is going out of the JDBC drivers correctly, and that if the dates are getting modified (which they are), it's Postgres that's doing it. Can anyone confirm, deny, or correct my thinking here? tia, Christian On 7/15/05, Christian Cryder wrote: > 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. >=20 > The heart of the problem here seems to be that the millis value is > really getting changed on the way to the DB... >=20 > 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) >=20 > 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? >=20 > Christian >=20 >=20 >=20 > On 7/15/05, Christian Cryder wrote: > > Ok, I think I've got a piece of code that dupes my problem: > > > > 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) > > ); > > > > And here's the code that illustrates the problem... > > //change our timezone so that we are not operating in DST (this all= ows 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()); > > > > //now we're going to write some sample data > > SimpleDateFormat sdf =3D new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.= SSS"); > > 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(); > > > > //clean up the table > > stmt.execute("DELETE FROM Foo"); > > > > //insert some sample data > > pstmt =3D conn.prepareStatement("INSERT INTO Foo (TrxTime) VALU= ES (?)"); > > 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(); > > > > //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(); > > > > } 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) {} > > } > > > > 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: > > > > inserting: 2005-04-03 00:06:02.000 > > inserting: 2005-04-03 02:29:43.000 > > inserting: 2005-04-03 03:02:09.000 > > > > [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 > > > > 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 > > > > 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. > > > > Any suggestions? > > > > tia, > > Christian > > > > > > > > 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 b= e > > > >> 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 tim= e 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 > > > > > > > > > > > > > > > > >