pingcap / pingcap/tidb

`CAST(HEX(...) AS DATETIME)` raises "expected integer" error, but MySQL returns `NULL`

Open
#69,185 2 comments 0 reactions 0 assignees View on GitHub
contribution severity/moderate sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

TiDB raises an error `expected integer` when casting the result of `HEX()` to `DATETIME`, while MySQL returns `NULL` with a warning.

Note that this is data-dependent: changing `1945768543` to `1945768542` (e.g., `SELECT CAST(HEX(1945768542/74) AS DATETIME)`) TiDB returns `NULL`, matching MySQL.

### 1. Minimal reproduce step (Required)

```sql
SELECT CAST(HEX(1945768543/74) AS DATETIME);
```

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

```sql
mysql> SELECT CAST(HEX(1945768543/74) AS DATETIME);
+--------------------------------------+
| CAST(HEX(1945768543/74) AS DATETIME) |
+--------------------------------------+
| NULL |
+--------------------------------------+
1 row in set, 1 warning (0.001 sec)
```

The expression should return `NULL` with a warning, matching MySQL behavior.

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

```
ERROR 1105 (HY000): expected integer
```

TiDB raises an error instead of returning `NULL`.

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

```
Release Version: v8.5.6
Edition: Community
Git Commit Hash: ae18096e023780bb56bfce33698abec0d4640d0a
Git Branch: HEAD
UTC Build Time: 2026-06-04 05:49:11
GoVersion: go1.25.8
Race Enabled: false
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.