pingcap / pingcap/tidb

`SUBTIME` function returns an error in DATETIME type related to TIMESTAMP type

Open
#36,059 0 comments 0 reactions 0 assignees View on GitHub
affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 affects-7.1 affects-7.5 affects-8.1 may-affects-4.0 may-affects-5.0 may-affects-5.1 may-affects-5.2 may-affects-5.3 may-affects-5.4 severity/major sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### 1. Minimal reproduce step
```sql
CREATE TABLE t1 (a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6));
INSERT INTO t1 VALUES ('1970-01-01 01:00:01.000000');
INSERT INTO t1 VALUES ('1970-01-01 01:00:01.000001');

CREATE TABLE t2 (
`SUBTIME(a, '00:00:00.000001')` datetime(6) DEFAULT NULL,
`SUBTIME(a, '10:00:00.000001')` datetime(6) DEFAULT NULL
);

INSERT INTO t2 SELECT
SUBTIME(a, '00:00:00.000001'),
SUBTIME(a, '10:00:00.000001')
FROM t1;
SELECT * FROM t2;
```
### 2. What did you expect to see?
```sql
mysql> INSERT INTO t2 SELECT
-> SUBTIME(a, '00:00:00.000001'),
-> SUBTIME(a, '10:00:00.000001')
-> FROM t1;
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> SELECT * FROM t2;
+-------------------------------+-------------------------------+
| SUBTIME(a, '00:00:00.000001') | SUBTIME(a, '10:00:00.000001') |
+-------------------------------+-------------------------------+
| 1970-01-01 01:00:00.999999 | 1969-12-31 15:00:00.999999 |
| 1970-01-01 01:00:01.000000 | 1969-12-31 15:00:01.000000 |
+-------------------------------+-------------------------------+
```

### 3. What did you see instead
```sql
tidb> INSERT INTO t2 SELECT
-> SUBTIME(a, '00:00:00.000001'),
-> SUBTIME(a, '10:00:00.000001')
-> FROM t1;
ERROR 1292 (22007): Incorrect time value: '{1969 12 31 15 0 0 999999}'
```

### 4. What is your TiDB version?
```*************************** 1. row ***************************
tidb_version(): Release Version: v6.2.0-alpha-230-g47a4f3a01
Edition: Community
Git Commit Hash: 47a4f3a017768dda0b9a826451486c5539bc8427
Git Branch: master
UTC Build Time: 2022-07-08 20:42:13
GoVersion: go1.18.1
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.