shantanu oak <[EMAIL PROTECTED]> wrote on 07/18/2005 01:17:57 PM:

> I am getting two different results for the same set of commands on two
> different versions of MySQL.
> Can anyone explain what the issue is?
> 
> CREATE TABLE `testdecimal` (
> `rate` decimal(7,4) NOT NULL default '0.0000'
> ) ENGINE=MyISAM; 
> 
> INSERT INTO testdecimal SET rate=1468;
> 
> select * from testdecimal;
> _____
> 
> version 4.1.12
> 1468.0000
> 
> version 5.0
> 999.9999
> 
> Shantanu Oak
> 


They fixed a bug. Count how many digits are in this number from your 
4.1.12 output:

           1468.0000
           ^^^^ ^^^^
           1234 5678

8 is more than 7. That violates your definition of (7,4). What you want is 
to declare (8.4) to be able to store numbers that large. The reason you 
get 999.9999 with 5.0 is because that is the number closest to your target 
value available for the field definition you declared.

The "old" behavior allowed an extra digit to possibly take the place of 
the "sign" marker (positive or negative) and since your number was not 
negative, your sign marker was "blank" which allowed your number to 
overflow its definition. That is the bug they fixed.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

Reply via email to