Message-ID: From: "marschall (@marschall)" To: "pgjdbc/pgjdbc" Date: Fri, 16 Nov 2018 17:30:33 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #1325: Additional jsr 310 support In-Reply-To: References: List-Id: X-GitHub-Author-Login: marschall X-GitHub-Comment-Id: 439467466 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 1325 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/1325#issuecomment-439467466 Content-Type: text/plain; charset=utf-8 > Timestamp as a data type is not bound the the jvm time zone. Unfortunately it is. Consider the following code: ```java LocalDateTime localDateTime = LocalDateTime.of(2018, 11, 16, 18, 2); TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); Instant instant1 = Timestamp.valueOf(localDateTime).toInstant(); long epochMilli1 = instant1.toEpochMilli(); TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); Instant instant2 = Timestamp.valueOf(localDateTime).toInstant(); long epochMilli2 = instant2.toEpochMilli(); System.out.printf("epochMilli1: %d%n", epochMilli1); System.out.printf("epochMilli2: %d%n", epochMilli2); System.out.println("same instant: " + instant1.equals(instant2)); ``` Which prints ``` epochMilli1: 1542420120000 epochMilli2: 1542409320000 same instant: false ``` As you can see the time java.sql.Timestamp -> java.time.Instant conversion depends on the JVM default time zone. This becomes quite dramatic when a user does something like this on a TIMESTAMP column: ```java OffsetDateTime.ofInstant(resultSet.getObject(1, Instant.class), ZoneOffset.UTC); ``` > I certainly understand that there are challenges with the TIMESTAMP datatype and that users should be encouraged to use TIMESTAMPTZ. But should this project "force" that by limiting the support for TIMESTAMP with the introduction of new data types? Ultimately the project needs to decide. You'll have to explain to users anyway that in order for what they want to work correctly they will have to switch data types. You can only chose if the trigger is either a reproducible exception that always happens and informs them about incompatible data types or a rare and hard to reproduce bug in production that may have already cased data corruption.