Skip to content

[Decimal] String -> Decimal with exponent not always correctly rounded #5392

@Tishj

Description

@Tishj

What happens?

As mentioned in #5362

Because of the limited size of the physical type of a DECIMAL, sometimes we don't have enough room to hold enough information to properly round later on.

To elaborate:

We register the exceeding decimals, because depending on the exponent (which we don't know at that time) those decimal values might become digit values instead.
But if the source value has more decimals than the physical type of the decimal can hold, we can't register them - which might become a problem depending on the exponent.
Example: (4 width is the max for physical type SMALLINT)

select '1.2345e2'::DECIMAL(4,1);
-- psql
123.5
-- duckdb
123.4

To Reproduce

query I
select '1.2345e2'::DECIMAL(4,1);
----
123.5

Current result is 123.4

OS:

MacOS

DuckDB Version:

master

DuckDB Client:

unittest

Full Name:

Thijs Bruineman

Affiliation:

DuckDB Labs

Have you tried this on the latest master branch?

  • I agree

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • I agree

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions