I was looking up the use of IFNULL() expression in db queries in Drupal and I found this module using it in HeartbeatStream::createQuery() (includes/heartbeatstream.inc).

// The user_access field holds the least access known. (NULL = HEARTBEAT_PUBLIC_TO_ALL).
$access_expression = "LEAST ( IFNULL ( ha.access, " . HEARTBEAT_PUBLIC_TO_ALL . "), IFNULL ( hut.status, " . HEARTBEAT_PUBLIC_TO_ALL . "))";

IFNULL is MySQL specific. For portability, use COALESCE as it is generic and is part of standard SQL. Docs from Mysql - http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#functio... but it is the same function syntax for PostgreSQL, Oracle and SQL Server.

Files: 
CommentFileSizeAuthor
coalesce_insteadof_ifnull-0.patch1.01 KBgirishmuraly

Comments

Status:Active» Needs review

Setting patch attached in first comment to needs review.

Great. Did not know that but I am happy to learn that.
Thx for the patch.

Thanks for the patch. Good thought about Portability.