Mysql – Why would Mysql’s Round(N.DD,1) sometimes show no digits after the decimal place when using the Perl DBI

MySQLmysql-5.5mysql-5.6perl

We have a set of calculations that do something like

SELECT ROUND(SUM(ROUND(3*IP))/3,1) as IP_sum from ….

Say for example that IP_sum is exactly 180.

When we call from the mysql client we get 180.0 every time, but if we use the perl dbi, the result depends on IP's column type.

When IP is a decimal(7,1) we get one digit and IP_sum => '180.0'
When IP is a float(7,1) we don't get any digits => IP_sum => '180'

Is anyone aware of a new change or update to the Perl DBI that might be causing this? We just updated some modules and programs this week.

Engine: Mysql 5.6, mysql client, 5.5.

Best Answer

This was unrelated to MySQL and was due to a change in the Perl DBD::mysql packages from version 4.013 to 4.042. Essentially, DBD::mysql now attempts to coerce the MySQL datatype into a Perl datatype. So, previously, a float of 4.0 would be returned as a string '4.0', but now the same float will be returned as a numeric value and be displayed as '4' when printed (without additional formatting on the part of Perl.