Skip to content

[Bug]: comparing INTEGER with a non-integer string errors ('1 = 1.0' fails; float path works) #31171

Closed as not planned

Description

@Ariznawlll

Description

Comparing an integer with a string raises invalid argument cast to int, bad value ... whenever the string is not a bare integer literal. MySQL coerces the string to a number (taking the numeric prefix, or 0) and compares. The same comparison against a float/decimal works fine, so the integer path is the outlier.

Environment

  • MatrixOne dev build (local multi-CN, main)
  • MySQL 8.0.45 control

Reproduction

Expression MO MySQL 8.0.45
SELECT 1 = '1.0' ERROR 20203 invalid argument cast to int, bad value 1.0 1
SELECT 1 = '1.5' ERROR 20203 0
SELECT 1 = '1x' ERROR 20203 1
SELECT 1 = '1e2' ERROR 20203 0
SELECT 100 = '1e2' ERROR 20203 1
SELECT 1.5 = '1.5' 1 ✓ 1
SELECT CAST(1 AS DECIMAL(5,1)) = '1.0' 1 ✓ 1

So: int vs string errors out, float/decimal vs string is correct. The problem is specific to the integer comparison path.

Root cause

The integer-vs-string comparison coerces the string operand with a strict integer parse (strconv.ParseInt-style, rejecting ., e, and any trailing characters). MySQL instead applies a lenient numeric prefix parse ('1.5'→1.5, '1x'→1, 'abc'→0) and then compares.

This is the same strictness that also shows up in explicit casts (CAST('1.5' AS SIGNED) errors, MySQL → 1), but the comparison path matters more because it happens implicitly in ordinary WHERE clauses and joins.

Impact

  • WHERE int_col = ? with a bound string parameter fails. Drivers that send parameters as strings (common with generic ORMs, JDBC setString, Python %s with a string value, JSON-sourced values) hit this on every integer column comparison:
    -- app sends '1.0' or '1' as a string parameter
    SELECT * FROM t WHERE id = '1.0';   -- MO errors, MySQL returns the row
  • Mixed-type joins (ON int_col = varchar_col) error as soon as a single non-bare-integer value appears in the varchar column, so the query fails at plan/exec rather than filtering.
  • Queries migrated from MySQL that rely on loose comparison (WHERE id = '0010', WHERE id = ' 10 ') break.
  • The inconsistency with the float path makes it hard to predict: 1.5 = '1.5' works while 1 = '1.0' does not.

Expected behavior

Coerce the string with MySQL's lenient numeric prefix rules and compare:

SELECT 1 = '1.0';    -- 1
SELECT 1 = '1.5';    -- 0
SELECT 1 = '1x';     -- 1
SELECT 100 = '1e2';  -- 1

If strictness is intentional for explicit CAST(... AS SIGNED), that is a separate decision — but implicit comparison should follow MySQL's lenient coercion, matching the already-correct float/decimal path.

Activity

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

    @Ariznawlll
    CollaboratorAuthor

    Adding concrete query-level evidence: this is not just a constant-folding edge case — five ordinary query shapes fail on a table whose VARCHAR column contains a non-numeric value.

    Setup (identical on both engines):

    CREATE TABLE ct_int (id INT PRIMARY KEY, v INT);
    CREATE TABLE ct_str (id INT PRIMARY KEY, k VARCHAR(10));
    INSERT INTO ct_int VALUES (1,10),(2,20),(3,30);
    INSERT INTO ct_str VALUES (1,'10'),(2,'20'),(3,'xx');   -- note the 'xx'
    Query MO MySQL
    SELECT COUNT(*) FROM ct_int a JOIN ct_str b ON a.v = b.k ERROR 20203 2
    SELECT COUNT(*) FROM ct_str WHERE k = 10 ERROR 20203 2
    SELECT COUNT(*) FROM ct_str WHERE k > 15 ERROR 20203 2
    SELECT GROUP_CONCAT(k ORDER BY k+0) FROM ct_str ERROR 20203 10,20,xx
    SELECT COUNT(*) FROM ct_int WHERE v IN (SELECT k FROM ct_str) ERROR 20203 2

    Two things make this worse than a single-bad-value problem:

    1. One non-numeric cell poisons the whole query. ct_str has three rows and only one is 'xx'; the presence of that single value makes every mixed int/varchar comparison fail — there is no per-row fallback to 0 like MySQL has.
    2. ORDER BY k+0 fails, which kills the standard workaround. MySQL users sorting numeric strings numerically (ORDER BY varchar_col + 0) hit the same error, so the documented escape hatch is unavailable.

    Note SELECT COUNT(*) FROM ct_int WHERE v = '10' (int column vs string literal) works — so only the direction where the string side is a column breaks. That asymmetry means the failure only appears against real data, never in unit tests with literals.

    The fix (lenient numeric prefix parse) should cover all expression contexts — comparison, join keys, IN, and arithmetic on a varchar column — not just literal-to-literal comparison.

  5. added
    severity/s0
    ai-easy
    and removed on Oct 26, 2026
  6. XuPeng-SH commented on Oct 26, 2026

    @XuPeng-SH
    Contributor

    Tracking consolidated into #30730. The canonical issue retains this report’s full reproduction/discussion and independent acceptance requirements. This is administrative consolidation, not a claim that the defect is fixed. Original evidence remains preserved here.

  7. Ariznawlll commented on Oct 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    The fix for this issue appears incomplete on main c6683bd2f5 (2026-10-29): literal-vs-literal comparisons now work (SELECT 1 = '1.0' returns 1), but the column-vs-integer predicate on real table data still hard-fails the whole statement whenever any row contains a non-numeric string, instead of MySQL's per-row coercion (bad value → 0 → no match):

    CREATE TABLE vt(id INT PRIMARY KEY, code VARCHAR(10));
    INSERT INTO vt VALUES (1,'007'),(2,'042'),(3,'abc');
    
    SELECT * FROM vt WHERE code = 7;
    -- ERROR 20203 (HY000): invalid argument cast to int, bad value abc
    -- MySQL 8.0: returns row (1,'007') — 'abc'→0, no match, no error
    
    DELETE FROM vt WHERE code = 7;
    -- same 20203 hard failure; MySQL deletes the '007' row
    
    SELECT * FROM vt WHERE code = 42;   -- works only while no bad row exists

    Notable properties of the残 gap:

    • The failure is data-dependent: the identical SQL succeeds after DELETE FROM vt WHERE id=3 (removing the 'abc' row) — a query that worked yesterday breaks the day one user enters a non-numeric code, making it a production landmine.
    • It blocks both reads and writes (SELECT and DELETE under the same predicate), and would equally poison UPDATE.
    • With only numeric-looking rows present, implicit cast semantics actually match MySQL ('007' matches 7), so the divergence is purely the error-vs-skip decision on bad rows.

    Given the original issue was closed as fixed, either the fix only covered the constant-folding path and not the row-evaluation path, or the row path deliberately errors — in which case this contradicts the MySQL-compat goal of the original report and deserves at least a documented truncation/warning mode.

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions