Repository navigation
Description
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, JDBCsetString, Python%swith 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 while1 = '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'; -- 1If 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
Ariznawlll commentedon Oct 26, 2026
Adding concrete query-level evidence: this is not just a constant-folding edge case — five ordinary query shapes fail on a table whose
VARCHARcolumn contains a non-numeric value.Setup (identical on both engines):
SELECT COUNT(*) FROM ct_int a JOIN ct_str b ON a.v = b.kSELECT COUNT(*) FROM ct_str WHERE k = 10SELECT COUNT(*) FROM ct_str WHERE k > 15SELECT GROUP_CONCAT(k ORDER BY k+0) FROM ct_str10,20,xxSELECT COUNT(*) FROM ct_int WHERE v IN (SELECT k FROM ct_str)Two things make this worse than a single-bad-value problem:
ct_strhas 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.ORDER BY k+0fails, 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.XuPeng-SH commentedon Oct 26, 2026
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.
Ariznawlll commentedon Oct 29, 2026
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):Notable properties of the残 gap:
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.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.