-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Inconsistent type coercion rules with comparison expressions #2890
Comments
Postgres does not add implicit casts in any of these cases:
|
@alamb DataFusion is inconsistent with itself as to when it adds implicit conversions or not. I think it would be better to not have implicit conversions at all and keep everything explicit, and this seems to be Postgres' approach as well (and the opposite of Spark). What is your opinion on this? |
I think implict type conversions are needed to do many arithmetic operations (e.g. adding a float to a integer) and that postgres does add implicit type conversions. For example: alamb=# select cast(1 as smallint) + cast(2 as bigint);
?column?
----------
3
(1 row)
alamb=# select cast(1 as float) + cast(2 as bigint);
?column?
----------
3
(1 row)
Postgres also seems to add conversions from integers to string for certain operations alamb=# create table foo(i int, c varchar);
CREATE TABLE
alamb=# insert into foo values (1, 'foo');
INSERT 0 1
alamb=# insert into foo values (2, 'bar');
INSERT 0 1
alamb=# select i || c from foo;
?column?
----------
1foo
2bar
(2 rows)
However interestingly it does not seem to try and coerce constants: ERROR: invalid input syntax for type integer: "foo"
LINE 1: select 1 = 'foo';
^
alamb=# I suspect postgres doesn't the challenges of equality between strings and numeric values (e.g. you can't always do it losselessly) -- perhaps we should remove the automatic string coercion for equality? I think the code is |
But in general I agree that the type coercion in DataFusion could be improved and is likely not self consistent |
Describe the bug
I have a table with an int32 and a string column.
I can compare them with
=
and!=
and an implicit cast gets added, casting the int to a string.The explain for the
=
query showsCAST(c3@0 AS Utf8) = c4@1
.Note that Spark would cast the string to an int and not the int to a string, so I'm not sure if we are doing the right thing here.
If I use other comparison expressions I get an error instead.
This seems inconsistent.
To Reproduce
See above.
Expected behavior
Additional context
None
The text was updated successfully, but these errors were encountered: