DSLContext create = DSL.using(connection);
create.select(DSL.function(
"timezone",
Time.class,
DSL.val("Asia/Hong_Kong"),
DSL.val(new java.sql.Timestamp(
java.time.LocalDateTime.of(2016, 5, 23, 17, 0)
.toInstant(ZoneOffset.UTC)
.toEpochMilli())))
.cast(PostgresDataType.TIMEWITHOUTTIMEZONE))
.execute();
create.select(DSL.function(
"timezone",
java.sql.Time.class,
DSL.val("Asia/Hong_Kong"),
DSL.val(java.time.OffsetDateTime.ofInstant(
Instant.ofEpochMilli(
java.time.LocalDateTime.of(2016, 5, 23, 17, 0)
.toInstant(ZoneOffset.UTC)
.toEpochMilli()),
java.time.ZoneId.of("UTC"))))
.cast(PostgresDataType.TIMEWITHOUTTIMEZONE))
.execute();
Executing query : select cast(timezone(?, cast(? as timestamp with time zone)) as time without time zone)-> with bind values : select cast(timezone('Asia/Hong_Kong', cast('2016-05-23T17:00Z' as timestamp with time zone)) as time without time zone)+--------+|cast |+--------+|01:00:00|+--------+
Hello,I've found (undocumented?) change of behavior of DSL.val(java.sql.Timestamp).Tested on PostgreSQL 9.4/9.5 running in UTC timezone, JVM process running in UTC default timezone too.Here's the query:DSLContext create = DSL.using(connection);
create.select(DSL.function(
"timezone",
Time.class,
DSL.val("Asia/Hong_Kong"),
DSL.val(new java.sql.Timestamp(
java.time.LocalDateTime.of(2016, 5, 23, 17, 0)
.toInstant(ZoneOffset.UTC)
.toEpochMilli())))
.cast(PostgresDataType.TIMEWITHOUTTIMEZONE))
.execute();
with jOOQ 3.6.2 it generates this (correct result):Executing query : select cast(timezone(?, ?) as time without time zone)-> with bind values : select cast(timezone('Asia/Hong_Kong', timestamp '2016-05-23 17:00:00.0') as time without time zone)+--------+|cast |+--------+|01:00:00|+--------+same query with jOOQ 3.8.1 (wrong result):Executing query : select cast(timezone(?, cast(? as timestamp)) as time without time zone)-> with bind values : select cast(timezone('Asia/Hong_Kong', timestamp '2016-05-23 17:00:00.0') as time without time zone)+--------+|cast |+--------+|09:00:00|+--------+
Debug output of both generated SQL queries looks the same,
but it doesn't seem as this is the ones being executed, because results are different.This query is wrong:select cast(timezone('Asia/Hong_Kong', timestamp '2016-05-23 17:00:00.0') as time without time zone)
This is the right query:select cast(timezone('Asia/Hong_Kong', '2016-05-23 17:00:00.0') as time without time zone);
or this (gives the same result):select cast(timezone('Asia/Hong_Kong', cast('2016-05-23 17:00:00.0' as timestamp with time zone)) as time without time zone);
To get the latter query I had to rewrite above jOOQ query like this:create.select(DSL.function(
"timezone",
java.sql.Time.class,
DSL.val("Asia/Hong_Kong"),
DSL.val(java.time.OffsetDateTime.ofInstant(
Instant.ofEpochMilli(
java.time.LocalDateTime.of(2016, 5, 23, 17, 0)
.toInstant(ZoneOffset.UTC)
.toEpochMilli()),
java.time.ZoneId.of("UTC"))))
.cast(PostgresDataType.TIMEWITHOUTTIMEZONE))
.execute();Executing query : select cast(timezone(?, cast(? as timestamp with time zone)) as time without time zone)-> with bind values : select cast(timezone('Asia/Hong_Kong', cast('2016-05-23T17:00Z' as timestamp with time zone)) as time without time zone)+--------+|cast |+--------+|01:00:00|+--------+
Hello Dmitry,Thank you very much for your detailed E-Mail. I will comment inline.2016-05-23 21:44 GMT+02:00 Dmitry Gusev <dmitry...@gmail.com>:Hello,I've found (undocumented?) change of behavior of DSL.val(java.sql.Timestamp).Tested on PostgreSQL 9.4/9.5 running in UTC timezone, JVM process running in UTC default timezone too.Here's the query:DSLContext create = DSL.using(connection);
create.select(DSL.function(
"timezone",
Time.class,
DSL.val("Asia/Hong_Kong"),
DSL.val(new java.sql.Timestamp(
java.time.LocalDateTime.of(2016, 5, 23, 17, 0)
.toInstant(ZoneOffset.UTC)
.toEpochMilli())))
.cast(PostgresDataType.TIMEWITHOUTTIMEZONE))
.execute();Just to be sure to get the full picture: Is there any reason for this conversion chain? Why not Timestamp.valueOf(LocalDateTime.of(...)) ?
with jOOQ 3.6.2 it generates this (correct result):Executing query : select cast(timezone(?, ?) as time without time zone)-> with bind values : select cast(timezone('Asia/Hong_Kong', timestamp '2016-05-23 17:00:00.0') as time without time zone)+--------+|cast |+--------+|01:00:00|+--------+same query with jOOQ 3.8.1 (wrong result):Executing query : select cast(timezone(?, cast(? as timestamp)) as time without time zone)-> with bind values : select cast(timezone('Asia/Hong_Kong', timestamp '2016-05-23 17:00:00.0') as time without time zone)+--------+|cast |+--------+|09:00:00|+--------+But that cast, which is generated by jOOQ seems to be correct, no? After all, you're binding a java.sql.Timestamp, which corresponds to the SQL TIMESTAMP data type. Temporal casts are sometimes necessary in PostgreSQL in order to correctly disambiguate the types.
If you want to stay in control of your bind variables, you could use an org.jooq.Binding.
--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/oX5QooSuWUo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
As for bindings... I don't remember I saw any examples how to use them for adhoc queries like this. Is there any examples?
You can now use the above with val():DataType<OffsetDateTime> type = SQLDataType.TIMESTAMP.asConvertedDataType(new MyBinding());
DSL.val(mydate, type);
Now, the question is why this worked for you before. Perhaps by accident?That's exactly my question :)It worked because I built the query to do exactly what I needed, it wasn't an accident.I was doing some TDD experimenting with jOOQ 3.6.2.Lucky that I created a test for it and that test caught this change in behavior after I upgraded to the latest jOOQ (3.8.1).Note that I didn't touch any java code at all during the upgrade.Then I found the overload for OffsetDateTime and it magically worked.So I was just wondering if the change was intentional or not, because I couldn't find any mentions of that in the documentation.
--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/oX5QooSuWUo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.