COALESCE two dates returns binary?

耗尽温柔 提交于 2019-12-01 22:38:35

This is probably a bug that has been fixed: bug-35662

[28 Mar 2008 22:44] Patrick Crews

Description:
COALESCE(date, date) returns varbinary on 5.0.51a for Windows XP 32bit (only tested this flavor)

COALESCE(date,date) returns date on Mac OS

...
...
...

[31 Mar 2008 17:41] Omer BarNir
The bug was fixed in 5.0.52 and was not observed when testing 5.0.56 - closing

I still don't know why this happens in MySql Workbench (and also MS Visual Studio). But i have found a workaround. I just cast the result to DATETIME and it works as expected:

SELECT CAST(COALESCE( last_modified, date_purchased )AS DATETIME)As LastModifiedOrPurchased
FROM Orders
ORDER BY COALESCE( last_modified, date_purchased )DESC
LIMIT 1;

Edit: as Jack has commented, IFNULL works also:

SELECT IFNULL( last_modified, date_purchased )As LastModifiedOrPurchased
FROM Orders
ORDER BY IFNULL( last_modified, date_purchased )DESC
LIMIT 1;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!