Bug #8449 Precision math: Silent column changes when DECIMAL definition invalid
Submitted: 11 Feb 2005 18:36 Modified: 8 Jul 2005 9:10
Reporter: Trudy Pelzer Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.3-alpha-debug OS:Linux (SuSE 9.1)
Assigned to: Alexey Botchkov CPU Architecture:Any

[11 Feb 2005 18:36] Trudy Pelzer
Description:
When a DECIMAL data type definition is invalid, the
enclosing statement should fail with SQLSTATE 42000
Incorrect column specifier for column. Instead, the
server accepts the statement and silently changes the
definition to a valid value.

How to repeat:
mysql> create table t1 (col1 decimal(0,38));
Query OK, 0 rows affected (0.01 sec)
-- This is an invalid definition: the scale may not be 
larger than the defined precision. This statement
should fail with SQLSTATE 42000.

mysql> show create table t1;
+-------+-------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                    |
+-------+-------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `col1` decimal(30,30) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+-------+-------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
-- Instead, the server changed the definition from DECIMAL(0,38)
to DECIMAL(30,30). This should never happen.

mysql> create table t2 (col1 decimal(0));
Query OK, 0 rows affected (0.01 sec)
-- Second example. This definition is also invalid: the precision
must be an integer greater than zero. So this statement should
fail with SQLSTATE 42000.

mysql> show create table t2;
+-------+------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                   |
+-------+------------------------------------------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (
  `col1` decimal(10,0) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+-------+------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
-- Instead, the server changed the definition from DECIMAL(0)
to DECIMAL(10,0). This should never happen.
[11 Feb 2005 18:48] MySQL Verification Team
Thank you for the bug report.
[2 Jun 2005 23:36] Peter Gulutzan
Also: there's a silent column change if I say DECIMAL(5,5), it becomes DECIMAL(6,5).
[10 Jun 2005 6:12] 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/internals/25845
[7 Jul 2005 16:48] 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/internals/26778
[8 Jul 2005 9:10] Alexey Botchkov
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html