Bug #108407 | UNIX_TIMESTAMP() returns a DECIMAL when argument does not include a fsp | ||
---|---|---|---|
Submitted: | 6 Sep 2022 19:20 | Modified: | 7 Sep 2022 10:10 |
Reporter: | William Chiquito | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S3 (Non-critical) |
Version: | 8.0.30 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | date_format, unix_timestamp |
[6 Sep 2022 19:20]
William Chiquito
[7 Sep 2022 6:04]
MySQL Verification Team
Hello William Chiquito, Thank you for the report and test case. regards, Umesh
[7 Sep 2022 8:46]
Roy Lyseng
Posted by developer: This is not a bug. In order to determine the exact number of decimals (zero in case of an integer), we need the expression to be consisting of only literal values. In this case, it is only cases f and g that qualifies for that. Cases d, e and h contains expressions that may vary at execution time and hence are assigned type DECIMAL and with 6 decimals. It is indeed the UNIX_TIMESTAMP function that returns the numeric type. DATE_FORMAT always returns a character string. If you really need the result to be an integer, you can add a CAST(<expression> AS SIGNED).
[7 Sep 2022 9:46]
William Chiquito
Has that behavior changed from version 8.0.x? because in 5.7.x the behavior is as expected (according to the documentation). Perhaps the documentation for version 8.0.x should be more explicit and include the explanation of these cases. Thanks.
[7 Sep 2022 10:10]
William Chiquito
However, it is confusing because in all cases (`d`, `e`, `f`, `g` and `h`) the UNIX_TIMESTAMP function receives as an argument the same character string returned by the DATE_FORMAT function. Thanks.
[7 Sep 2022 17:48]
Roy Lyseng
It changed in 8.0.22. Before that, types could be determined more specifically based on literal values, user variables and parameter values. Starting with 8.0.22, such specific typing is only possible for literal values. The reason was to get more predictable types for prepared statements.