During my work when using python and MySQL, I've faced to
problem with updating DECIMAL fields. When I am executing a query
like that:
cursor.execute("UPDATE t SET v = v + %s", Decimal('0.30'))
on a table like that:
CREATE TABLE t (
t
v decimal(9,2) NOT NULL,
v
) ENGINE=MyISAM ;
INSERT INTO t VALUES (0.00);
sporadically I get "Warning: Data truncated for column 'v' at
row 1". I've analyzed MySQLdb a little, and found out that executed
query is "UPDATE t SET v = v + '0.30'". I think, because of these
single quotemarks, MySQL truncate something during computation of
expression.
Is this MySQL bug or do we need for MySQLdb patch to add Decimal
type conversion to string without quotes?
Sounds more like your 't' values have exceeded 9999999.99. Is that possible?
Log in to post a comment.
During my work when using python and MySQL, I've faced to
problem with updating DECIMAL fields. When I am executing a query
like that:
cursor.execute("UPDATE t SET v = v + %s", Decimal('0.30'))
on a table like that:
CREATE TABLE
t
(v
decimal(9,2) NOT NULL,) ENGINE=MyISAM ;
INSERT INTO
t
VALUES (0.00);sporadically I get "Warning: Data truncated for column 'v' at
row 1". I've analyzed MySQLdb a little, and found out that executed
query is "UPDATE t SET v = v + '0.30'". I think, because of these
single quotemarks, MySQL truncate something during computation of
expression.
Is this MySQL bug or do we need for MySQLdb patch to add Decimal
type conversion to string without quotes?
Sounds more like your 't' values have exceeded 9999999.99. Is that possible?