Bug #112102 | The ifnull function query result is not as expected | ||
---|---|---|---|
Submitted: | 18 Aug 2023 1:48 | Modified: | 20 Aug 2023 12:35 |
Reporter: | Sakurajima Mai | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Data Types | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[18 Aug 2023 1:48]
Sakurajima Mai
[18 Aug 2023 13:16]
MySQL Verification Team
Hi Mr. Mai, Thank you for your bug report. We have managed to repeat the behaviour that you reported. We first ran a SELECT on the row and then the SELECT with IFNULL() function. We have got this: date_col time_col 1000-01-01 00:00:00 ifnull(time_col,date_col) 2023-08-18 00:00:00 We have repeated your results with latest 8.0 and 8.1. This is definitely wrong behaviour. This is now a verified bug report for the latest 8.0 and 8.1.
[20 Aug 2023 12:35]
Roy Lyseng
Posted by developer: This is correct behavior. When IFNULL is called with two temporal arguments, the result type is calculated as a common temporal type. When the two arguments are TIME and DATE, the common type is DATETIME. Thus the return value is the time value extended with the value of CURRENT_DATE. If you want the result as a character string, try this statement: select ifnull(cast(time_col as char),date_col) from t1; When one argument is character string, the result is also a character string.