mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 08:35:13 +00:00
fix the round() function on Postgres
for some dumb reason, round(x,n) doesn't accept a double on pg
This commit is contained in:
parent
f7d5bc857b
commit
2f08812187
@ -72,7 +72,6 @@
|
||||
|
||||
import jakarta.persistence.TemporalType;
|
||||
|
||||
import static org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers.useArgType;
|
||||
import static org.hibernate.type.SqlTypes.*;
|
||||
|
||||
/**
|
||||
@ -249,13 +248,9 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {
|
||||
functionFactory.leftRight_substrLength();
|
||||
functionFactory.characterLength_length( SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER );
|
||||
functionFactory.power_expLn();
|
||||
functionFactory.round_floor();
|
||||
functionFactory.bitLength_pattern( "length(?1)*8" );
|
||||
|
||||
queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "round", "floor(?1*1e?2+0.5)/1e?2")
|
||||
.setReturnTypeResolver( useArgType(1) )
|
||||
.setExactArgumentCount( 2 )
|
||||
.register();
|
||||
|
||||
queryEngine.getSqmFunctionRegistry().register(
|
||||
"concat",
|
||||
new CastingConcatFunction(
|
||||
|
@ -404,6 +404,7 @@ public void initializeFunctionRegistry(QueryEngine queryEngine) {
|
||||
|
||||
CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine);
|
||||
|
||||
functionFactory.round_floor(); //Postgres round(x,n) does not accept double
|
||||
functionFactory.cot();
|
||||
functionFactory.radians();
|
||||
functionFactory.degrees();
|
||||
@ -602,13 +603,9 @@ public boolean useInputStreamToInsertBlob() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for postgres bug #1453
|
||||
* <p/>
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getSelectClauseNullString(int sqlType) {
|
||||
// Workaround for postgres bug #1453
|
||||
return "null::" + getRawTypeName( sqlType );
|
||||
}
|
||||
|
||||
|
@ -1883,6 +1883,14 @@ public void power_expLn() {
|
||||
.register();
|
||||
}
|
||||
|
||||
public void round_floor() {
|
||||
functionRegistry.patternDescriptorBuilder( "round", "floor(?1*1e?2+0.5)/1e?2")
|
||||
.setReturnTypeResolver( useArgType(1) )
|
||||
.setExactArgumentCount( 2 )
|
||||
.setParameterTypes(NUMERIC, INTEGER)
|
||||
.register();
|
||||
}
|
||||
|
||||
public void square() {
|
||||
functionRegistry.namedDescriptorBuilder( "square" )
|
||||
.setExactArgumentCount( 1 )
|
||||
|
@ -282,6 +282,8 @@ public void testMathFunctions(SessionFactoryScope scope) {
|
||||
.list();
|
||||
session.createQuery("select ceiling(e.theDouble), floor(e.theDouble) from EntityOfBasics e")
|
||||
.list();
|
||||
session.createQuery("select round(e.theDouble, 2) from EntityOfBasics e")
|
||||
.list();
|
||||
session.createQuery("select round(cast(e.theDouble as BigDecimal), 3) from EntityOfBasics e")
|
||||
.list();
|
||||
assertThat( session.createQuery("select abs(-2)").getSingleResult(), is(2) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user