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

后端 未结 2 1876
盖世英雄少女心
盖世英雄少女心 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.

提交回复
热议问题