diff --git a/ChangeLog/7.1.6-dev.txt b/ChangeLog/7.1.6-dev.txt index e69de29bb..18dbe75a1 100644 --- a/ChangeLog/7.1.6-dev.txt +++ b/ChangeLog/7.1.6-dev.txt @@ -0,0 +1 @@ +[postgresql] For PostgreSQL 13+ apply 'trim_scale' function to results of aggregation to improve compatibility with .NET decimal \ No newline at end of file diff --git a/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/DomainHandler.cs b/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/DomainHandler.cs index c35579037..36a524e1c 100644 --- a/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/DomainHandler.cs +++ b/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/DomainHandler.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2008-2020 Xtensive LLC. +// Copyright (C) 2008-2025 Xtensive LLC. // This code is distributed under MIT license terms. // See the License.txt file in the project root for more information. // Created by: Alexey Gamzov @@ -18,6 +18,12 @@ namespace Xtensive.Orm.Providers.PostgreSql /// public class DomainHandler : Providers.DomainHandler { + /// + /// if storage can trim insignificant zeros in numeric values + /// + protected bool HasNativeTrimOfInsignificantZerosInDecimals => + Handlers.ProviderInfo.StorageVersion.Major >= 13; + /// protected override ICompiler CreateCompiler(CompilerConfiguration configuration) => new SqlCompiler(Handlers, configuration); @@ -25,8 +31,11 @@ protected override ICompiler CreateCompiler(CompilerConfiguration configuration) /// protected override IPreCompiler CreatePreCompiler(CompilerConfiguration configuration) { - var decimalAggregateCorrector = new AggregateOverDecimalColumnCorrector(Handlers.Domain.Model); - return new CompositePreCompiler(decimalAggregateCorrector, base.CreatePreCompiler(configuration)); + if (!HasNativeTrimOfInsignificantZerosInDecimals) { + var decimalAggregateCorrector = new AggregateOverDecimalColumnCorrector(Handlers.Domain.Model); + return new CompositePreCompiler(decimalAggregateCorrector, base.CreatePreCompiler(configuration)); + } + return base.CreatePreCompiler(configuration); } /// diff --git a/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/PostgresqlSqlDml.cs b/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/PostgresqlSqlDml.cs index 491524f94..174ba4dfe 100644 --- a/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/PostgresqlSqlDml.cs +++ b/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/PostgresqlSqlDml.cs @@ -1,10 +1,11 @@ -// Copyright (C) 2014-2020 Xtensive LLC. +// Copyright (C) 2014-2025 Xtensive LLC. // This code is distributed under MIT license terms. // See the License.txt file in the project root for more information. // Created by: Alena Mikshina // Created: 2014.05.06; using Xtensive.Core; +using Xtensive.Sql; using Xtensive.Sql.Dml; namespace Xtensive.Orm.Providers.PostgreSql @@ -16,6 +17,15 @@ namespace Xtensive.Orm.Providers.PostgreSql /// public class PostgresqlSqlDml { + /// + /// Creates an expression for native "trim_scale" function call. The function is supported starting from PostgreSQL 13 + /// + public static SqlExpression DecimalTrimScale(SqlExpression operand) + { + ArgumentValidator.EnsureArgumentNotNull(operand, nameof(operand)); + return SqlDml.FunctionCall("TRIM_SCALE", operand); + } + #region Spatial types /// diff --git a/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs b/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs index 18e5eec66..6de659947 100644 --- a/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs +++ b/Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2021 Xtensive LLC. +// Copyright (C) 2009-2025 Xtensive LLC. // This code is distributed under MIT license terms. // See the License.txt file in the project root for more information. // Created by: Denis Krjuchkov @@ -21,6 +21,8 @@ internal class SqlCompiler : Providers.SqlCompiler { private const int MaxDotnetDecimalPrecision = 28; + private readonly bool canRemoveInsignificantZerosInDecimals; + protected override SqlProvider VisitFreeText(FreeTextProvider provider) { var rankColumnName = provider.Header.Columns[provider.Header.Columns.Count - 1].Name; @@ -61,6 +63,11 @@ protected override SqlExpression ProcessAggregate(SqlProvider source, List= 13; } } }