Skip to content

Coercion between floating point types and exact numeric types should result in floating point type as the common super type #14272

@findepi

Description

@findepi

Describe the bug

When coercing decimal with other numeric types, the result is always decimal.
However, when one of operands is floating point, the result should be float.
Floating point's range of possible values cannot be fit into a decimal. Also NaN and Infinity cannot be converted to a decimal.

To Reproduce

> SELECT arrow_typeof(a) FROM (SELECT '1'::float UNION ALL SELECT '1'::decimal(10)) t(a);
+-------------------+
| arrow_typeof(t.a) |
+-------------------+
| Decimal128(17, 7) |
| Decimal128(17, 7) |
+-------------------+
> SELECT '1'::decimal(10,0) = '1e99'::float;
Arrow error: Cast error: Cannot cast to Decimal128(17, 7). Overflowing on inf

Expected behavior

PostgreSQL

postgres=# SELECT pg_typeof(a) FROM (SELECT '1'::float UNION ALL SELECT '1'::decimal(10)) t(a);
    pg_typeof
------------------
 double precision
 double precision
postgres=# SELECT '1'::decimal(10,0) = '1e99'::float;
 ?column?
----------
 f

(Note: PostgreSQL's decimal can express NaN and Infinity)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions