Bug #24558 Increasing decimal column length causes data loss
Submitted: 23 Nov 2006 20:35 Modified: 30 Mar 2007 19:30
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:5.1.14-beta-debug/5.0BK OS:Linux (SUSE 10.0 / 64-bit)
Assigned to: Ramil Kalimullin CPU Architecture:Any

[23 Nov 2006 20:35] Peter Gulutzan
Description:
I have a DECIMAL(18) column with an 18-digit number in it.
I alter the table so that the column is DECIMAL(19).
There is a warning and the number is changed.

See also bug#18014 (closed).

How to repeat:
mysql> create table t77 (s1 decimal(18)) engine=myisam;
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t77 values (123456789012345678);
Query OK, 1 row affected (0.01 sec)

mysql> alter table t77 modify column s1 decimal(19);
Query OK, 1 row affected, 1 warning (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 1

mysql> show warnings;
+-------+------+-----------------------------------------+
| Level | Code | Message                                 |
+-------+------+-----------------------------------------+
| Note  | 1265 | Data truncated for column 's1' at row 1 |
+-------+------+-----------------------------------------+
1 row in set (0.00 sec)

mysql> select * from t77;
+--------------------+
| s1                 |
+--------------------+
| 123456789012345700 |
+--------------------+
1 row in set (0.00 sec)
[23 Nov 2006 23:24] MySQL Verification Team
Thank you for the bug report. Verified as described on Suse 10 32-bit.
[10 Jan 2007 9:38] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/17835

ChangeSet@1.2354, 2007-01-10 13:38:00+04:00, ramil@mysql.com +3 -0
  Fix for bug #24558: Increasing decimal column length causes data loss
  
  Altering to a decimal field we get double value then store it 
  that may cause data loss. 
  Fix: use store_decimal() instead.
[15 Mar 2007 8:06] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/21976

ChangeSet@1.2466, 2007-03-15 12:06:06+04:00, ramil@mysql.com +3 -0
  Fix for bug #24558: Increasing decimal column length causes data loss
  
  Altering to a decimal field we get double value then store it 
  that may cause data loss. 
  Fix: use store_decimal() instead.
[22 Mar 2007 20:01] Mads Martin Joergensen
Fixed in 5.0.40 and 5.1.17
[30 Mar 2007 19:30] Paul DuBois
Noted in 5.0.40, 5.1.17 changelogs.