Can not UPDATE / DELETE rows in tables containing floats

[expired user #10835]'s profile image [expired user #10835] posted 7 years ago in General Permalink

Hello!

Consider a table containing a float value, for example this one:

CREATE TABLE `TestTable` (
    `MyInt` INT(11) NULL DEFAULT '0',
    `MyFloat` FLOAT NULL DEFAULT '0'
)
ENGINE=InnoDB;

which I created in a MariaDB.

A row can be inserted either by an SQL statement or using the GUI, which of course also executes an SQL statement:

INSERT INTO `MyTable`.`TestTable` (`MyInt`, `MyFloat`) 
VALUES ('10', '3.14159');

Now, trying to delete this row using the GUI, HeidiSQL displays the error 0 rows deleted were that should be 1. Almost the same happens when one tries to change a value of this row.

The reason is that HeidiSQL runs an SQL command in the background, which checks two floats for equality, which typically fails:

DELETE FROM `MyTAble`.`TestTable` 
WHERE  `MyInt`=10 AND `MyFloat`=3.14159 LIMIT 1;

Just to check;

SELECT *, (`MyFloat`-3.14159) AS 'Difference' from `TestTable`;

gives

MyInt  MyFloat  Difference
10     3.14159  0.00000011840820324238166

I understand that this is a dilemma, but may be there is a solution which can be implemented or is already there? (Note that I mean for editing the database by mouse, not by SQL commands)

[expired user #10835]'s profile image [expired user #10835] posted 7 years ago Permalink

Since I don't know how to edit my posting:

If a table contains a primary key column, HeidiSQL uses only this column to identify the row to be changed, and deleting/updating rows is no problem ( I guess as long as this column isn't a float...)

Please login to leave a reply, or register at first.