Skip to content

[Compatibility]: STR_TO_DATE returns NULL for supported day and week format directives #29331

Closed

Description

@Ariznawlll

Description

STR_TO_DATE() returns NULL for multiple format directives that MySQL 8.0 accepts and converts to a date. The affected set includes ordinal day, day-of-year, weekday names, and week/year directives.

Environment

  • Branch: main
  • Commit: 95b1d2bfd9d756d08320569858080cb16f230fff
  • Deployment: local standalone MatrixOne
  • Reference: MySQL 8.0.45
  • Date: 2026-09-24

Steps to reproduce

SET sql_mode='';

SELECT STR_TO_DATE('29th February 2024','%D %M %Y');
SELECT STR_TO_DATE('2024 060','%Y %j');
SELECT STR_TO_DATE('2024-02-29 Thursday','%Y-%m-%d %W');
SELECT STR_TO_DATE('2024-02-29 Thu','%Y-%m-%d %a');
SELECT STR_TO_DATE('2024-09-1','%x-%v-%w');
SELECT STR_TO_DATE('2024-09-1','%X-%V-%w');
SELECT STR_TO_DATE('2024-09-1','%Y-%u-%w');
SELECT STR_TO_DATE('2024-09-1','%Y-%U-%w');

Actual behavior

MatrixOne returns NULL for all eight expressions.

The complete directive matrix shows the same gap for:

  • %D: day of month with English suffix;
  • %j: day of year;
  • %a / %W: abbreviated/full weekday name;
  • %U / %u / %V / %v: week number modes;
  • %w: weekday number when used to construct a week date;
  • %X / %x: week-based year.

Expected behavior

Match MySQL 8.0.45:

29th February 2024 / %D %M %Y -> 2024-02-29
2024 060 / %Y %j             -> 2024-02-29
2024-02-29 Thursday / ...%W  -> 2024-02-29
2024-02-29 Thu / ...%a       -> 2024-02-29
2024-09-1 / %x-%v-%w         -> 2024-02-26
2024-09-1 / %X-%V-%w         -> 2024-03-04
2024-09-1 / %Y-%u-%w         -> 2024-02-26
2024-09-1 / %Y-%U-%w         -> 2024-03-04

Stability and controls

  • Reproducer: identical results in 3/3 complete runs.
  • Passing controls: numeric year/month/day, abbreviated and full month names, 12/24-hour time, compound %r/%T, microseconds, two-digit years, leading whitespace and trailing input all match MySQL.
  • NULL operands remain NULL and the session stays usable after every query.
  • The same failures occur as literals and from table rows; they are independent of data volume.

Code analysis

pkg/sql/plan/function/generalTime.go leaves %a, %D, %U, %u, %V, %v, %W, %w, %X, and %x commented out in dateFormatParserTable. %j is tokenized and stored in the parse context, but checkMysqlTime() does not convert the parsed day-of-year into month/day fields, so the final date validation returns NULL.

Regression coverage

After implementation, add a stable SQL regression covering every directive above, leap/non-leap day-of-year boundaries, week 00/53 and invalid combinations. This is scalar compatibility coverage; big-data, stability and Chaos are not required.

Related

Activity

  1. added this to the MO-202609 milestone on Sep 24, 2026
  2. added theissue type on Sep 24, 2026
  3. self-assigned this
    on Sep 24, 2026
  4. added a commit that references this issue on Sep 24, 2026
    bff570f
  5. Ariznawlll commented on Sep 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地单机(1 CN / 1 TN / 1 LogService)
    • 测试日期:2026-09-27

    原问题验证

    在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交 bff570f0f7048c0c778bf7a6fb852f23ac9d1532。

    Happy Path 覆盖

    1. STR_TO_DATE 的 day-of-year、week/day 与 week/weekday 指令返回正确日期。

    Unhappy Path 覆盖

    1. 覆盖第 0 周及越界第 54 周,非法边界返回受控结果而非错误日期。

    白盒验证

    确认修复提交 bff570f0f7048c0c778bf7a6fb852f23ac9d1532 是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。

    回归测试

    已加入 MOTR PR #204 的 issue_29323_29325_29327_29328_29329_29330_29331_sql_contracts.test,MOTR 提交 2b4462f2;本地基线比对连续 3 次通过。

    测试证据

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions