Bug #34692 allow DECIMAL overflow to be reported as an error
Submitted: 20 Feb 2008 15:49 Modified: 31 Mar 2008 10:02
Reporter: Roland Bouman
Status: In progress
Category:Server: Types Severity:S3 (Non-critical)
Version:5.1.23 OS:Any
Assigned to: Alexey Botchkov Target Version:
Triage: Triaged: D5 (Feature request)

[20 Feb 2008 15:49] Roland Bouman
Description:
DECIMAL expressions can have a precision of 73 but DECIMAL column definitions can have a
maximum precision of 65. When DECIMAL overflow occurs in an expressionm, a warning is
issued, and the result is truncated to 65 decimal digits (65 9's)

it would be nice to
1) not truncate to 65 digits, instead do 73 9's
2) be able to set an sql_mode or similar that allows an overflow to be reported as an
error rather than a warning.

How to repeat:
create table d(
 d decimal(65,0)
);

insert into d values (12345678901234567890123456789012345678901234567890123456789012345)
;

select d * 100000000 from d;
+---------------------------------------------------------------------------+
| d * 100000000                                                             |
+---------------------------------------------------------------------------+
| 1234567890123456789012345678901234567890123456789012345678901234500000000 |
+---------------------------------------------------------------------------+
1 row in set (0.00 sec)

(73 digits maximum for expression)

select d * 1000000000 from d;
+-------------------------------------------------------------------+
| d * 1000000000                                                    |
+-------------------------------------------------------------------+
| 99999999999999999999999999999999999999999999999999999999999999999 |
+-------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

(warning and truncation occurs)

mysql> show warnings;
+-------+------+---------------------------------------+
| Level | Code | Message                               |
+-------+------+---------------------------------------+
| Error | 1292 | Truncated incorrect DECIMAL value: '' |
+-------+------+---------------------------------------+
1 row in set (0.00 sec)

Suggested fix:
Please add an SQL mode to allow DECIMAL overflow to be reported as an error
Also, don't truncate to 65 digits
[20 Feb 2008 19:29] Sveta Smirnova
Thank you for the report.

Verified as described.