[MDEV-20343] CAST("18446744073709552001" AS INT) returns a wrong result Created: 2019-08-14 Updated: 2022-08-15 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Data types |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2, 10.3, 10.4 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Major |
| Reporter: | Alexander Barkov | Assignee: | Alexander Barkov |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Epic Link: | Data type cleanups |
| Description |
|
CAST("string-with-a-huge-number" AS INT) erroneously performs a binary complement:
The same problem is repeatable with CAST in dynamic columns:
Applying binary complement to string->int conversion is wrong. Binary complement should only be applied when converting between integer types of different signness. Note, implicit conversion works fine though:
Notice, unlike explicit CAST, implicit conversion does not apply binary complement. Instead, it correctly cuts the number to the maximum possible signed 64-bit value, which is 9223372036854775807. Explicit CAST should be fixed accordingly. |
| Comments |
| Comment by Andrei Lurie [ 2022-08-15 ] |
|
We ran into the same issue in 10.4 and 10.6: {{select cast('9999999999999999999' as int); select cast('-9999999999999999999' as int); select cast('9223372036854775808' as int); select cast('99999999999999999999' as int); |