pingcap / pingcap/tidb

cast string as time behavior is incompatible with MySQL

Open
#36,110 1 comment 0 reactions 0 assignees View on GitHub
compatibility-mysql80 sig/execution
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)

```sql
select cast("1 1" as TIME);
```

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

in both mysql 8.0 and 5.7, the result is

```sql
mysql> select cast("1 1" as TIME);
+---------------------+
| cast("1 1" as TIME) |
+---------------------+
| 00:00:01 |
+---------------------+
1 row in set, 1 warning (0.00 sec)
```

### 3. What did you see instead (Required)

However, in tidb 6.2.0, the result is

```sql
mysql> select cast("1 1" as TIME);
+---------------------+
| cast("1 1" as TIME) |
+---------------------+
| 25:00:00 |
+---------------------+
1 row in set (0.00 sec)
```

I think tidb treats the first `1` as day and the second `1` as hour, therefore outputting the final 25 hours. However, it seems that mysql truncated the second `1` and only regards the first `1` as 1 second. The bug might lie in duration(aka. Time) parsing logic.

Some other incompatible cases:

```sql
select cast("1 1:" as TIME);
// mysql: 25:00:00
// tidb: 00:00:01

select cast("1 asdasdfasdfasdf1" as TIME);
// mysql: 00:00:01
// tidb: null

select cast("1:1 :aasdfasdf1" as time);
// mysql: 01:01:00
// tidb: null

select cast("1:1:1 :aasdfasdf1" as time);
// mysql: 00:00:00
// tidb: null
```

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

master

```sql
| Release Version: v6.2.0-alpha-331-g87052dc2f
Edition: Community
Git Commit Hash: 87052dc2f8643ffc74974dec8bb52a454a1c1329
Git Branch: master
UTC Build Time: 2022-07-11 20:40:03
GoVersion: go1.18.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
Store: unistore |
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.