Skip to content

[Compatibility]: STR_TO_DATE rejects incomplete zero dates when SQL modes allow them #30233

Open

Description

@Ariznawlll

Description

With zero-date SQL modes disabled, MatrixOne returns NULL from STR_TO_DATE() for MySQL incomplete-date values. MySQL preserves the zero month/day components. This also changes values from date-part functions and formatting applied to the parsed result.

Environment

  • MatrixOne local service: 8.0.30-MatrixOne-v1.3.0
  • MySQL reference: 8.0.45
  • Verification: 3 repeated runs on each engine
  • Session SQL mode: explicitly set per case

Reproduction

SET SESSION sql_mode = '';

SELECT STR_TO_DATE('2024-00-00', '%Y-%m-%d');
SELECT STR_TO_DATE('2024-00-01', '%Y-%m-%d');
SELECT STR_TO_DATE('2024-01-00', '%Y-%m-%d');
SELECT STR_TO_DATE('0000-00-00', '%Y-%m-%d');

SELECT
  YEAR(STR_TO_DATE('2024-00-00', '%Y-%m-%d')),
  MONTH(STR_TO_DATE('2024-00-00', '%Y-%m-%d')),
  DAYOFMONTH(STR_TO_DATE('2024-00-00', '%Y-%m-%d')),
  DATE_FORMAT(STR_TO_DATE('2024-00-00', '%Y-%m-%d'), '%Y-%m-%d');

SELECT STR_TO_DATE('2024-02-29', '%Y-%m-%d'); -- valid control

Observed behavior

Input / expression MySQL 8.0.45 MatrixOne
2024-00-00 2024-00-00 NULL
2024-00-01 2024-00-01 NULL
2024-01-00 2024-01-00 NULL
0000-00-00 0000-00-00 NULL
YEAR/MONTH/DAYOFMONTH/DATE_FORMAT of 2024-00-00 2024 / 0 / 0 / 2024-00-00 NULL / NULL / NULL / NULL
Valid 2024-02-29 control 2024-02-29 2024-02-29

MySQL emits no warnings for these incomplete dates with sql_mode=''. The result difference reproduced identically in 3/3 runs per engine.

The mode distinction also differs: with sql_mode='NO_ZERO_IN_DATE', MySQL rejects 2024-00-00 with warning 1411 but still returns 0000-00-00; MatrixOne returns NULL for both. Warning parity is separately tracked by #30213.

Expected behavior

Match MySQL's incomplete-date parsing in STR_TO_DATE() when the active SQL mode permits zero date parts, and honor the distinction between NO_ZERO_IN_DATE and NO_ZERO_DATE.

MySQL documentation states that zero dates or zero date parts are permitted by STR_TO_DATE() unless the relevant SQL mode disallows them: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_str-to-date

Related issues checked

Activity

  1. added this to the MO-202610 milestone on Oct 14, 2026
  2. added
    kind/bug
    on Oct 14, 2026
  3. added theissue type on Oct 14, 2026
  4. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充同一差异在表列和 SQL PREPARE 路径的观察(MatrixOne 服务源码 commit 2ce4e58af6f03b943ee288ffad81012766cf830a,MySQL 8.0.45;每条路径各重复 3 轮):

    SET SESSION sql_mode = '';
    CREATE TABLE source_dates(v VARCHAR(16));
    INSERT INTO source_dates VALUES ('2024-00-00'), ('2024-02-29');
    SELECT v, STR_TO_DATE(v, '%Y-%m-%d') FROM source_dates ORDER BY v;
    
    PREPARE p FROM 'SELECT STR_TO_DATE(?, ''%Y-%m-%d'')';
    SET @d = '2024-00-00';
    EXECUTE p USING @d;
    DEALLOCATE PREPARE p;
    • 表列输入:MySQL 返回 2024-00-00 和有效控制 2024-02-29;MO 对前者返回 NULL,有效控制相同。
    • SQL PREPARE 参数:MySQL 返回 2024-00-00;MO 返回 NULL。
    • 两端对这里的 incomplete-date 输入都没有附加 warning。

    因此该结果差异不仅出现在字面量表达式,也稳定存在于行输入和 SQL PREPARE 参数路径。

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