On main page, before any user logs in, one can see several warnings like:
# warning: pg_query(): Query failed: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list in /var/www/drupal-6.16/includes/database.pgsql.inc on line 139.
# user warning: query: SELECT DISTINCT t.* FROM drupal_term_node r INNER JOIN drupal_term_data t ON r.tid = t.tid INNER JOIN drupal_vocabulary v ON t.vid = v.vid LEFT JOIN drupal_forum_access fa ON t.tid = fa.tid LEFT JOIN drupal_acl acl_fa ON acl_fa.name = CAST(t.tid AS VARCHAR) AND acl_fa.module = 'forum_access' LEFT JOIN drupal_acl_user aclu_fa ON aclu_fa.acl_id = acl_fa.acl_id AND aclu_fa.uid = 0 WHERE ((fa.grant_view >= 1 AND fa.rid IN (1)) OR fa.tid IS NULL OR aclu_fa.uid = 0) AND ( r.vid = 578 )ORDER BY v.weight, t.weight, t.name in /var/www/drupal-6.16/modules/taxonomy/taxonomy.module on line 617.
This happens on several different queries and modules, not just Taxonomy (also on "Image" for instance). The server is a Debian Squeeze/sid running apache 2.2.14-7 and php 5.3.1-5.
Comments
Comment #1
fjleal commentedAn important detail I forgot: DBMS is PostgreSQL 8.3. Maybe the SQL is valid for MySQL, that's being used on most installations, and hasn't been tested on Postgres?
Comment #2
miurahr commentedsimilar problem also on comment module line 314 in 6.15
That's because PostgreSQL implement strictly SELECT clause with ORDER BY.
A solution is simple. We need insert a column described in ORDER BY into SELET list.
see postgresql manual for select list.
http://www.postgresql.org/docs/8.3/static/sql-select.html#SQL-SELECT-LIST
for example,
It is no side effect because after this code block, it retrieves only $row->nid from results.
from the issue, proposal of fix is that
original:
changes
That's mean remove v.weight from ORDER BY.
It looks no bad side effect because the results will set into $term array indexed by vid and key.
Comment #3
fjleal commentedThank you miurahr for looking into the problem. I confirm removing v.weight from the ORDER BY list resolves the issue, since all other ordering fields are present in the SELECT list ("select t.* ..."). I'm not sure if there can be any particular situation where ordering by v.weight first may be meaningful... On my particular case it seems to be ok now.
Comment #4
roderikWhat ordering by v.weight does: if you have terms from several vocabularies attached to the node, the terms are always grouped per vocabulary. This seems nice to keep.
I tried solving this in a different way, which should catch all the errors. Patch is in comment #1 of #735120: Fix changes to db_distinct_field() in D6.16 / PostgreSQL.
No idea if that will get committed,assume that that issue will yield a 'proper' (as proper as possible) solution, in the end.