Skip to content

Commit 60d2b69

Browse files
committed
rework interval/datetime arithmetic on Informix
change the NATIVE precision to seconds
1 parent ad1b257 commit 60d2b69

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,7 @@ public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType,
701701
private static String intervalPattern(TemporalUnit unit, TemporalType temporalType) {
702702
return switch (unit) {
703703
case NANOSECOND -> "?2/1e9 * interval (1) second(9) to fraction";
704-
case NATIVE -> "?2/1e3 * interval (1) second(9) to fraction"; // millis
705-
case SECOND ->
704+
case SECOND, NATIVE ->
706705
temporalType == TemporalType.TIME
707706
? "?2 * 1 units second" // times don't usually come equipped with fractional seconds
708707
: "?2 * interval (1) second(9) to fraction"; // datetimes do have fractional seconds
@@ -714,9 +713,13 @@ private static String intervalPattern(TemporalUnit unit, TemporalType temporalTy
714713

715714
@Override
716715
public long getFractionalSecondPrecisionInNanos() {
717-
// Informix actually supports up to 10 microseconds
718-
// but defaults to milliseconds (so use that)
719-
return 1_000_000;
716+
// since we do computations with intervals,
717+
// may as well just use seconds as the NATIVE
718+
// precision, do minimize conversion factors
719+
return 1_000_000_000;
720+
// // Informix actually supports up to 10 microseconds
721+
// // but defaults to milliseconds (so use that)
722+
// return 1_000_000;
720723
}
721724

722725
@Override @SuppressWarnings("deprecation")
@@ -729,8 +732,8 @@ public String timestampdiffPattern(TemporalUnit unit, TemporalType fromTemporalT
729732
case NATIVE ->
730733
fromTemporalType == TemporalType.TIME
731734
// arguably, we don't really need to retain the milliseconds for a time, since times don't usually come with millis
732-
? "((mod(to_number(cast(cast(sum(?3-?2) as interval second(6) to second) as varchar(9))),86400)+to_number(cast(cast(sum(?3-?2) as interval fraction to fraction) as varchar(6))))*1e3)"
733-
: "((to_number(cast(cast(sum(?3-?2) as interval day(9) to day) as varchar(12)))*86400+mod(to_number(cast(cast(sum(?3-?2) as interval second(6) to second) as varchar(9))),86400)+to_number(cast(cast(sum(?3-?2) as interval fraction to fraction) as varchar(6))))*1e3)";
735+
? "(mod(to_number(cast(cast(sum(?3-?2) as interval second(6) to second) as varchar(9))),86400)+to_number(cast(cast(sum(?3-?2) as interval fraction to fraction) as varchar(6))))"
736+
: "(to_number(cast(cast(sum(?3-?2) as interval day(9) to day) as varchar(12)))*86400+mod(to_number(cast(cast(sum(?3-?2) as interval second(6) to second) as varchar(9))),86400)+to_number(cast(cast(sum(?3-?2) as interval fraction to fraction) as varchar(6))))";
734737
case SECOND -> "to_number(cast(cast(sum(?3-?2) as interval second(9) to fraction) as varchar(15)))";
735738
case NANOSECOND -> "(to_number(cast(cast(sum(?3-?2) as interval second(9) to fraction) as varchar(15)))*1e9)";
736739
default -> "to_number(cast(cast(sum(?3-?2) as interval ?1(9) to ?1) as varchar(12)))";

0 commit comments

Comments
 (0)