alamb commented on issue #2890:
URL: 
https://github.com/apache/arrow-datafusion/issues/2890#issuecomment-1183077551

   @andygrove  
   
   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:
   
   ```sql
   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 
   
   ```sql
   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:
   
   ```shell
   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
   
https://github.com/apache/arrow-datafusion/blob/6e0bb8476d783c1caaf6bf011487c92ae9352f78/datafusion/expr/src/binary_rule.rs#L167


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to