Skip to content

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

Open
@ramanich1

Description

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                                                                  |
+-------------------------+--------------------------------------------------------------------------+

Metadata

Assignees

Labels

affects-5.0This bug affects 5.0.x versions.affects-5.1This bug affects 5.1.x versions.affects-5.2This bug affects 5.2.x versions.affects-5.3This bug affects 5.3.x versions.affects-5.4This bug affects the 5.4.x(LTS) versions.affects-6.0affects-6.1This bug affects the 6.1.x(LTS) versions.compatibility-mysql80This is a compatibility issue with MySQL 8.0(but NOT 5.7)severity/moderatesig/executionSIG executiontype/bugThe issue is confirmed as a bug.type/compatibility

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions