-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GREATEST function with plus operations to time/date type gives wrong result. #30264
Comments
related to #29498 |
more issues with DATE/DATETIME comparison using LEAST()/GREATEST() functions: set sql_mode = default;
select least(cast('01-01-01' as date), '01-01-02') as a,
greatest(cast('01-01-01' as date), '01-01-02') as b,
least(cast('01-01-01' as date), '01-01-02') + 0 as c,
greatest(cast('01-01-01' as date), '01-01-02') + 0 as d,
least(cast('01-01-01' as datetime), '01-01-02') + 0 as e,
cast(least(cast('01-01-01' as datetime), '01-01-02') as signed) as f,
cast(least(cast('01-01-01' as datetime), '01-01-02') as decimal(16,2)) as g;
---mysql 5.7:
+------------+----------+----------+----------+----------------+----------------+-------------------+
| a | b | c | d | e | f | g |
+------------+----------+----------+----------+----------------+----------------+-------------------+
| 2001-01-01 | 01-01-02 | 20010101 | 20010102 | 20010101000000 | 20010101000000 | 20010101000000.00 |
+------------+----------+----------+----------+----------------+----------------+-------------------+
--mysql 8.0
+------------+------------+----------+----------+----------------+----------------+-------------------+
| a | b | c | d | e | f | g |
+------------+------------+----------+----------+----------------+----------------+-------------------+
| 2001-01-01 | 2001-01-02 | 20010101 | 20010102 | 20010101000000 | 20010101000000 | 20010101000000.00 |
+------------+------------+----------+----------+----------------+----------------+-------------------+
---Tidb:
+---------------------+---------------------+------+------+------+------+---------+
| a | b | c | d | e | f | g |
+---------------------+---------------------+------+------+------+------+---------+
| 2001-01-01 00:00:00 | 2001-01-02 00:00:00 | 2001 | 2001 | 2001 | 2001 | 2001.00 |
+---------------------+---------------------+------+------+------+------+---------+ |
Reproduced on dev machine. |
Update some observations of MySQL confusing type conversion behavior:
mysql> select least('11', 2);
|
So TiDB's previous behavior seems reasonable, GREATEST(time '20:00:00', 120000) + 0.00
|
|
Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label. |
Bug Report
1. Minimal reproduce step
2. What did you expect to see?
3. What did you see instead
4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: