pingcap / pingcap/tidb

CAST(x AS YEAR) skips the two-digit-year conversion used by column inserts

Open
#70,821 2 comments 0 reactions 0 assignees View on GitHub
contribution may-affects-25.10 may-affects-26.3 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

```
SELECT CAST(70 AS YEAR); -- 70
CREATE TABLE y(y YEAR);
INSERT INTO y VALUES (70);
SELECT y+0 FROM y; -- 1970 (70–99 → 1900s per MySQL rules)
```

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

```
mysql>
mysql> SELECT CAST(70 AS YEAR); -- 70
+------------------+
| CAST(70 AS YEAR) |
+------------------+
| 1970 |
+------------------+
1 row in set (0.00 sec)

mysql> CREATE TABLE y(y YEAR);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO y VALUES (70);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT y+0 FROM y; -- 1970 (70–99 → 1900s per MySQL rules)
+------+
| y+0 |
+------+
| 1970 |
+------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 9.7.2 |
+-----------+
1 row in set (0.00 sec)
```

### 3. What did you see instead (Required)
```
mysql>
mysql> SELECT CAST(70 AS YEAR); -- 70
+------------------+
| CAST(70 AS YEAR) |
+------------------+
| 70 |
+------------------+
1 row in set (0.00 sec)

mysql> CREATE TABLE y(y YEAR);
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> INSERT INTO y VALUES (70);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT y+0 FROM y; -- 1970 (70–99 → 1900s per MySQL rules)
+------+
| y+0 |
+------+
| 1970 |
+------+
1 row in set (0.00 sec)

```
### 4. What is your TiDB version? (Required)

```
mysql> select tidb_version();
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v9.0.0-beta.2.pre-2174-g65ac2fad58-dirty
Edition: Community
Git Commit Hash: 65ac2fad582510b92d3c4b79999e48217c989737
Git Branch: master
UTC Build Time: 2026-08-30 15:18:00
GoVersion: go1.25.12
Race Enabled: false
Check Table Before Drop: false
Store: unistore
Kernel Type: Classic |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported SELECT CAST(70 AS YEAR) and INSERT behavior in TiDB, then trace the separate CAST and YEAR column conversion paths. Compare their handling of two-digit years and add a regression test covering the query result; done means CAST(70 AS YEAR) matches the column-insert conversion without breaking the existing cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.