I think it's mostly you. CAn you check and see if the mysql command-line client gives different results? I suspect floating-point approximations are the cause of your problem. For example, in the Python interpreter:
>>> 5.3
5.2999999999999998
Perhaps you can't do anything about this, but since you have a price, you should probably use a DECIMAL column. MySQLdb-1.2.0 returns these as decimal.Decimal, if it is available (Python-2.4 and newer); otherwise it returns it as a float.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
DECIMAL SQL columns are specifically for monetary values, or values with a fixed number of fractional digits, and so is the Python Decimal type, so it only makes sense to use them together. I think it will help to avoid comparision problems.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'select * from Item where price = 5.3'
gives 0 results in a table with a 5.3 price value, and a float field
'select * from item where price = 40' works fine
Is it just me that has this problem?
I think it's mostly you. CAn you check and see if the mysql command-line client gives different results? I suspect floating-point approximations are the cause of your problem. For example, in the Python interpreter:
>>> 5.3
5.2999999999999998
Perhaps you can't do anything about this, but since you have a price, you should probably use a DECIMAL column. MySQLdb-1.2.0 returns these as decimal.Decimal, if it is available (Python-2.4 and newer); otherwise it returns it as a float.
thanks for the tip about the Decimal! , is that the best aproach in mysqldb to work with monetary columns?
Well... try it and report back.
DECIMAL SQL columns are specifically for monetary values, or values with a fixed number of fractional digits, and so is the Python Decimal type, so it only makes sense to use them together. I think it will help to avoid comparision problems.