Everything works as expected on my development machine, but when deploying to quality assurance environment, tests are failing because MariaDB is padding the result set with extra precision zeros after a decimal.
For example, when I run this query:
SELECT GREATEST( '2016-04-14 15:06:30', NOW() )
On dev, running Ubuntu 14.04.4 LTS (Trusty Tahr) mysql Ver 14.14 Distrib 5.5.47, for debian-linux-gnu (x86_64) using readline 6.3, I get this expected result:
2016-04-18 09:07:42
On test, running Red Hat Enterprise Linux Server 7.2 (Maipo) mysql Ver 15.1 Distrib 5.5.44-MariaDB, for Linux (x86_64) using readline 5.1, I get this unexpected result:
2016-04-18 09:07:42.000000
I don't see anything in the GREATEST()
documentation that would explain this behavior, so I think it must be a server configuration setting in my.cnf
but I couldn't find anything in online search results.
Even more curiously, when running the following queries, I get the same unpadded results on both machines:
SELECT GREATEST( '2016-04-14 15:06:30', '2016-04-14 16:06:30' )
2016-04-14 16:06:30
SELECT GREATEST( NOW(), NOW() )
2016-04-18 09:24:22
SELECT GREATEST( 5, 10 )
10
Why is MariaDB GREATEST()
padding/appending my result set with zeros on timestamp comparison with NOW()
?
now()
totimestamp
ordatetime(0)
, eg withSELECT GREATEST( '2016-04-14 15:06:30', CAST(NOW() AS TIMESTAMP))
?select greatest('2016-04-02 12:24:52',cast(now() as datetime(0)))
results in2016-04-18 14:17:22.000000
on both serversSELECT GREATEST(NOW(), '2016-04-14 15:06:30');
?SELECT GREATEST(NOW(), '2016-04-14 15:06:30');
results in2016-04-18 14:43:16
on Ubuntu, and2016-04-18 14:46:49.000000
on RedHat.DATE_FORMAT
, similarly to what is suggested in the answer but with reverse order:SELECT DATE_FORMAT( GREATEST(NOW(), '2016-04-14 15:06:30'), '%Y-%m-%d %H:%i:%s');
First compare the values, then convert to the format you want for display.