Bug #115145 | MySQL seems to lose precision when adding dates | ||
---|---|---|---|
Submitted: | 28 May 2024 2:07 | Modified: | 28 May 2024 9:57 |
Reporter: | Wenqian Deng | 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 |
[28 May 2024 2:07]
Wenqian Deng
[28 May 2024 9:57]
MySQL Verification Team
Hi Mr. Deng, Thank you for your bug report. However, this is not a bug. The function that you used can be applied only to DATE and DATETIME types. Next, you have mixed incompatible datatypes in your query. According to SQL Standard, such query should just return a very short error code. MySQL tries to do more by adopting the intermediary data type for two incompatible data types. That is a very good reason why you the result that you get. Not a bug.
[28 May 2024 9:58]
MySQL Verification Team
Mr. Deng, In short, TEXT is not a data type that is equivalent to the DATE type.
[29 May 2024 6:32]
Roy Lyseng
MySQL cannot see that the first argument is a datetime value without inspecting the first argument to DATE_ADD(), which is a character string. You can tell that the value is actually a datetime by using a CAST: SELECT DATE_ADD(CAST(t0.c_0 AS DATETIME(6)), INTERVAL t0.c_1 DAY) FROM t0;
[29 May 2024 10:27]
MySQL Verification Team
Thank you, Roy.