Menu

Decimal type

Help
2010-01-30
2012-09-19
  • Alexey Smolsky

    Alexey Smolsky - 2010-01-30

    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?

     
  • Jack Repenning

    Jack Repenning - 2010-07-30

    Sounds more like your 't' values have exceeded 9999999.99. Is that possible?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.