List:General Discussion« Previous MessageNext Message »
From:Gerald Clark Date:February 8 2002 3:24pm
Subject:Re: Problems with select
View as plain text  
15.8 has no exact binary representation, so a test for  equality will fail.
Do not use floating point if you want to test for equality. Try DECIMAL

Miguel Figueiredo wrote:

>Hello all,
>
>I have a (probably dumb) question. 
>My table "temperatura" has two fields described bellow.
>
>mysql> describe temperatura;
>+-------------+----------+------+-----+---------+-------+
>| Field            | Type     | Null | Key | Default | Extra |
>+-------------+----------+------+-----+---------+-------+
>| datetime      | datetime | YES  |     | NULL    |       |
>| temperatura | float    | YES  |     | NULL    |       |
>+-------------+----------+------+-----+---------+-------+
>2 rows in set (0.00 sec)
>
>
>When I try to select rows with floats, the result is an empty set.
>For example:
>
>mysql> select datetime,temperatura from temperatura where 
>datetime="2002-02-08 09:30:00";
>+---------------------+-------------+
>| datetime            | temperatura |
>+---------------------+-------------+
>| 2002-02-08 09:30:00 |        15.8 |
>+---------------------+-------------+
>1 row in set (0.00 sec)
>
>----------------------------> got one row :)
>
>mysql>select datetime,temperatura from temperatura where datetime="2002-02-08 
>09:30:00" and temperatura=15.8;
>
>Empty set (0.00 sec)
>
>----------> same thing but with the temperatura value, gives me an empy set :(
>
>When I try to select another row but the temperatura field has an integer 
>this is what happens:
>
>mysql> select datetime,temperatura from temperatura where 
>datetime="2002-01-25 09:40:00";
>+---------------------+-------------+
>| datetime            | temperatura |
>+---------------------+-------------+
>| 2002-01-25 09:40:00 |          16 |
>+---------------------+-------------+
>1 row in set (0.00 sec)
>
>-----------> got one row :)
>
>mysql> select datetime,temperatura from temperatura where 
>datetime="2002-01-25 09:40:00" and temperatura=16;
>+---------------------+-------------+
>| datetime            | temperatura |
>+---------------------+-------------+
>| 2002-01-25 09:40:00 |          16 |
>+---------------------+-------------+
>1 row in set (0.00 sec)
>
>--------------> It works now :/
>
>Does anyone have an idea why this happens? How can I select float numbers?
>
>Best wishes,
>
>Miguel
>


Thread
Problems with selectMiguel Figueiredo8 Feb
  • Re: Problems with selectadmin8 Feb
  • Re: Problems with selectGerald Clark8 Feb
  • Re: Problems with selectDL Neil8 Feb
Re: Problems with selectalec.cawley8 Feb