Skip to content

CAST of non-numeric strings to numeric types errors instead of returning zero #30911

Closed as not planned

Description

@Ariznawlll

Description

CAST of a string that does not start with a digit to an integer type raises a hard error instead of returning 0 (with a warning) as MySQL does. E.g. CAST('abc12' AS SIGNED) → ERROR 20203, MySQL → 0. This is the explicit-CAST entry point of the same string→integer strictness issue; the comparison entry point ('10.0' = 10) is tracked in #30694 and also still errors on this build.

Environment

  • MatrixOne dev build 3a1e42b430, server reports 8.0.30-MatrixOne-v1.3.0
  • MySQL comparison: 8.0.45 (localhost)

Reproduction

SELECT CAST('abc12' AS SIGNED);
-- MatrixOne: ERROR 20203 (HY000) invalid argument cast to int, bad value abc12
-- MySQL:     0   (Warning 1292: Truncated incorrect INTEGER value: 'abc12')

SELECT CAST('   ' AS SIGNED);   -- MatrixOne: ERROR 20203 bad value '' ;  MySQL: 0
SELECT CAST('12abc' AS SIGNED); -- both: 12  (leading-digit form works)
SELECT CAST('abc' AS UNSIGNED); -- MatrixOne: ERROR ;  MySQL: 0

Root cause

The string→integer cast path rejects any string that does not begin with a digit, instead of MySQL's permissive behavior of returning 0 with a 1292 truncation warning. The leading-digit prefix form ('12abc' → 12) already works, so the defect is specifically the non-leading-digit fallback.

Impact

  • Loosely-typed data (VARCHAR columns holding free-form values) cannot be safely cast to integers; CAST(v AS SIGNED) fails the whole statement on the first non-numeric row, where MySQL would coerce it to 0.
  • Common ETL normalization (CAST(col AS UNSIGNED)) over mixed-quality columns breaks entirely.

Expected behavior

CAST('abc12' AS SIGNED) and CAST('' AS SIGNED) should return 0 (optionally with a truncation warning), matching MySQL. The leading-digit prefix form is already correct.

Activity

  1. added this to the MO-202610 milestone on Oct 23, 2026
  2. changed the title [-][Bug]: CAST(non-numeric string AS SIGNED/UNSIGNED) errors instead of returning 0[/-] [+]CAST of non-numeric strings to numeric types errors instead of returning zero[/+] on Oct 23, 2026
  3. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    Additional DECIMAL CAST reproduction consolidated from #30912

    The same explicit nonnumeric-string CAST behavior occurs for DECIMAL targets:

    SELECT CAST('abc' AS DECIMAL(10,2));
    -- MatrixOne: ERROR 20301, invalid decimal string
    -- MySQL 8.0.45: 0.00 with truncation warning 1292
    
    SELECT CAST('' AS DECIMAL(10,2));
    -- MatrixOne: error
    -- MySQL: 0.00
    
    SELECT CAST('12.345' AS DECIMAL(10,2));
    -- Both: 12.35

    The original environment, controls, and report remain on #30912. Extend this issue's acceptance matrix to SIGNED, UNSIGNED, and DECIMAL casts, covering nonnumeric text, empty/whitespace input, valid leading numeric prefixes, target precision/scale, and SQL-mode-appropriate truncation diagnostics. This is the same explicit CAST fallback contract; no fix is claimed.

  4. added theissue type on Oct 23, 2026
  5. XuPeng-SH commented on Oct 24, 2026

    @XuPeng-SH
    Contributor

    Tracking consolidated into #30417. The canonical issue now includes this report's independent scope and acceptance criteria. This is administrative consolidation, not a claim that the defect is fixed; the original reproduction and discussion are preserved here.

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions