Julian, thanks !

mysql differs here:
mysql> SELECT LENGTH(a) from (SELECT COALESCE('a', 'bbbb') as a) as t;
+-----------+
| LENGTH(a) |
+-----------+
|         1 |
+-----------+

mysql> SELECT LENGTH(a) from (SELECT COALESCE('aa', 'bbbb') as a) as t;
+-----------+
| LENGTH(a) |
+-----------+
|         2 |
+-----------+

I don`t claim that calcite need to be the same, i just want to understand what is correct. My point of view - if COALESCE transforms into CASE-WHEN statement and returns first not null it strange instead of expected 'a' gets 'a '.
I`m wrong ?

The current behavior looks ok to me. The expression has type CHAR(2) because the arguments have types CHAR(1) and CHAR(2). So ‘a’ is widened to ‘a ‘.

Julian

On Sep 22, 2021, at 12:00 AM, stanilovsky evgeny <estanilovs...@gridgain.com> wrote:

sorry for typo, 'fill the ticket' of course ))

hi community !
I found that COALESCE('a', 'bb') will return 'a ' <-- whitespace is present, i found that now it expands for maximum presented CHAR (RelDataType#inferReturnType logic)
sql 92 standard tolds:

'''
COALESCE (V1, V2) is equivalent to the following <case specification>:
CASE WHEN V1 IS NOT NULL THEN V1 ELSE V2 END
'''

So i suppose that existing behavior is erroneous, if it`s ok i fell the ticket.

wdyt ?

Reply via email to