pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.98k stars 5.82k forks source link

Expression castRealAsTime does not respect sql mode. #37539

Open mengxin9014 opened 2 years ago

mengxin9014 commented 2 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

 create table t(d1 double, f float);
 insert into t values(0, 0);
 set session sql_mode = "NO_ZERO_IN_DATE,NO_ZERO_DATE";
 select cast(d1 as datetime), cast(f as datetime) from t;

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

+----------------------+---------------------+
| cast(d1 as datetime) | cast(f as datetime) |
+----------------------+---------------------+
| NULL                 | NULL                |
+----------------------+---------------------+

3. What did you see instead (Required)

+----------------------+---------------------+
| cast(d1 as datetime) | cast(f as datetime) |
+----------------------+---------------------+
| 0000-00-00 00:00:00  | 0000-00-00 00:00:00 |
+----------------------+---------------------+

4. What is your TiDB version? (Required)

nightly

Other expressions like castDecimalAsTime, etc. may have the same problem.

bb7133 commented 2 years ago

This is about the behavior of cast, reassign it to 'sig-execution'.