I'm in a GMT+1 timezone, and I have a UTC timestamp (11:12:56) in a long
variable.
long ts = 1487157176450;
I initialize a java.sql.Timestamp
from this timestamp.
Timestamp timestamp = new Timestamp(ts);
Then, I insert this timestamp into a PostgreSQL (v9.4) database using jOOQ.
create.insertInto(TABLE,
TABLE.NAME, TABLE.TS)
.values("Foo bar", timestamp);
However, when I've logged the actual SQL commands executed, I saw this:
< 2017-02-15 10:50:37.326 CET >LOG: execute <unnamed>: insert into "database"."table" ("name", "ts") values ($1, cast($2 as timestamp))
< 2017-02-15 10:50:37.326 CET >DETAIL: parameters: $1 = 'Foo bar', $2 = '2017-02-15 12:12:56.450'
I'm not entirely sure where did the timestamp get turned into a local one, but unless pgAdmin lies, I actually do store GMT+1 timestamps in the database instead of the UTC I intended.
Now as I am not using JDBC, the answer to the linked question isn't helpful. How do I make jOOQ store the right timestamp?