-
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
The return type of UNIX_TIMESTAMP() is confusing in MySQL #9861
Comments
@eurekaka PTAL. |
Thanks for your report, @wjhuang2016 ! |
I don't have a good explanation for it, but I tried a couple more examples:
Is it possible that invalid values result in decimal return values unless the reason it is invalid is because of a zero value? |
@morgo I think it's more complecate here.
So, |
I think the specifics of why MySQL does what it does in these different cases is sort of irrelevant. There's lots of historical stuff that's happened with date/time handling in MySQL, so it's not very surprising that there are some surprising return values. I guess the question is whether TiDB wants to prioritize MySQL compatibility or prioritize some kind of well-justified handling of erroneous inputs. I don't think there are probably a large number of users relying on the data type of a completely nonsensical value given to the UNIX_TIMESTAMP() function, so I propose that UNIX_TIMESTAMP() in TiDB return a decimal only when invoked with an argument with fractional second components and return an integer in all other cases. Returning NULL instead of a numeric value certainly makes more sense for truly invalid values, but it breaks MySQL compatibility, so I nominate @morgo to make the definitive recommendation as the MySQL-compatibility guru. |
I am fine with not being fully compatible with MySQL in these specific cases / declaring the MySQL behavior as a bug. In general though, it can be difficult to judge when a case is important, so I appreciate the CC. Thanks! |
I'm in favor of your proposal. We should return a decimal only when invoked with an argument with fractional second components. |
General Question
According to #9729,
will should return 1 instead of 1.000000.
And
select unix_timestamp(1)
will also return 1.When I try to solve this problem, I found that in MySQL:
and
Finaly, in TiDB:
In MySQL Doc:https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_unix-timestamp
We can see that:
The return type of UNIX_TIMESTAMP() is so confusing in MySQL that we need to make it clear to implement UNIX_TIMESTAMP() in TiDB properly.
The text was updated successfully, but these errors were encountered: