pingcap / pingcap/tidb

Inconsistent behaviors when casting an integer value into a timestamp

Open
#59,832 0 comments 0 reactions 0 assignees View on GitHub
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)
I run the following cases, which try to cast the same integer value into a timestamp

```sql
-- 1
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (c1 SMALLINT);
INSERT INTO t1 (c1) VALUES (17044);
SELECT TIMESTAMP(c1) FROM t1; -- {2017-04-04 00:00:00}
-- 2
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (c1 INT);
INSERT INTO t1 (c1) VALUES (17044);
SELECT TIMESTAMP(c1) FROM t1; -- {2017-04-04 00:00:00}
-- 3
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (c1 BIGINT);
INSERT INTO t1 (c1) VALUES (17044);
SELECT TIMESTAMP(c1) FROM t1; -- null
-- 4
SELECT TIMESTAMP(17044); -- null
```
### 2. What did you expect to see? (Required)
I expect these queries should return the same result.
### 3. What did you see instead (Required)
Different query results are returned.
### 4. What is your TiDB version? (Required)

Release Version: v8.5.1
Edition: Community
Git Commit Hash: fea86c8e35ad4a86a5e1160701f99493c2ee547c
Git Branch: HEAD
UTC Build Time: 2025-01-16 07:38:34
GoVersion: go1.23.4
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.