Different type result with MySQL 8.0 (date -> datetime)
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
This seems to affect Django's `coalesce` function.
### 1. Minimal reproduce step (Required)
```sql
create view typeof as select
date '1970-01-01' as a,
cast('1970-01-01' as date) as b,
min(date '1970-01-01') as c,
min(cast('1970-01-01' as date)) as d,
cast(null as date) as e,
min(cast(null as date)) as f,
coalesce(min(cast('1970-01-01' as date)), '1980-01-01') as g,
coalesce(min(cast(null as date)), '1980-01-01') as h,
coalesce(min(cast(null as date)), cast('1980-01-01' as date)) as i,
coalesce(min(cast(null as date)), date '1980-01-01') as j,
coalesce(min(cast(null as date)), date(now())) as k;
desc typeof;
```
### 2. What did you expect to see? (Required)
MySQL 8.0:
```
mysql> desc typeof;
+-------+-------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+------------+-------+
| a | date | NO | | 0000-00-00 | |
| b | date | YES | | NULL | |
| c | date | YES | | NULL | |
| d | date | YES | | NULL | |
| e | date | YES | | NULL | |
| f | date | YES | | NULL | |
| g | varchar(10) | NO | | | |
| h | varchar(10) | NO | | | |
| i | date | YES | | NULL | |
| j | date | NO | | 0000-00-00 | |
| k | date | YES | | NULL | |
+-------+-------------+------+-----+------------+-------+
11 rows in set (0.00 sec)
```
### 3. What did you see instead (Required)
TiDB:
```
my:root@127.0.0.1:4000=> desc typeof;
Field | Type | Null | Key | Default | Extra
-------+-------------+------+-----+---------+-------
a | date | NO | | |
b | date | NO | | |
c | date | YES | | |
d | date | YES | | |
e | date | YES | | |
f | date | YES | | |
g | varchar(10) | YES | | |
h | varchar(10) | YES | | |
i | datetime(6) | YES | | |
j | datetime(6) | YES | | |
k | datetime(6) | YES | | |
(11 rows)
```
The last 3 rows are `datetime`, not `date`.
### 4. What is your TiDB version? (Required)
```
my:root@127.0.0.1:4000=> select tidb_version();
tidb_version()
-------------------------------------------------------------------
Release Version: v6.1.0-alpha +
Edition: Community +
Git Commit Hash: 37d86dada8885e4fcaa1bf73c5404b86489be3fe +
Git Branch: heads/refs/tags/v6.1.0-alpha +
UTC Build Time: 2022-04-06 14:52:21 +
GoVersion: go1.18 +
Race Enabled: false +
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306+
Check Table Before Drop: false
(1 row)
```
Contributor guide
Assessment
This issue has not been assessed yet.