Sad.
Sad that the easiest way to fix The Error From Hell [1] was to use a search-and-replace function to “fix” the SQL (Structured Query Language) query [2].
Sigh.
$sql = preg_replace("/\s+\'\s+\'\s+([a-z]+)/"," ' ' AS \\1",$sql);
It's not perfect. It'll break if there's an SQL statement with a lowercase AS. But it'll have to do for now until I find a better regular expression.
To top it all off, I received the following from someone who has worked on porting SugarCRM [3] to PostgreSQL [4]:
The SugarFolk, I think due to rather obtuse source management and procedural policies, aren't interested in folding in my many improvements and PostgreSQL support. I moved on to other employment having nothing at all to do with SugarCRM or PHP (and very little to do with PostgreSQL), so I haven't worked on it. So it's officially dormant.
Sigh.