pingcap / pingcap/tidb

TIMESTAMPADD returns NULL when result is in DST transition.

Open
#61,567 3 comments 0 reactions 0 assignees View on GitHub
may-affects-6.1 may-affects-6.5 may-affects-7.1 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)

```mysql
CREATE TABLE t (id int primary key, ts timestamp);
SET time_zone = 'UTC';
INSERT INTO t VALUES (1, '2025-03-30 00:59:59');
SET time_zone = 'Europe/Amsterdam';
SELECT TIMESTAMPADD(HOUR, 1, ts) FROM t;
```

### 2. What did you expect to see? (Required)
TIMESTAMPADD is actually working with DATETIME, not TIMESTAMP as the name suggests, so I would expect ts to first be casted to DATETIME, and then added one hour, like MySQL:
```mysql
mysql80> SELECT TIMESTAMPADD(HOUR, 1, ts) FROM t;
+---------------------------+
| TIMESTAMPADD(HOUR, 1, ts) |
+---------------------------+
| 2025-03-30 02:59:59 |
+---------------------------+
1 row in set (0.00 sec)
```

### 3. What did you see instead (Required)
I don't consider this as a big issue, but when looking at the warning, it also says `Incorrect time value: '{2025 3 30 1 59 59 0}'` while it is actually a valid timestamp for the time zone (02:00:00-02:59:59 is not).

```mysql
tidb> SELECT TIMESTAMPADD(HOUR, 1, ts) FROM t;
+---------------------------+
| TIMESTAMPADD(HOUR, 1, ts) |
+---------------------------+
| NULL |
+---------------------------+
1 row in set, 1 warning (0.00 sec)

tidb> show warnings;
+---------+------+-----------------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------------+
| Warning | 1292 | Incorrect time value: '{2025 3 30 1 59 59 0}' |
+---------+------+-----------------------------------------------+
1 row in set (0.00 sec)
```

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

```
tidb_version(): Release Version: v8.5.2
Edition: Community
Git Commit Hash: f43a13324440f92209e2a9f04c0bbe9cf763978d
Git Branch: HEAD
UTC Build Time: 2025-05-29 03:33:08
GoVersion: go1.23.6
Race Enabled: false
Check Table Before Drop: false
Store: tikv
```

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.