diff --git a/pkg/sql/logictest/testdata/logic_test/builtin_function b/pkg/sql/logictest/testdata/logic_test/builtin_function index 6c4d6ed33ff7..e587e13ea075 100644 --- a/pkg/sql/logictest/testdata/logic_test/builtin_function +++ b/pkg/sql/logictest/testdata/logic_test/builtin_function @@ -1187,10 +1187,10 @@ SELECT round(123.456::float, -1), round(123.456::float, -2), round(123.456::floa ---- 120 100 0 -query RRRR -SELECT round(123.456::decimal, -1), round(123.456::decimal, -2), round(123.456::decimal, -3), round(123.456::decimal, -200) +query RRRRR +SELECT round(123.456::decimal, -1), round(123.456::decimal, -2), round(123.456::decimal, -3), round(123.456::decimal, -200), round(-0.1::decimal) ---- -1.2E+2 1E+2 0E+3 0E+200 +1.2E+2 1E+2 0E+3 0E+200 0 query RRRR SELECT round('nan'::decimal), round('nan'::decimal, 1), round('nan'::float), round('nan'::float, 1) diff --git a/pkg/sql/sem/builtins/math_builtins.go b/pkg/sql/sem/builtins/math_builtins.go index 6756bc3d8f2e..cfd038b7a3cd 100644 --- a/pkg/sql/sem/builtins/math_builtins.go +++ b/pkg/sql/sem/builtins/math_builtins.go @@ -769,6 +769,9 @@ func roundDDecimal(d *tree.DDecimal, scale int32) (tree.Datum, error) { func roundDecimal(x *apd.Decimal, scale int32) (tree.Datum, error) { dd := &tree.DDecimal{} _, err := tree.HighPrecisionCtx.Quantize(&dd.Decimal, x, -scale) + if dd.IsZero() { + dd.Negative = false + } return dd, err }