Skip to content

trunc(decimal) produces unexpected/wrong results above 2^53 #22512

Description

@neilconway

Describe the bug

There is actually no implementation of trunc for decimal inputs, so we coerce the input to floating point. This yields incorrect/unexpected results for inputs above 2^53.

To Reproduce

> select trunc(CAST(9007199254740993 AS DECIMAL(20,0)));
+--------------------------------+
| trunc(Int64(9007199254740993)) |
+--------------------------------+
| 9007199254740992.0             |
+--------------------------------+
1 row(s) fetched.
Elapsed 0.011 seconds.

Expected behavior

The query should return 9007199254740993, which is what Postgres and DuckDB both do.

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions