pingcap / pingcap/tidb

`UNIX_TIMESTAMP` doesn't support all formats which are supported by MySQL

Open
#59,434 1 comment 0 reactions 0 assignees View on GitHub
component/expression severity/moderate 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)

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

```
mysql> SELECT UNIX_TIMESTAMP('');
+--------------------+
| UNIX_TIMESTAMP('') |
+--------------------+
| 0.000000 |
+--------------------+
1 row in set, 1 warning (0.00 sec)

mysql> SELECT UNIX_TIMESTAMP('2024');
+------------------------+
| UNIX_TIMESTAMP('2024') |
+------------------------+
| 0.000000 |
+------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> SELECT UNIX_TIMESTAMP('20240228T123456');
+-----------------------------------+
| UNIX_TIMESTAMP('20240228T123456') |
+-----------------------------------+
| 1709094896 |
+-----------------------------------+
1 row in set (0.01 sec)

mysql> SELECT UNIX_TIMESTAMP('28 February 2024');
+------------------------------------+
| UNIX_TIMESTAMP('28 February 2024') |
+------------------------------------+
| 0.000000 |
+------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> SELECT UNIX_TIMESTAMP('2024-02-28abc');
+---------------------------------+
| UNIX_TIMESTAMP('2024-02-28abc') |
+---------------------------------+
| 1709049600 |
+---------------------------------+
1 row in set, 1 warning (0.00 sec)
```

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

```
mysql> SELECT UNIX_TIMESTAMP('');
+--------------------+
| UNIX_TIMESTAMP('') |
+--------------------+
| NULL |
+--------------------+
1 row in set, 1 warning (0.00 sec)

mysql> SELECT UNIX_TIMESTAMP('2024');
+------------------------+
| UNIX_TIMESTAMP('2024') |
+------------------------+
| NULL |
+------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> SELECT UNIX_TIMESTAMP('20240228T123456');
+-----------------------------------+
| UNIX_TIMESTAMP('20240228T123456') |
+-----------------------------------+
| NULL |
+-----------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> SELECT UNIX_TIMESTAMP('28 February 2024');
+------------------------------------+
| UNIX_TIMESTAMP('28 February 2024') |
+------------------------------------+
| NULL |
+------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> SELECT UNIX_TIMESTAMP('2024-02-28abc');
+---------------------------------+
| UNIX_TIMESTAMP('2024-02-28abc') |
+---------------------------------+
| NULL |
+---------------------------------+
1 row in set, 1 warning (0.00 sec)
```

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

Contributor guide

Open the contributing guide

Research direction

Start by running the listed UNIX_TIMESTAMP queries against TiDB and MySQL, noting the differences for each input format. The issue names no implementation file or test; locate the existing UNIX_TIMESTAMP entry point and date-format tests, then add coverage so the listed cases match the expected MySQL results.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, mysql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.