matrixorigin / matrixorigin/matrixone

[Bug]: date/time functions error on zero or invalid date strings instead of MySQL NULL/0 semantics

Open
#25,306 1 comment 0 reactions 1 assignee Assigned to @jiangxinmeng1 View on GitHub
kind/bug needs-triage
Dominant language
Go
Stars
1.9k
Forks
311
Avg merge
1d 3h
Merged PRs (30d)
768

Description

## Bug Report

### MatrixOne Version

Latest `origin/main` verified locally at `200bfa7e0efb`.

### Reproduce Steps

```sql
set session sql_mode = '';

select date_format('0000-00-00', '%Y-%m-%d') as zero_fmt,
dayofmonth('0000-00-00') as zero_day,
month('0000-00-00') as zero_month,
year('0000-00-00') as zero_year,
last_day('2024-02-31') as invalid_last_day;

select extract(month from '0000-00-00') as zero_extract_month,
extract(day from 'not-a-date') as invalid_extract_day;

select convert_tz('2024-01-01 00:00:00', '+00:00', '+08:00') as offset_ok,
convert_tz('invalid', '+00:00', '+08:00') as invalid_dt;
```

### Expected Behavior

MySQL returns zero parts for extractor-style functions that accept incomplete dates, and returns `NULL` for invalid complete-date operations:

```text
zero_fmt zero_day zero_month zero_year invalid_last_day
0000-00-00 0 0 0 NULL

zero_extract_month invalid_extract_day
0 NULL

offset_ok invalid_dt
2024-01-01 08:00:00 NULL
```

### Actual Behavior

MatrixOne errors before returning the rows:

```text
ERROR 20301 (HY000): invalid input: invalid datetime value 0000-00-00
ERROR 20101 (HY000): internal error: invalid input
ERROR 20301 (HY000): invalid input: invalid datetime value invalid
```

### Notes

This is separate from #25253, which covers `CAST('0000-00-00 00:00:00' AS DATETIME)`. This issue is about date/time function behavior for zero/incomplete/invalid date strings.

MySQL documentation says some date functions work with zero or incomplete dates and return zero parts, while functions expecting complete dates return `NULL` for invalid/incomplete values.

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.