Skip to content

Commit c81bed2

Browse files
committed
Use server-side zeros trim instead of hinted precision and scale
For expressions as columns we cast to decimal first because there is a chance it should be done because there is internal cast to decimal and this is the reason that result type of column is decimal, For simple column expressions we probably don't need cast, just trim
1 parent 01581a0 commit c81bed2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ internal class SqlCompiler : Providers.SqlCompiler
2121
{
2222
private const int MaxDotnetDecimalPrecision = 28;
2323

24+
private readonly bool canRemoveInsignificantZerosInDecimal;
25+
2426
protected override SqlProvider VisitFreeText(FreeTextProvider provider)
2527
{
2628
var rankColumnName = provider.Header.Columns[provider.Header.Columns.Count - 1].Name;
@@ -61,6 +63,11 @@ protected override SqlExpression ProcessAggregate(SqlProvider source, List<SqlEx
6163
var aggregateType = aggregateColumn.AggregateType;
6264
var originCalculateColumn = source.Origin.Header.Columns[aggregateColumn.SourceIndex];
6365
if (AggregateRequiresDecimalAdjustments(aggregateColumn)) {
66+
if (canRemoveInsignificantZerosInDecimal) {
67+
return (IsCalculatedColumn(originCalculateColumn))
68+
? PostgresqlSqlDml.DecimalTrimScale(SqlDml.Cast(result, Driver.MapValueType(aggregateColumn.Type)))
69+
: PostgresqlSqlDml.DecimalTrimScale(result);
70+
}
6471
if (!IsCalculatedColumn(originCalculateColumn)) {
6572
// this is aggregate by one column, result will be defined by the precision and scale of the column
6673
return result;
@@ -138,6 +145,7 @@ AggregateType.Min or
138145
public SqlCompiler(HandlerAccessor handlers, CompilerConfiguration configuration)
139146
: base(handlers, configuration)
140147
{
148+
canRemoveInsignificantZerosInDecimal = handlers.ProviderInfo.StorageVersion.Major >= 13;
141149
}
142150
}
143151
}

0 commit comments

Comments
 (0)