Bug #96294 CAST of STRING with newlines to SIGNED/UNSIGNED returns unexpected result
Submitted: 23 Jul 2019 12:39 Modified: 1 Apr 2020 9:58
Reporter: Manuel Rigger Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.6/5.7/8.0 OS:Any
Assigned to: CPU Architecture:Any

[23 Jul 2019 12:39] Manuel Rigger
Description:
Consider the examples below:

How to repeat:
SELECT CAST('\n1' AS UNSIGNED); -- expected: 1, actual: 0
SELECT CAST('\n1' AS SIGNED); -- expected: 1, actual: 0
SELECT CAST('\t  1' AS SIGNED); -- 1
SELECT CAST('\n1' AS REAL); -- 1
SELECT CAST('\n1' AS FLOAT); -- 1
SELECT CAST('\n1' AS DECIMAL); -- 1

Casting a number contained in a string that has leading newlines yields the number for numeric types such as REAL, FLOAT, and DECIMAL. However, for UNSIGNED and SIGNED, 0 is returned. Like the other types, UNSIGNED and SIGNED ignore other whitespace characters, such as tabs and spaces, as shown in the example above.

This issue looks like it might be related to https://bugs.mysql.com/bug.php?id=95938, which has been fixed in 8.0.16.
[23 Jul 2019 13:19] MySQL Verification Team
Thank you for the bug report.
[24 Jul 2019 13:03] Oleksandr Peresypkin
The patches in the ticket https://bugs.mysql.com/bug.php?id=95960 are going to fix this issue as well.
[25 Jul 2019 16:20] Manuel Rigger
Thanks! So I guess we can consider this bug report a duplicate?
[26 Jul 2019 5:21] Oleksandr Peresypkin
Yes, I suppose so.
[1 Apr 2020 9:58] Manuel Rigger
Closing this issue.