Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/expr/src/scalar/func/impls/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ fn round_numeric(mut a: Numeric) -> Numeric {
return a;
}
numeric::cx_datum().round(&mut a);
// Canonicalize: `dec`'s round preserves the sign on zero results, so e.g.
// `round(-0.4)` yields `-0`. munge_numeric strips that, ensuring row
// encodings match decimal equality.
numeric::munge_numeric(&mut a).unwrap();
a
}

Expand Down
27 changes: 27 additions & 0 deletions test/sqllogictest/numeric.slt
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,33 @@ SELECT round (-0.10212864, -900)
----
0

# Rounding a small negative numeric to zero must canonicalize away the sign
# bit; otherwise the result is `-0`, which renders incorrectly via the text
# cast and survives as a distinct row encoding from `0`.
query T
SELECT round(-0.4::numeric)::text
----
0

query T
SELECT round(-0.49::numeric, 0)::text
----
0

query T
SELECT round(-0.000001::numeric, 2)::text
----
0

query T
SELECT v::text FROM (
SELECT round(-0.4::numeric) AS v
UNION
SELECT 0::numeric
) t
----
0

# ceil

query RRR
Expand Down
Loading