Skip to content
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

CAST AS..YEAR TiDB results not matching with MySQL 8.0 #29629

Open
ramanich1 opened this issue Nov 9, 2021 · 4 comments
Open

CAST AS..YEAR TiDB results not matching with MySQL 8.0 #29629

ramanich1 opened this issue Nov 9, 2021 · 4 comments
Assignees
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) severity/moderate sig/execution SIG execution type/bug This issue is a bug. type/compatibility

Comments

@ramanich1
Copy link
Collaborator

ramanich1 commented Nov 9, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

SELECT CAST(69  AS YEAR), CAST(70  AS YEAR),CAST(00  AS YEAR);
select (CAST(20201 AS YEAR));
SELECT CAST(TIMESTAMP'579-10-10 10:10:10' AS YEAR);

2. What did you expect to see? (Required)

mysql> SELECT CAST(69  AS YEAR), CAST(70  AS YEAR),CAST(00  AS YEAR);
+-------------------+-------------------+-------------------+
| CAST(69  AS YEAR) | CAST(70  AS YEAR) | CAST(00  AS YEAR) |
+-------------------+-------------------+-------------------+
|              2069 |              1970 |                 0 |
+-------------------+-------------------+-------------------+
1 row in set (0.00 sec)
mysql> select (CAST(20201 AS YEAR));
+-----------------------+
| (CAST(20201 AS YEAR)) |
+-----------------------+
|                  NULL |
+-----------------------+
1 row in set, 1 warning (0.00 sec)
--Warning | 1292 | Truncated incorrect YEAR value: '20201'
mysql> SELECT CAST(TIMESTAMP'579-10-10 10:10:10' AS YEAR);
+---------------------------------------------+
| CAST(TIMESTAMP'579-10-10 10:10:10' AS YEAR) |
+---------------------------------------------+
|                                        NULL |
+---------------------------------------------+
1 row in set, 1 warning (0.00 sec)
--| Warning | 1292 | Truncated incorrect YEAR value: '579'

3. What did you see instead (Required)

mysql> SELECT CAST(69  AS YEAR), CAST(70  AS YEAR),CAST(00  AS YEAR);
+-------------------+-------------------+-------------------+
| CAST(69  AS YEAR) | CAST(70  AS YEAR) | CAST(00  AS YEAR) |
+-------------------+-------------------+-------------------+
|                69 |                70 |              0000 |
+-------------------+-------------------+-------------------+
1 row in set (0.00 sec)
mysql> select (CAST(20201 AS YEAR));
+-----------------------+
| (CAST(20201 AS YEAR)) |
+-----------------------+
|                 20201 |
+-----------------------+
1 row in set (0.00 sec)
mysql> SELECT CAST(TIMESTAMP'579-10-10 10:10:10' AS YEAR);
+---------------------------------------------+
| CAST(TIMESTAMP'579-10-10 10:10:10' AS YEAR) |
+---------------------------------------------+
|                               5791010101010 |
+---------------------------------------------+
1 row in set (0.01 sec)

4. What is your TiDB version? (Required)

+-------------------------+--------------------------------------------------------------------------+
| Variable_name           | Value                                                                    |
+-------------------------+--------------------------------------------------------------------------+
| innodb_version          | 5.6.25                                                                   |
| protocol_version        | 10                                                                       |
| tidb_analyze_version    | 2                                                                        |
| tidb_row_format_version | 2                                                                        |
| tls_version             | TLSv1,TLSv1.1,TLSv1.2                                                    |
| version                 | 5.7.25-TiDB-v5.2.2                                                       |
| version_comment         | TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible |
| version_compile_machine | x86_64                                                                   |
| version_compile_os      | osx10.8                                                                  |
+-------------------------+--------------------------------------------------------------------------+
@ramanich1 ramanich1 added the type/bug This issue is a bug. label Nov 9, 2021
@morgo
Copy link
Contributor

morgo commented Nov 9, 2021

CAST .. AS YEAR is new to MySQL 8.0. In MySQL 5.7, this returns a syntax error:

mysql [localhost:5735] {msandbox} (test) > SELECT CAST(69  AS YEAR), CAST(70  AS YEAR),CAST(00  AS YEAR);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'YEAR), CAST(70  AS YEAR),CAST(00  AS YEAR)' at line 1

So TiDB could chose to either return an error as well (5.7) or correct results per MySQL 8.0. But currently the results are incorrect, which could cause problems.

@ramanich1 ramanich1 changed the title CAST two digit year in TiDB is not converting to 4 digit year to match with Mysql8.0 CAST AS..YEAR TiDB results not matching with Mysql8.0 Nov 9, 2021
@fuzhe1989
Copy link
Contributor

/assign @ichn-hu

@jebter jebter added affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. labels Jan 11, 2022
@solotzg
Copy link
Contributor

solotzg commented Jun 17, 2022

According to https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html. MySQL supports CAST( AS YEAR) since 8.0.22. TiDB should follow those behaviors if need to be compatible with mysql 8.0.
But for mysql 5.7, tidb should raise error like ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ...

@zanmato1984
Copy link
Contributor

We'll aim to MySQL 8.0. But this usage, i.e., two digits number, is not very common. We consider this to be a moderate issue.

@dveeden dveeden added type/compatibility compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) labels Mar 26, 2024
@dveeden dveeden changed the title CAST AS..YEAR TiDB results not matching with Mysql8.0 CAST AS..YEAR TiDB results not matching with MySQL 8.0 Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) severity/moderate sig/execution SIG execution type/bug This issue is a bug. type/compatibility
Projects
None yet
Development

No branches or pull requests

10 participants