You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "jayzhan211 (via GitHub)" <gi...@apache.org> on 2026/09/24 12:38:11 UTC
Re: [I] coalesce(Int, Utf8) coerces to Int [datafusion]
jayzhan211 commented on issue #23045:
URL: https://github.com/apache/datafusion/issues/23045#issuecomment-5814261594
Closing as working as intended. DataFusion follows Postgres/DuckDB here: in `COALESCE`, a string literal next to a numeric argument resolves to the numeric type, so the result type is `Int64`:
```sql
SELECT coalesce(1, '5'); -- 1, Int64
SELECT coalesce(bigint_col, '0') + 1; -- numeric arithmetic works
SELECT coalesce(1, ''); -- error: Cannot cast string '' to value of Int64 type
```
The last one fails because `''` isn't a valid integer, which is the same result as in Postgres. If you want a string result, cast explicitly: `coalesce(CAST(1 AS VARCHAR), '')`.
Typing it as a string (#23225) would break the second query and change VALUES / `make_array` / array functions, which share the same coercion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org