Skip to content

[Bug]: CAST(non-numeric string AS DECIMAL) errors instead of returning 0.00 #30912

Closed as not planned

Description

@Ariznawlll

Description

CAST of a non-numeric string to DECIMAL raises a hard error, while MySQL returns 0.00 (with a truncation warning). CAST('abc' AS DECIMAL(10,2)) → ERROR 20301: "abc" is invalid decimal string on MatrixOne, 0.00 on MySQL. This is the DECIMAL entry point of the string→numeric strictness issue (the integer entry is #30911, the DOUBLE entry already returns 0 correctly).

Environment

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

Reproduction

SELECT CAST('abc' AS DECIMAL(10,2));
-- MatrixOne: ERROR 20301 (HY000) invalid input: "abc" is invalid decimal string
-- MySQL:     0.00   (Warning 1292: Truncated incorrect DECIMAL value: 'abc')

SELECT CAST('' AS DECIMAL(10,2));   -- MatrixOne: ERROR ;  MySQL: 0.00

-- Controls (already correct on MatrixOne):
SELECT CAST('12.345' AS DECIMAL(10,2));  -- 12.35  (both)
SELECT CAST('abc' AS DOUBLE);            -- 0      (both)

Root cause

The string→DECIMAL cast path rejects any string that is not a valid decimal literal, instead of MySQL's permissive behavior of returning 0.00 with a 1292 warning. The DOUBLE cast path already coerces non-numeric strings to 0, and the leading-numeric prefix works for DECIMAL too (CAST('12.345' ...)), so the defect is specifically the non-numeric-string fallback for DECIMAL.

Impact

  • CAST(v AS DECIMAL(p,s)) over mixed-quality VARCHAR columns fails the whole statement on the first non-numeric value, where MySQL would coerce it to 0.00.
  • Breaks monetary/normalization ETL (CAST(amount_str AS DECIMAL(12,2))) whenever source data contains stray text.

Expected behavior

CAST('abc' AS DECIMAL(10,2)) and CAST('' AS DECIMAL(10,2)) should return 0.00 (optionally with a truncation warning), matching MySQL and the already-correct DOUBLE path.

Activity

  1. added this to the MO-202610 milestone on Oct 23, 2026
  2. added
    duplicate
    on Oct 23, 2026
  3. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    This explicit string-to-numeric CAST failure is now tracked under #30911, which has been expanded to include DECIMAL targets as well as SIGNED/UNSIGNED integer targets. The parent records this report's decimal result, empty-string case, valid-prefix control, precision/scale, and warning expectations. The original reproduction remains here.

    Closing as a duplicate tracking item only; no fix is claimed.

  4. added theissue type on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

duplicatekind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions