-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
Description
Describe the bug
The fix that corrected the decimal position spillover when parsing zero scale numbers also introduced another issue, which is that it always truncates the number instead of rounding it appropriately.
To Reproduce
The following test case fails, instead the parsed number is 1.
assert_eq!(
parse_decimal::<Decimal128Type>("1.9", 3, 0).unwrap(),
2,
);Expected behavior
It's not instantly clear that this should be the expected behavior in this case, but it would make sense to align with Postgres and DuckDB, where this is true
postgres@localhost:postgres> select '1.1'::numeric(3, 0), '1.9'::numeric(3, 0);
+---------+---------+
| numeric | numeric |
|---------+---------|
| 1 | 2 |
+---------+---------+D select '1.1'::numeric(3, 0), '1.9'::numeric(3, 0);
┌─────────────────────────────┬─────────────────────────────┐
│ CAST('1.1' AS DECIMAL(3,0)) │ CAST('1.9' AS DECIMAL(3,0)) │
│ decimal(3,0) │ decimal(3,0) │
├─────────────────────────────┼─────────────────────────────┤
│ 1 │ 2 │
└─────────────────────────────┴─────────────────────────────┘Additional context
Note that the behavior is as expected when the decimal part is less than .5, since truncation and rounding then match up.
Reactions are currently unavailable