Fix cast for pi function on MySQL 5.7

This commit is contained in:
Christian Beikov 2022-09-21 10:57:22 +02:00
parent aae3513d58
commit 6b8a782d50
1 changed files with 16 additions and 5 deletions

View File

@ -501,11 +501,22 @@ public class MySQLDialect extends Dialect {
.register();
// pi() produces a value with 7 digits unless we're explicit
functionRegistry.patternDescriptorBuilder( "pi", "cast(pi() as double)" )
.setInvariantType(basicTypeRegistry.resolve( StandardBasicTypes.DOUBLE ))
.setExactArgumentCount(0)
.setArgumentListSignature("")
.register();
if ( getMySQLVersion().isSameOrAfter( 8 ) ) {
functionRegistry.patternDescriptorBuilder( "pi", "cast(pi() as double)" )
.setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.DOUBLE ) )
.setExactArgumentCount( 0 )
.setArgumentListSignature( "" )
.register();
}
else {
// But before MySQL 8, it's not possible to cast to double. Double has a default precision of 53
// and since the internal representation of pi has only 15 decimal places, we cast to decimal(53,15)
functionRegistry.patternDescriptorBuilder( "pi", "cast(pi() as decimal(53,15))" )
.setInvariantType( basicTypeRegistry.resolve( StandardBasicTypes.DOUBLE ) )
.setExactArgumentCount( 0 )
.setArgumentListSignature( "" )
.register();
}
// By default char() produces a binary string, not a character string.
// (Note also that char() is actually a variadic function in MySQL.)