jOOQ returns offset date time as Z (UTC) even though it's not

时光毁灭记忆、已成空白 提交于 2019-12-02 00:55:59

This is not a jOOQ issue. PostgreSQL doesn't have a data type that corresponds to ZonedDateTime. Its TIMESTAMPTZ or TIMESTAMP WITH TIME ZONE type is really just a java.time.Instant. Consider the manual: https://www.postgresql.org/docs/current/datatype-datetime.html

For timestamp with time zone, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone. If no time zone is stated in the input string, then it is assumed to be in the time zone indicated by the system's TimeZone parameter, and is converted to UTC using the offset for the timezone zone.

There's nothing jOOQ can do here for you.

Do note that jOOQ defaults to mapping TIMESTAMP WITH TIME ZONE types in all SQL databases to java.time.OffsetDateTime, because that's what the JDBC specification does. It is a reasonable default for a vendor agnostic API like JDBC (and jOOQ). But if you want to have PostgreSQL-native behaviour, I would recommend rewriting all of your TIMESTAMPTZ types to INSTANT (if you're using jOOQ 3.12+).

If, for some reason, you need to maintain this information, you will need to store it in a separate column, or a text column as the formatted value.

There is an incompatibility between the impossibl pgjdbc driver version 0.7.1 and jOOQ causing offsets not to be applied when selecting timestamp with timezone back out of a postgres database.

In the unlikely event that someone else is also running this combination of jars, recommend updating to pgjdbc 0.8.2 if the features in the impossibl driver are necessary or abandoning if not.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!