[MDEV-380] conversion from string to decimal isn´t working (or i´m doing it wrong) Created: 2012-07-03  Updated: 2012-07-11  Resolved: 2012-07-11

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: 5.1.62
Fix Version/s: 5.5.25

Type: Bug Priority: Minor
Reporter: roberto spadim Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Environment:

i didn´t found the version, but it´s mariadb 5.3.2



 Description   

CREATE TABLE `tmp` (
`id` int(10) unsigned NOT NULL DEFAULT '0',
`datahora` decimal(17,6) NOT NULL DEFAULT '0.000000',
`value` decimal(20,10) NOT NULL DEFAULT '0.0000000000',
PRIMARY KEY (`id`,`datahora`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

====
INSERT INTO `tmp` (`id`, `datahora`, `value`) VALUES (1, 1340977500.000000, 1.0000000000);
====

this don´t work...:
SELECT * FROM tmp WHERE id=1 AND
datahora="1340977500.00000000000000"

this work: (without conversion)
SELECT * FROM tmp WHERE id=1 AND
datahora=1340977500.00000000000000

any idea?



 Comments   
Comment by Elena Stepanova [ 2012-07-03 ]

Hi Roberto,

Is there any particular reason why you expect the first comparison should work? (Did you find it documented somewhere, or something?)
Otherwise, you are comparing a numeric value to a string, there is no "conversion" as far as I can see.
Try to use CAST if you need to convert the value.

Comment by roberto spadim [ 2012-07-03 ]

no just because this:
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.0" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.00" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.000" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.0000" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.00000" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.000000" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.0000000" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.00000000" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.000000000" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.0000000000" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.00000000000" -> return 1 row
SELECT * FROM tmp WHERE id=1 AND datahora="1340977500.000000000000" -> don´t return (i don´t know why)

since 'datahora' field is DECIMAL(17,6) i don´t understand some things...
1) if there´s no 'conversion' from string "" to decimal to get rows at datahora fiel why any of this don´t returned a error?
2) ok, let´s say the 'conversion' is something that works, why it didn´t stop working at .0000000 (7 numbers) like decimal(17,6) definition?
3) there´s a reason why this work at .,00000000000 (11 numbers) and 12 numbers not ?

i din´t saw documentation , just using and trying =)

Comment by roberto spadim [ 2012-07-03 ]

some more info:
1)
explain extended select * from tmp where datahora="1340977500.00000000000" (this one work)
id;select_type;table;type;possible_keys;key;key_len;ref;rows;filtered;Extra
1;SIMPLE;tmp;system;NULL;NULL;NULL;NULL;1;100.00;

show warnings:
Level;Code;Message
Note;1003;select 1 AS `id`,1340977500.000000 AS `datahora`,1.0000000000 AS `value` from `33_sensors_log`.`tmp` where (1340977500.000000 = '1340977500.00000000000')

2)
explain extended
select * from tmp where datahora="1340977500.000000000000" (don´t work)
id;select_type;table;type;possible_keys;key;key_len;ref;rows;filtered;Extra
1;SIMPLE;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;Impossible WHERE noticed after reading const tables

show warnings:
Level;Code;Message
Note;1003;select 1 AS `id`,1340977500.000000 AS `datahora`,1.0000000000 AS `value` from `33_sensors_log`.`tmp` where (1340977500.000000 = '1340977500.000000000000')

Comment by roberto spadim [ 2012-07-03 ]

a bit more info

INSERT INTO `tmp` (`id`, `datahora`) VALUES (1, 1234);
1)
explain extended
select * from tmp where datahora="1340977500.00000000000" (this work)

id;select_type;table;type;possible_keys;key;key_len;ref;rows;filtered;Extra
1;SIMPLE;tmp;ALL;NULL;NULL;NULL;NULL;2;100.00;Using where

show warnings
Level;Code;Message
Note;1003;select `33_sensors_log`.`tmp`.`id` AS `id`,`33_sensors_log`.`tmp`.`datahora` AS `datahora`,`33_sensors_log`.`tmp`.`value` AS `value` from `33_sensors_log`.`tmp` where (`33_sensors_log`.`tmp`.`datahora` = '1340977500.00000000000')

2)
explain extended
select * from tmp where datahora="1340977500.000000000000" (don´t work)
id;select_type;table;type;possible_keys;key;key_len;ref;rows;filtered;Extra
1;SIMPLE;tmp;ALL;NULL;NULL;NULL;NULL;2;100.00;Using where

show warnings
Level;Code;Message
Note;1003;select `33_sensors_log`.`tmp`.`id` AS `id`,`33_sensors_log`.`tmp`.`datahora` AS `datahora`,`33_sensors_log`.`tmp`.`value` AS `value` from `33_sensors_log`.`tmp` where (`33_sensors_log`.`tmp`.`datahora` = '1340977500.000000000000')

Comment by roberto spadim [ 2012-07-04 ]

more information....
this last two posts was in version 5.3.2

i´m testing this in 5.5.23 now.... and it works, so ... sorry =) not a bug (for currently versions)... i will update the old server to a new version, tahnks
just to post here if someone need this info and get this page...
this 'should' work with any string size (right pad "0")
select * from tmp where datahora=
"1340977500.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
-> return 1 row as expected... (i tested with 1MB of "0" and worked too)

Comment by Elena Stepanova [ 2012-07-04 ]

>> i din´t saw documentation , just using and trying =)

Roberto,

Please do try to check documentation, it might save a lot of time. You can start from here http://dev.mysql.com/doc/refman/5.1/en/type-conversion.html, and browse further, depending on what you are curious about.
If after reading it you find out that the server doesn't work as expected, please point out at the exact inconsistency.

Thanks.

Comment by roberto spadim [ 2012-07-04 ]

in docs have some interesting informations...
mysql> SELECT '18015376320243458' = 18015376320243458;
-> 1
mysql> SELECT '18015376320243459' = 18015376320243459;
-> 0
but in my case, the string (the constant part) is in the right part and the field is in left (i don´t know if this change...)

i didn´t found information in my situation at this doc page... :/
since it doesnt matther (it is a old version of mariadb...) i think we can close bug, and leave here just for information ...

Comment by roberto spadim [ 2012-07-04 ]

sorry again...
there´s information, but i think it´s (old version 5.3.2) working in a diferent way (isn´t of float it convert to double or to decimal(17,6)... i dont know, just what i checked)

at doc: http://dev.mysql.com/doc/refman/5.5/en/type-conversion.html

*If one of the arguments is a decimal value, comparison depends on the other argument. The arguments are compared as decimal values if the other argument is a decimal or integer value, or as floating-point values if the other argument is a floating-point value. <<<<<<<--- not my case since one is decimal and other string, right?

*In all other cases, the arguments are compared as floating-point (real) numbers. <<<<<<<<<<----- my case?

Comment by Elena Stepanova [ 2012-07-11 ]

Hi Roberto,
Apparently so, if there is no more specific logic for your case described.
Anyway, since it's a MySQL 5.1 legacy issue, and has been fixed in 5.5, can we close the bug report?

Comment by roberto spadim [ 2012-07-11 ]

yes

Comment by roberto spadim [ 2012-07-11 ]

just a doubt, in this case, is the "=" being used as a <float-point "=" float-point> instead of a <decimal "=" decimal>?

Comment by Elena Stepanova [ 2012-07-11 ]

The effect is not observed in MariaDB or MySQL 5.5, only in 5.1-based versions.

Comment by Elena Stepanova [ 2012-07-11 ]

>> just a doubt, in this case, is the "=" being used as a <float-point "=" float-point> instead of a <decimal "=" decimal>?

Roberto,

For a general discussion, it would be more productive for you to use IRC, #mysql or #maria channel, they have a much bigger audience and suit better for talks or questions.

Comment by roberto spadim [ 2012-07-11 ]

nice thanks!

Generated at Thu Feb 08 06:28:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.