Bug #43886 A warning is no longer given when casting a too large float to integer
Submitted: 26 Mar 2009 14:53 Modified: 27 Mar 2009 9:03
Reporter: Øystein Grøvlen Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:6.0 bzr OS:Any
Assigned to: CPU Architecture:Any

[26 Mar 2009 14:53] Øystein Grøvlen
Description:
A warning is not given when a large float value is truncated when it casted to integer.  According to the result file for the disabled main.cast test (has been able for a year), the following warning, used to be given in this situation:

Warning	1292	Truncated incorrect INTEGER value: '1e30'

I think it makes sense to warn the user in this situation, and the SQL standard
agrees that an exception should be generated.

How to repeat:
CREATE TABLE t1 (f1 double);
INSERT INTO t1 SET f1 = -1.0e+30 ;
INSERT INTO t1 SET f1 = +1.0e+30 ;
SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1;
[26 Mar 2009 15:44] MySQL Verification Team
Thank you for the bug report. I couldn't repeat on Windows 64-bit server with latest revision. Which source bzr tree you have tested?. Thanks in advance.

c:\dbs>c:\dbs\6.0\bin\mysql -uroot --port=3600 --prompt="mysql 6.0 > "
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 6.0.11-alpha-Win X64 revno: 2791-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql 6.0 > use test
Database changed
mysql 6.0 > CREATE TABLE t1 (f1 double);
Query OK, 0 rows affected (0.14 sec)

mysql 6.0 > INSERT INTO t1 SET f1 = -1.0e+30 ;
Query OK, 1 row affected (0.03 sec)

mysql 6.0 > INSERT INTO t1 SET f1 = +1.0e+30 ;
Query OK, 1 row affected (0.00 sec)

mysql 6.0 > SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1;
+------------+----------------------+
| double_val | cast_val             |
+------------+----------------------+
|      -1e30 | -9223372036854775808 |
|       1e30 |  9223372036854775807 |
+------------+----------------------+
2 rows in set, 2 warnings (0.03 sec)

mysql 6.0 > show warnings
    -> ;
+---------+------+--------------------------------------------+
| Level   | Code | Message                                    |
+---------+------+--------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: '-1e30' |
| Warning | 1292 | Truncated incorrect INTEGER value: '1e30'  |
+---------+------+--------------------------------------------+
2 rows in set (0.00 sec)
[27 Mar 2009 9:03] Øystein Grøvlen
My mistake. This issue is caused by my local changes.  I got mixed up with some other changes that have occurred while main.cast has been disabled.