alamb opened a new issue #1609:
URL: https://github.com/apache/arrow-datafusion/issues/1609


   As we found on #1601, the return type of a `CASE` statement is currently 
based on the `THEN` clause. One problem with this this logic is that it may 
cause a cast (e.g.  `float64` to `int`) that loses accuracy.  
   
   The goal of this ticket would be to compute the return type of a case 
statement by applying coercion rules to the various clauses. 
   
   
   @xudong963 found that Postgres' behavior is  reasonable:
   
   ```sql
   postgres=# SELECT * FROM test;
    a
   ---
    1
    2
    3
   (3 rows)
   
   
   postgres=# SELECT a,
          CASE WHEN a=1 THEN 1.2
               ELSE 0
          END
       FROM test;
    a | case
   ---+------
    1 |  1.2
    2 |    0
    3 |    0
   (3 rows)
   
   
   postgres=# SELECT a,
          CASE WHEN a=1 THEN 12
               ELSE 5.4
          END
       FROM test;
    a | case
   ---+------
    1 |   12
    2 |  5.4
    3 |  5.4
   (3 rows)
   ```
   
   _Originally posted by @xudong963 in 
https://github.com/apache/arrow-datafusion/issues/1601#issuecomment-1015046138_


-- 
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