I have been getting Data truncated when inserting data into a MySQL db. At first because I was using mediumint and the number was too large. Now because I am using a decimal(9,5), and python likes to change numbers. I believe that the problem is either that the numbers are looking like 1.02340000756 or it is -1 (the fields are unsigned). Is there a way to either see the number that caused the error (don't want to print all the inserts, for only a few cause problems) or disable the warnings?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ciao Mario,
I had seen the decimal module, but didn't realized it was what I needed. Set getcontext.prec to 5 (the size of the decimal portion in the db), and store all the values using Decimal(str(x)).
Gracie mille
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry for not explaining better. The integer column was causing problems until I changed the MEDIUMINT type. However, Don't want to use a double type, for it caused issues when testing, not to mention python's ability to ad digits to values. However, I am getting too many warnings, and was hoping there was a way to clean that up. In the string construct ('%s" % str(value)), I am forcing the number into a string (seems to clean the numbers better than a %f). Still every now and then I get a warning.
If there is a way to stop the warnings or clean the numbers, i would appreciate any help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
just a few reading hints, as I have the impression that you are facing a problem that is not typical of any program on your machine but of your hardware(1)... there is a solution to it inside of the standard library(2). if after checking the reading hints you think they were useless to you, would you mind being more specific? like giving some examples of numbers for which "Python adds digits to values", what precision you need, how your CREATE TABLE looks like?
I have been getting Data truncated when inserting data into a MySQL db. At first because I was using mediumint and the number was too large. Now because I am using a decimal(9,5), and python likes to change numbers. I believe that the problem is either that the numbers are looking like 1.02340000756 or it is -1 (the fields are unsigned). Is there a way to either see the number that caused the error (don't want to print all the inserts, for only a few cause problems) or disable the warnings?
Ciao Mario,
I had seen the decimal module, but didn't realized it was what I needed. Set getcontext.prec to 5 (the size of the decimal portion in the db), and store all the values using Decimal(str(x)).
Gracie mille
DECIMAL is not an integer column. If MEDIUMINT is not big enough, use INT.
Sorry for not explaining better. The integer column was causing problems until I changed the MEDIUMINT type. However, Don't want to use a double type, for it caused issues when testing, not to mention python's ability to ad digits to values. However, I am getting too many warnings, and was hoping there was a way to clean that up. In the string construct ('%s" % str(value)), I am forcing the number into a string (seems to clean the numbers better than a %f). Still every now and then I get a warning.
If there is a way to stop the warnings or clean the numbers, i would appreciate any help.
just a few reading hints, as I have the impression that you are facing a problem that is not typical of any program on your machine but of your hardware(1)... there is a solution to it inside of the standard library(2). if after checking the reading hints you think they were useless to you, would you mind being more specific? like giving some examples of numbers for which "Python adds digits to values", what precision you need, how your CREATE TABLE looks like?
(1) http://docs.python.org/tut/node16.html
(2) http://docs.python.org/lib/module-decimal.html
ciao,
Mario