[MDEV-21553] DATE(IFNULL(XXX, 0)) is not returning same result with different XXX Created: 2020-01-22 Updated: 2020-06-16 Resolved: 2020-06-12 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data types, Server |
| Affects Version/s: | 5.5, 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Eimantas | Assignee: | Alexander Barkov |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | upstream | ||
| Environment: |
Any |
||
| Issue Links: |
|
||||||||
| Description |
|
DATE(IFNULL(XXX, 0)) is not returning same result with different XXX
3rd column DATE(IFNULL(DATE(NULL), 0)) expected to be 0000-00-00 |
| Comments |
| Comment by Elena Stepanova [ 2020-01-22 ] | |||||||||||||||||||||||||||||||||||||||||
|
Reproducible on all of 5.5-10.5 and MySQL 5.6, 8.0 (didn't try other MySQL versions). | |||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2020-06-12 ] | |||||||||||||||||||||||||||||||||||||||||
|
This is not a bug. This expression:
returns a string '0'. Then the string '0' is converted to DATE, and gives NULL.
| |||||||||||||||||||||||||||||||||||||||||
| Comment by Eimantas [ 2020-06-12 ] | |||||||||||||||||||||||||||||||||||||||||
|
I know that DATE('0') is NULL, but there are no strings in examples provided. Why IFNULL(DATE(NULL),0) is '0' string? | |||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2020-06-13 ] | |||||||||||||||||||||||||||||||||||||||||
|
Historically all hybrid functions in MariaDB (and in MySQL), like:
resolve their return data type as VARCHAR. VARCHAR is the common datatype that can store both DATE and INT without data loss. The same happens with UNION:
If you need a different behaviour instead of this style automatic data type conversion, please use the explicit CAST operator. | |||||||||||||||||||||||||||||||||||||||||
| Comment by Eimantas [ 2020-06-13 ] | |||||||||||||||||||||||||||||||||||||||||
|
Thank you! That makes everything clear. "IFNULL(?, 0)" changing to "IFNULL(?, DATE(0))" and it works as expected: |