On line 633, of the taxonomy.module file, the query is specified as:
$result = db_query(db_rewrite_sql('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.vid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $node->vid);
Which is problematic for postgresql because:
ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 7: ...L OR aclu_fa.uid = 0) AND ( r.vid = 10 )ORDER BY v.weight, ...
********** Error **********
ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
SQL state: 42P10
Character: 457
The query needs to be re-written like this:
$result = db_query(db_rewrite_sql('SELECT t.*,v.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.vid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $node->vid);
However, it would probably be a better idea to actually specify the fields rather than specifying a wildcard value in my opinion.
In any case, on line 633, my change works for postgresql. I do not have a mysql database to test this on.
I propose that my change be tested on MySQL and if it works, then move it into production.
Since most Drupal users settle for MySQL, this kind of query will not be problematic, hence the normal priority. Feel free to escalate however.
Comments
Comment #1
salvis#879270: Fix ORDER BY query in taxonomy.module to avoid db_rewrite_sql() producing PostgreSQL syntax error is older and has a patch.
Please review the patch.