File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
hibernate-core/src/main/java/org/hibernate/dialect Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -501,11 +501,22 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {
501
501
.register ();
502
502
503
503
// pi() produces a value with 7 digits unless we're explicit
504
- functionRegistry .patternDescriptorBuilder ( "pi" , "cast(pi() as double)" )
505
- .setInvariantType (basicTypeRegistry .resolve ( StandardBasicTypes .DOUBLE ))
506
- .setExactArgumentCount (0 )
507
- .setArgumentListSignature ("" )
508
- .register ();
504
+ if ( getMySQLVersion ().isSameOrAfter ( 8 ) ) {
505
+ functionRegistry .patternDescriptorBuilder ( "pi" , "cast(pi() as double)" )
506
+ .setInvariantType ( basicTypeRegistry .resolve ( StandardBasicTypes .DOUBLE ) )
507
+ .setExactArgumentCount ( 0 )
508
+ .setArgumentListSignature ( "" )
509
+ .register ();
510
+ }
511
+ else {
512
+ // But before MySQL 8, it's not possible to cast to double. Double has a default precision of 53
513
+ // and since the internal representation of pi has only 15 decimal places, we cast to decimal(53,15)
514
+ functionRegistry .patternDescriptorBuilder ( "pi" , "cast(pi() as decimal(53,15))" )
515
+ .setInvariantType ( basicTypeRegistry .resolve ( StandardBasicTypes .DOUBLE ) )
516
+ .setExactArgumentCount ( 0 )
517
+ .setArgumentListSignature ( "" )
518
+ .register ();
519
+ }
509
520
510
521
// By default char() produces a binary string, not a character string.
511
522
// (Note also that char() is actually a variadic function in MySQL.)
You can’t perform that action at this time.
0 commit comments