Skip to content

[Bug]: zero-like and empty strings fail MySQL-compatible numeric casts #25243

Closed

Description

@Ariznawlll

Environment

  • Branch: latest main
  • Commit: 33e96877604ad4b847ea7d5c55eb09429de1a5b6
  • MySQL oracle: 8.0.45
  • MO: 8.0.30-MatrixOne-v1.3.0

Steps to Reproduce

select cast('-0' as unsigned) as unsigned_neg_zero;
select cast('+000' as decimal(6,2)) as decimal_plus_zero;
select cast('' as signed) as empty_signed,
       cast('' as unsigned) as empty_unsigned,
       cast('' as decimal(6,2)) as empty_decimal,
       '' + 1 as empty_plus_one;
select cast('  ' as signed) as space_signed,
       cast('  ' as decimal(6,2)) as space_decimal,
       '  ' + 1 as space_plus_one;

MySQL Result

unsigned_neg_zero
0

decimal_plus_zero
0.00

empty_signed empty_unsigned empty_decimal empty_plus_one
0            0              0.00          1

space_signed space_decimal space_plus_one
0            0.00          1

MatrixOne Result

select cast('-0' as unsigned);
ERROR 20203 (HY000): invalid argument cast to uint64, bad value -0

select cast('+000' as decimal(6,2));
ERROR 20301 (HY000): invalid input: +000 beyond the range, can't be converted to Decimal64(6,2).

select cast('' as signed);
ERROR 20203 (HY000): invalid argument cast to int, bad value

Expected Behavior

MySQL coerces zero-like strings, empty strings, and all-space strings to numeric zero in expression context, emitting warnings instead of failing the query. MatrixOne should align these string-to-numeric cast/coercion paths with MySQL.

Duplicate Check

Related but not identical: #25225 covers a leading-plus string converted to UNSIGNED. This issue tracks zero-like and empty/all-space string-to-numeric conversion cases on latest main.

Activity

  1. added
    kind/bug
    severity/s1
    on Jun 30, 2026
  2. added theissue type on Jun 30, 2026
  3. added this to the MO-202607 milestone on Jun 30, 2026
  4. added
    ai-light
    on Jul 1, 2026
  5. daviszhen commented on Jul 3, 2026

    @daviszhen
    Contributor

    字符串 'abc','123abc' 转 数字, mo 既 不返回0, 也不返回 NULL, 一直报错的。 这类case 也避免掉。mo不会改已经用了多年的行为。

  6. daviszhen commented on Jul 3, 2026

    @daviszhen
    Contributor

    这类问题要修改

    select cast('-0' as unsigned) as unsigned_neg_zero;
    select cast('+000' as decimal(6,2)) as decimal_plus_zero;

  7. added
    severity/s0
    and removed
    severity/s1
    on Jul 6, 2026
  8. added a commit that references this issue on Jul 7, 2026
  9. daviszhen commented on Jul 7, 2026

    @daviszhen
    Contributor

    修改了行为.

  10. Ariznawlll commented on Jul 8, 2026

    @Ariznawlll
    CollaboratorAuthor

    Verified on latest main.

    Build tested:

    Validation SQL and result for the zero-like cases that were called out for fixing:

    select cast('-0' as unsigned) as neg_zero_unsigned,
           cast('-0b0' as unsigned) as neg_bin_zero_unsigned,
           cast('-0o0' as unsigned) as neg_oct_zero_unsigned,
           cast('-0x0' as unsigned) as neg_hex_zero_unsigned;
    
    -- result
    -- neg_zero_unsigned | neg_bin_zero_unsigned | neg_oct_zero_unsigned | neg_hex_zero_unsigned
    -- 0                 | 0                     | 0                     | 0
    
    select cast('+000' as decimal(6,2)) as plus_zero_decimal,
           cast('-000' as decimal(6,2)) as minus_zero_decimal;
    
    -- result
    -- plus_zero_decimal | minus_zero_decimal
    -- 0.00              | 0.00

    Additional check:

    • Empty string / all-space string casts still return MO errors, for example cast('' as signed) and cast(' ' as signed) still return invalid argument cast to int.
    • I did not add those rows to motr because the earlier R&D comment said non-numeric string-to-number conversion should continue to follow MO's existing behavior rather than MySQL's warning-and-zero behavior.

    Conclusion:

    • The zero-like cases explicitly mentioned in the issue comments are fixed on latest main.
    • Non-numeric empty/all-space string coercion remains MO current behavior and is not included in the regression case.

    Added motr regression coverage in matrixorigin/motr#39:

    • suites/14_issue_regression/t/issue_25243_cast_zero_like_strings.test
    • suites/14_issue_regression/r/issue_25243_cast_zero_like_strings.result

    motr validation:

    [ISSUE_25243_CAST_ZERO_LIKE_STRINGS] success | stmts=2 ok=2 fail=0
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-lightkind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions