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

后端 未结 2 1877
盖世英雄少女心
盖世英雄少女心 2021-01-23 02:33

I have a simple Postgres test table of id, timestamp with timezone. The test and output below should be self explanatory, but to summarize, I insert a row that has a timestamp

相关标签:
2条回答
  • 2021-01-23 03:10

    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.

    0 讨论(0)
  • 2021-01-23 03:29

    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.

    0 讨论(0)
提交回复
热议问题