Hi, I am using SQLAlchemy which is an very nice ORM under python: http://www.sqlalchemy.org/ I am only an amateur. I attach a file, which will be helpful for people willing to help me.
I am trying to make a query with a simple table containing integers and floats. The purpose of the query is to divide colB by colC. the result of the division is between 0 and 1, since 0 =< colB =<colC The query in sql is: SELECT * , CAST(Mytable.colB AS FLOAT) / CAST(Mytable.colC AS FLOAT)AS CALCUL FROM Mytable When I use the direct method execute in SQLAlchemy, the result is fine. Nevertheless, for some reasons, I would like to use the query object of SQLAlchemy. The query, translated into sql by SQLAlchemy, is (it returns tuple objects): SELECT mytable.id AS mytable_id, mytable."colA" AS "mytable_colA", mytable."colB" AS "mytable_colB", mytable."colC" AS "mytable_colC", CAST(mytable."colB" AS NUMERIC(10, 2)) / CAST(mytable."colC" AS NUMERIC(10, 2)) AS anon_1 FROM mytable ORDER BY mytable.oid This query does not return correct results: 1/10 should be 0.1 and not 0 It only returns correct results when the initial divisor is a float with a number different than 0 after the period: 3 / 4.0 returns 0 instead of .75 and 3 / 4.01 returns the correct result. As you can see, when using the query object, the columns are converted into Numeric, while when using direct sql with execute(), the translation seems to be Float. I asked the question to the sqlalchemy users-list and Mike Bayer told be that in sqlite, only real and numeric values are used: See http://groups.google.com/group/sqlalchemy/browse_thread/thread/a3cc437e0db6059a# Therefore, my question is: Can the above problem be due to sqlite ? I doubt since it returns correct results with my Query2 example. If not, does anybody know if my Query1 is wrong and why ? Sorry not to be as clear as I would have liked to. Thanks a lot in advance Dominique
_______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users