Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
findepi opened this issue Jan 24, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@findepi
Copy link
Member

findepi commented Jan 24, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant