Bug #79292 cast('-123.9' as signed) returns -123, not expected -124
Submitted: 16 Nov 2015 9:48 Modified: 19 Nov 2015 21:56
Reporter: Su Dylan Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.0/5.1/5.5/5.6/5.7 OS:Any
Assigned to: CPU Architecture:Any

[16 Nov 2015 9:48] Su Dylan
Description:
Output:
=======
mysql> drop table if exists t1;
Query OK, 0 rows affected (0.01 sec)

mysql> create table t1(c1 int);
insert into t1 values('-123.9');
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1 values('-123.9');
Query OK, 1 row affected (0.00 sec)

mysql> select c1, cast('-123.9' as signed) from t1;
+------+--------------------------+
| c1   | cast('-123.9' as signed) |
+------+--------------------------+
| -124 |                     -123 |
+------+--------------------------+
1 row in set, 1 warning (0.00 sec)

mysql>
mysql>
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc  |
+-----------+
1 row in set (0.00 sec)

Problem:
========
In this example, in select list, c1 and "cast('-123.9' as signed)" are expected to return consistent result -124.

How to repeat:

drop table if exists t1;
create table t1(c1 int);
insert into t1 values('-123.9');
select c1, cast('-123.9' as signed) from t1;

Suggested fix:
In this example, in select list, c1 and "cast('-123.9' as signed)" are expected to return consistent result -124.
[16 Nov 2015 10:27] Peter Laursen
All (recent, at least) MySQL (and alos MariaDB) versions seem affected - for instance

SELECT VERSION(); -- 5.6.14-LOG 
SELECT CAST('-123.9' AS SIGNED); -- returns -123
SELECT CAST(-123.9 AS SIGNED); -- returns -124
[19 Nov 2015 21:56] MySQL Verification Team
Thank you for the bug report. Same behavior since 5.0.

C:\dbs>c:\dbs\5.7\bin\mysql -uroot -p --port=3570 --prompt="mysql 5.7 > "
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.10 Source distribution PULL: 2015-NOV-07

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql 5.7 > use test
Database changed
mysql 5.7 > drop table if exists t1;
Query OK, 0 rows affected (0.07 sec)

mysql 5.7 > create table t1(c1 int);
Query OK, 0 rows affected (0.03 sec)

mysql 5.7 > insert into t1 values('-123.9');
Query OK, 1 row affected (0.04 sec)

mysql 5.7 > select c1, cast('-123.9' as signed) from t1;
+------+--------------------------+
| c1   | cast('-123.9' as signed) |
+------+--------------------------+
| -124 |                     -123 |
+------+--------------------------+
1 row in set, 1 warning (0.17 sec)