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