The forum uses IF(condition, then, else) syntax in two places that break on PostgreSQL. However there is an equivalent CASE syntax that work on PostgreSQL and is supported on MySQL according to docs (http://dev.mysql.com/doc/refman/5.0/en/case-statement.html)

Attached is path that fixed forum tests from breaking in PostgreSQL.

1 down. 3 to go.

CommentFileSizeAuthor
fix-forum-pgsql.patch1.91 KBjosh waihi

Comments

josh waihi’s picture

Status: Active » Needs review

marking as needs review

andypost’s picture

damien tournoud’s picture

No objection. This said, PostgreSQL can and should also implement the IF() compatibility function, as sqlite already does.

andypost’s picture

We should document that using IF() is mysqlism

CASE() is ansi sql but IF() is db-specific

oracle and mssql does not support IF() syntax for DML

http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/expressio...
http://msdn.microsoft.com/en-us/library/ms189074.aspx and IF() http://msdn.microsoft.com/en-us/library/ms187471.aspx

damien tournoud’s picture

@andypost: the IF() function can (and IMO should) be implemented by all the Drivers. SQLite and SQL Server already do that.

andypost’s picture

@Damien Tournoud Could you explain any reason to write a custom function instead of using the standard?

IMO any custom function implementation makes install process a bit slower. Also is there any uninstall for custom functions?

josh waihi’s picture

I'd rather avoid custom functions as much as possible. Custom functions are slower. Take the FIRST() function PostgreSQL has to use in Views 2.

josh waihi’s picture

anyway, implementing an IF() function is a different issue. This fixes forums and fixes tests. We can commit this.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks!

It might be worth writing up a sub-page in the developer handbook about common MySQLisms that you might not know are MySQLisms and cause Pgsql and other dbs to puke all over themselves. And probably a patch to Coder module too, to catch this kind of thing.

andypost’s picture

A child page under http://drupal.org/node/555514 is a good place

andypost’s picture

josh waihi’s picture

#833138: MySQLism: Use CASE instead of IF(). added also. Will restructure both pages.

damien tournoud’s picture

We also have http://drupal.org/node/773090, which is an effort to document the functions and operators that *we actually support* against every database drivers. Seems like a better idea then trying to document everything we don't support.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.