Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XihZ7-00074f-25 for pgsql-jdbc@arkaria.postgresql.org; Mon, 27 Oct 2014 10:30:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XihZ6-0003cC-Hx for pgsql-jdbc@arkaria.postgresql.org; Mon, 27 Oct 2014 10:30:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XihZ5-0003c5-C4 for pgsql-jdbc@postgresql.org; Mon, 27 Oct 2014 10:30:19 +0000 Received: from gw1-york.kickstone.com ([46.37.63.73] helo=mail.kickstone.com) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XihZ1-00077o-4L for pgsql-jdbc@postgresql.org; Mon, 27 Oct 2014 10:30:18 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.kickstone.com (Postfix) with ESMTP id 68DF22E02D1 for ; Mon, 27 Oct 2014 10:29:41 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kickstone.com; h= content-type:content-type:in-reply-to:references:subject:subject :to:mime-version:user-agent:from:from:date:date:message-id; s= dkim; t=1414405778; x=1415269779; bh=NocghNAsriRPKvqhayiTeXhKoxS DISWKAW3eZNH/PqU=; b=KrE7J9GYformHkxFxllpfYqP+WOA1zkV2ErTc4nilOa WZz8Gl+4bwiQbD/cXSvGrvyBOSHGEsgAlCU4CcvTGV6sY44vI2+cBQdndLR0P6mF kxb10njPGe8CyjVR7c2J79BfB7EgxYYamfZMJtmcAbgl0tLNRAx9rlCbapLZpwMA = X-Virus-Scanned: amavisd-new at mail.kickstone.com Received: from mail.kickstone.com ([127.0.0.1]) by localhost (mail.kickstone.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Kt8Z6wqji9QF for ; Mon, 27 Oct 2014 10:29:38 +0000 (GMT) Received: from [192.168.2.133] (unknown [46.37.63.75]) by mail.kickstone.com (Postfix) with ESMTP id BFB742E02D0 for ; Mon, 27 Oct 2014 10:29:38 +0000 (GMT) Message-ID: <544E1EAE.9010605@kickstone.com> Date: Mon, 27 Oct 2014 10:30:06 +0000 From: John Lister User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: TIMESTAMP value binary transfer problem References: <001401cfedf0$2d861690$889243b0$@infoart.hr> <65A3123A-80BB-4F4C-ACDD-ED25142C7B2D@kickstone.com> <000401cff167$03db1a50$0b914ef0$@infoart.hr> In-Reply-To: <000401cff167$03db1a50$0b914ef0$@infoart.hr> Content-Type: multipart/alternative; boundary="------------070301030102030007020508" X-Pg-Spam-Score: -1.7 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org This is a multi-part message in MIME format. --------------070301030102030007020508 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit You are right it is related to timezones and daylight saving. I haven't looked through the recent code, but from memory the old code used to use a date in 1970 (epoch year) to calculate daylight saving offsets, etc This causes problems if the timezone information has changed between then and now. I know this was a problem for UK which was experimenting with daylight savings during 1970 and causes the calculations to be off. I'll dig into the code again when I have a minute to find out where this occurs and if it is in the JDK or the JDBC code. John On 26/10/2014 21:51, Vladimir Crnčić (Infoart d.o.o.) wrote: > > Well, the server and the client are on the same development Windows 7 > machine. I've done some testing using class in attachment and found > out that results depend on time zone and daylight saving settings, in > some zones results are always correct, in some are correct with > daylight saving turned off, in some with daylight saving turned on, > and so on. Obviously there's some problem with incoming binary data > or time zone compensation in TimestampUtils.toTimestampBin() > > if (!timestamptz) { > > if (tz == null) { > > tz = defaultTz; > > } > > millis -= tz.getOffset(millis); > > } > > I don't really understand why this compensation is needed in the first > place, conversion in TimestampUtils.toTimestamp() takes no time zone > in account with TIMESTAMP type. Anyway, getting different results > depending on data transfer type is unacceptable. > > *From:*John Lister [mailto:john.lister@kickstone.com] > *Sent:* Saturday, October 25, 2014 10:26 PM > *To:* Dave Cramer; Vladimir Crnčić (Infoart d.o.o.) > *Cc:* List > *Subject:* Re: [JDBC] TIMESTAMP value binary transfer problem > > There was a problem with some time zones from memory, in the uk for > example 1970 had an odd daylight saving period and because 1970 is > used in calculating the time values in the driver this skews the > results in the driver. Using the current year fixes it when > calculating times. > > Maybe something to check. > > On 25 October 2014 19:21:25 GMT+01:00, Dave Cramer > wrote: > > This is the same as https://github.com/pgjdbc/pgjdbc/pull/133 > > So what I am wondering is why a small number of people see this > and the rest are fine ??? > > What is unique about your environment. Are the server and the > client on the same timezone ? > > > Dave Cramer > > dave.cramer(at)credativ(dot)ca > http://www.credativ.ca > > On 22 October 2014 14:03, Vladimir Crnčić (Infoart d.o.o.) > > wrote: > > There is a problem with JDBS driver interpretation of > "timestamp without time zone" values when binary transfer is > on. When binary transfer is disabled for TIMESTAMP columns > (binaryTransferDisable=TIMESTAMP or binaryTransfer=false) > problem does not occur. > > database version: 9.1.1 > > driver version: 9.2, 9.3 > > BINARY TRANSFER: > > ---------------- > > database value (TIMESTAMP): 2014-10-26 01:00:04 > > bytes (AbstractJdbc2Resultset): [0, 1, -87, 71, > -77, -6, 45, 0] > > long value (TimestampUtils): 467600404000000 > > java timestamp (TimestampUtils): 2014-10-26 > 02:00:04.0 (not OK) > > TEXT TRANSFER: > > -------------- > > database value (TIMESTAMP): > 2014-10-26 01:00:04 > > string value (AbstractJdbc2Resultset): 2014-10-26 01:00:04 > > java timestamp (TimestampUtils): > 2014-10-26 01:00:04.0 (OK) > > > -- > Sent from my Android device with K-9 Mail. Please excuse my brevity. > > > --------------070301030102030007020508 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit You are right it is related to timezones and daylight saving. I haven't looked through the recent code, but from memory the old code used to use a date in 1970 (epoch year) to calculate daylight saving offsets, etc This causes problems if the timezone information has changed between then and now. I know this was a problem for UK which was experimenting with daylight savings during 1970 and causes the calculations to be off. I'll dig into the code again when I have a minute to find out where this occurs and if it is in the JDK or the JDBC code.

John
On 26/10/2014 21:51, Vladimir Crnčić (Infoart d.o.o.) wrote:

Well, the server and the client are on the same development Windows 7 machine. I've done some testing using class in attachment and found out that results depend on time zone and daylight saving settings, in some zones results are always correct, in some are correct with daylight saving turned off, in some with daylight saving turned on, and so on.  Obviously there's some problem with incoming binary data or time zone compensation in TimestampUtils.toTimestampBin()

 

                               if (!timestamptz) {

                                               if (tz == null) {

                                                               tz = defaultTz;

                                               }

                                               millis -= tz.getOffset(millis);

                               }

 

I don't really understand why this compensation is needed in the first place, conversion in TimestampUtils.toTimestamp() takes no time zone in account with TIMESTAMP type. Anyway, getting different results depending on data transfer type is unacceptable.

 

 

From: John Lister [mailto:john.lister@kickstone.com]
Sent: Saturday, October 25, 2014 10:26 PM
To: Dave Cramer; Vladimir Crnčić (Infoart d.o.o.)
Cc: List
Subject: Re: [JDBC] TIMESTAMP value binary transfer problem

 

There was a problem with some time zones from memory, in the uk for example 1970 had an odd daylight saving period and because 1970 is used in calculating the time values in the driver this skews the results in the driver. Using the current year fixes it when calculating times.

Maybe something to check.

On 25 October 2014 19:21:25 GMT+01:00, Dave Cramer <pg@fastcrypt.com> wrote:

This is the same as https://github.com/pgjdbc/pgjdbc/pull/133

 

So what I am wondering is why a small number of people see this and the rest are fine ???

 

What is unique about your environment. Are the server and the client on the same timezone ?


Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

 

On 22 October 2014 14:03, Vladimir Crnčić (Infoart d.o.o.) <vcrncic@infoart.hr> wrote:

There is a problem with JDBS driver interpretation of "timestamp without time zone" values when binary transfer is on. When binary transfer is disabled for TIMESTAMP columns (binaryTransferDisable=TIMESTAMP or binaryTransfer=false) problem does not occur.

 

database version: 9.1.1

driver version: 9.2, 9.3

 

BINARY TRANSFER:

----------------

database value (TIMESTAMP):                 2014-10-26 01:00:04

bytes (AbstractJdbc2Resultset):              [0, 1, -87, 71, -77, -6, 45, 0]

long value (TimestampUtils):                    467600404000000

java timestamp (TimestampUtils):          2014-10-26 02:00:04.0                   (not OK)

 

TEXT TRANSFER:

--------------

database value (TIMESTAMP):                                 2014-10-26 01:00:04

string value (AbstractJdbc2Resultset):                 2014-10-26 01:00:04

java timestamp (TimestampUtils):                         2014-10-26 01:00:04.0    (OK)

 


--
Sent from my Android device with K-9 Mail. Please excuse my brevity.




    

--------------070301030102030007020508--