List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:December 21 2002 4:12am
Subject:Re: MySQL Decimal Column Types Question
View as plain text  
>  >>> For a 10,2 decimal column, should this be a valid number:
> 1234567890.12?
>>>
>>>  It's easy to test:
>>>
>>>  mysql> CREATE TABLE t (d DECIMAL(10,2));
>>>  Query OK, 0 rows affected (0.01 sec)
>>>
>>>  mysql> INSERT INTO t SET d = 1234567890.12;
>>>  Query OK, 1 row affected (0.01 sec)
>>>
>>>  mysql> SELECT * FROM t;
>>>  +--------------+
>>>  | d            |
>>>  +--------------+
>>>  | 999999999.99 |
>>>  +--------------+
>>>  1 row in set (0.00 sec)
>>>
>>>  The value's been clipped to the upper end of the range.
>>>
>>>  Your next question should be why that value has 9 digits to the left
>>>  of the decimal point. :-)
>>
>>
>>  How did you guess!  This behaviour is why I asked the question in the first
>>  place.  Why does it get clipped for a 10 digit number.  Without the decimal
>>  value I believe it inserts correctly, but with the 2 decimal places it get
>>  clipped...
>>  --
>>  Michael She  : michael.she@stripped
>>  Mobile       : (519) 589-7309
>>  WWW Homepage : http://www.binaryio.com/
>>
>>
>
>>>  mysql> INSERT INTO t SET d = 1234567890.12;
>>>  Query OK, 1 row affected (0.01 sec)
>
>A different question would be why does MySQL not generate an error or
>warning on the insert when it mangled the value?

The philosophy is that it's the clients responsibility not to insert
bad data.
Thread
MySQL Decimal Column Types QuestionMichael She20 Dec
  • Re: MySQL Decimal Column Types QuestionPaul DuBois21 Dec
    • Re: MySQL Decimal Column Types QuestionMichael She21 Dec
      • Re: MySQL Decimal Column Types QuestionJim Dickenson21 Dec
        • Re: MySQL Decimal Column Types QuestionPaul DuBois21 Dec
          • Re: MySQL Decimal Column Types QuestionMichael She21 Dec
      • Re: MySQL Decimal Column Types QuestionPaul DuBois21 Dec
        • Re: MySQL Decimal Column Types QuestionMichael She21 Dec