fix for datetime subtraction on DB2

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-02 19:58:23 +02:00
parent 064526a5c6
commit ac40e37700
1 changed files with 13 additions and 5 deletions

View File

@ -476,7 +476,11 @@ public class DB2Dialect extends Dialect {
switch ( unit ) { switch ( unit ) {
case NATIVE: case NATIVE:
case NANOSECOND: case NANOSECOND:
pattern.append( "(seconds_between(" ); pattern.append( "(seconds_between(date_trunc('second'," );
pattern.append( toExpression );
pattern.append( "),date_trunc('second'," );
pattern.append( fromExpression );
pattern.append( "))" );
break; break;
//note: DB2 does have weeks_between() //note: DB2 does have weeks_between()
case MONTH: case MONTH:
@ -484,14 +488,18 @@ public class DB2Dialect extends Dialect {
// the months_between() function results // the months_between() function results
// in a non-integral value, so trunc() it // in a non-integral value, so trunc() it
pattern.append( "trunc(months_between(" ); pattern.append( "trunc(months_between(" );
pattern.append( toExpression );
pattern.append( ',' );
pattern.append( fromExpression );
pattern.append( ')' );
break; break;
default: default:
pattern.append( "?1s_between(" ); pattern.append( "?1s_between(" );
pattern.append( toExpression );
pattern.append( ',' );
pattern.append( fromExpression );
pattern.append( ')' );
} }
pattern.append( toExpression );
pattern.append( ',' );
pattern.append( fromExpression );
pattern.append( ')' );
switch ( unit ) { switch ( unit ) {
case NATIVE: case NATIVE:
pattern.append( "+(microsecond("); pattern.append( "+(microsecond(");