Bug #7052 Traditional: NUMERIC columns accept out of range values
Submitted: 6 Dec 2004 20:52 Modified: 6 Jan 2005 14:41
Reporter: Trudy Pelzer Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.3-alpha-debug OS:Linux (SuSE 9.1)
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[6 Dec 2004 20:52] Trudy Pelzer
Description:
When sql_mode='traditional', all columns with a numeric 
data type must reject out of range values. But if the 
data type is NUMERIC, MySQL accepts out of range values. 
 
Note: Per the SQL Standard, the difference between 
the DECIMAL and NUMERIC data types is that, for 
DECIMAL, the column may accept numbers with a 
greater precision than the defined precision but 
NUMERIC may not. Thus, a column defined as 
DECIMAL(5,2) may accept values greater than 
999.99 (e.g. 1000.00) and/or less than -999.99 
(e.g. -1000.00) but a NUMERIC(5,2) column may 
accept only values between -999.99 and +999.99. 

How to repeat:
mysql> CREATE TABLE t1 (col1 NUMERIC(4,2)); 
Query OK, 0 rows affected (0.01 sec) 
 
mysql> INSERT INTO t1 VALUES (10.55); 
Query OK, 1 row affected (0.00 sec) 
mysql> INSERT INTO t1 VALUES (-10.55); 
Query OK, 1 row affected (0.00 sec) 
-- These both show the correct response; the values 
exactly match the defined precision. 
 
mysql> INSERT INTO t1 VALUES (10.5555); 
Query OK, 1 row affected (0.00 sec) 
mysql> INSERT INTO t1 VALUES (-10.5555); 
Query OK, 1 row affected (0.00 sec) 
-- These both show the correct response; the extra 
digits in the scale will be rounded, as it normal. 
 
mysql> INSERT INTO t1  VALUES (101.55); 
Query OK, 1 row affected (0.00 sec) 
-- This is the incorrect response; a 3 digit precision  
cannot be assigned to a column that allows only 
2 digit precision. The INSERT should fail with 
SQLSTATE 22003 numeric value out of range.
[6 Dec 2004 23:05] Sergei Golubchik
It won't be fixed. Old  NUMERIC type is obsolete.
We only have to make sure that new NUMERIC type behaves correctly.
[6 Jan 2005 11:45] Sergei Golubchik
Sanja, could you check new decimal type doesn't have this problem ?