pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: marschall (@marschall) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #1325: Additional jsr 310 support
Date: Fri, 16 Nov 2018 17:30:33 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

> 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.



view thread (25+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #1325: Additional jsr 310 support
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox