I have the following issue:
When a user tries to create a new topic in og forum then the followings errors appears:
1) warning: pg_query() [function.pg-query]: Query failed: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list at character 276 in /var/www/sibportals2.icstweb.eu/includes/database.pgsql.inc on line 139.

2) user warning: query: SELECT DISTINCT t.* FROM term_node r INNER JOIN term_data t ON r.tid = t.tid INNER JOIN vocabulary v ON t.vid = v.vid LEFT JOIN og_term ogt ON ogt.tid = t.tid WHERE (ogt.public > 1 OR ogt.nid IN (166,16,164,20,6,24,22,28,75,72) AND t.tid != -1) AND ( r.vid = 148 )ORDER BY v.weight, t.weight, t.name in /var/www/sibportals2.icstweb.eu/modules/taxonomy/taxonomy.module on line 632.

Also when a user of a group tries to create a topic in a specific group then the following errors occurs:
warning: pg_query() [function.pg-query]: Query failed: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list at character 229 in /var/www/sibportals2.icstweb.eu/includes/database.pgsql.inc on line 139.

user warning: query: SELECT DISTINCT t.* FROM term_node r INNER JOIN term_data t ON r.tid = t.tid INNER JOIN vocabulary v ON t.vid = v.vid LEFT JOIN og_term ogt ON ogt.tid = t.tid WHERE (ogt.public > 1 AND t.tid != -1) AND ( r.vid = 170 )ORDER BY v.weight, t.weight, t.name in /var/www/sibportals2.icstweb.eu/modules/taxonomy/taxonomy.module on line 632.

warning: pg_query() [function.pg-query]: Query failed: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list at character 255 in /var/www/sibportals2.icstweb.eu/includes/database.pgsql.inc on line 139.

user warning: query: SELECT DISTINCT t.* FROM term_node r INNER JOIN term_data t ON r.tid = t.tid INNER JOIN vocabulary v ON t.vid = v.vid LEFT JOIN og_term ogt ON ogt.tid = t.tid WHERE (ogt.public > 1 OR ogt.nid IN (166,16,20) AND t.tid != -1) AND ( r.vid = 171 )ORDER BY v.weight, t.weight, t.name in /var/www/sibportals2.icstweb.eu/modules/taxonomy/taxonomy.module on line 632.

warning: pg_query() [function.pg-query]: Query failed: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list at character 255 in /var/www/sibportals2.icstweb.eu/includes/database.pgsql.inc on line 139.

user warning: query: SELECT DISTINCT t.* FROM term_node r INNER JOIN term_data t ON r.tid = t.tid INNER JOIN vocabulary v ON t.vid = v.vid LEFT JOIN og_term ogt ON ogt.tid = t.tid WHERE (ogt.public > 1 OR ogt.nid IN (166,16,20) AND t.tid != -1) AND ( r.vid = 294 )ORDER BY v.weight, t.weight, t.name in /var/www/sibportals2.icstweb.eu/modules/taxonomy/taxonomy.module on line 632.

I would be really grateful if someone could give me a hand..

Comments

-Mania-’s picture

I am getting errors as well, looks to be postgres related? I'm using the latest dev because the 2.2 stable version doesn't work for me (due to http://drupal.org/node/651672).

Creating a topic:

warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "WHERE" at character 112 in /var/vhost/drupal/drupal-6.19/includes/database.pgsql.inc on line 139.
user warning: query: SELECT COUNT(*) FROM node n INNER JOIN node_comment_statistics l INNER JOIN og_term ot INNER JOIN term_node tn WHERE ot.nid = 2 AND ot.tid = tn.tid AND tn.nid = n.nid AND n.nid = l.nid AND n.status = 1 AND n.type = 'forum' ORDER BY l.last_comment_timestamp DESC in /home/staff/username/vhost/www.mysite.com/modules/og_forum/og_forum.module on line 197

Viewing a forum:

warning: pg_query() [function.pg-query]: Query failed: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list in /var/vhost/drupal/drupal-6.19/includes/database.pgsql.inc on line 139.
user warning: query: SELECT DISTINCT t.* FROM term_node r INNER JOIN term_data t ON r.tid = t.tid INNER JOIN vocabulary v ON t.vid = v.vid LEFT JOIN og_term ogt ON ogt.tid = t.tid WHERE (ogt.public > 1 OR ogt.nid IN (2) AND t.tid != -1) AND ( r.vid = 2 )ORDER BY v.weight, t.weight, t.name in /var/vhost/drupal/drupal-6.19/modules/taxonomy/taxonomy.module on line 633.
warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "WHERE" at character 112 in /var/vhost/drupal/drupal-6.19/includes/database.pgsql.inc on line 139.
user warning: query: SELECT COUNT(*) FROM node n INNER JOIN node_comment_statistics l INNER JOIN og_term ot INNER JOIN term_node tn WHERE ot.nid = 2 AND ot.tid = tn.tid AND tn.nid = n.nid AND n.nid = l.nid AND n.status = 1 AND n.type = 'forum' ORDER BY l.last_comment_timestamp DESC in /home/staff/username/vhost/www.mysite.com/modules/og_forum/og_forum.module on line 197.
thepanz’s picture

This issue seems to be related to PostGRESQL engine.
Could you please further investigate in which part of the QUERY is causing the issue? AFAIK this could be related to a different syntax between MySQL and Postgres

Cheers

salvis’s picture

Assigned: m_dimitris » Unassigned

Citing from http://www.postgresql.org/docs/8.2/static/sql-select.html

For the INNER and OUTER join types, a join condition must be specified, namely exactly one of NATURAL, ON join_condition, or USING (join_column [, ...]).

You have to put the JOIN condition into the ON clause, such as

SELECT COUNT(*) FROM node n 
  INNER JOIN node_comment_statistics l ON n.nid = l.nid 
  INNER JOIN term_node tn ON n.nid = tn.nid 
  INNER JOIN og_term ot ON tn.tid = ot.tid
  WHERE ot.nid = 2 AND n.status = 1 AND n.type = 'forum'
  ORDER BY l.last_comment_timestamp DESC

Whenever you don't know how to do something, then look into the core or contrib code. In this case search for "INNER JOIN" to find plenty of examples of how to write inner joins.

markshep’s picture

To get rid of this error:

  • warning: pg_query(): Query failed: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list LINE 1: ...OR ogt.nid IN (5,3,1)) AND ( r.vid = 3 )ORDER BY v.weight, ... ^ in /blah/blah/blah/includes/database.pgsql.inc on line 138.
  • user warning: query: SELECT DISTINCT t.* FROM term_node r INNER JOIN term_data t ON r.tid = t.tid INNER JOIN vocabulary v ON t.vid = v.vid LEFT JOIN og_term ogt ON ogt.tid = t.tid WHERE (ogt.public > 1 OR ogt.nid IN (166,16,164,20,6,24,22,28,75,72) AND t.tid != -1) AND ( r.vid = 148 )ORDER BY v.weight, t.weight, t.name in /blah/blah/blah/modules/taxonomy/taxonomy.module on line 632.

I just changed the SQL query on line 632 of that file from SELECT t.* FROM {term_node}... to SELECT t.*, v.weight FROM {term_node}.... Hopefully that won't have any bad effects!

vegantriathlete’s picture

Version: 6.x-2.2 » 6.x-2.x-dev
Status: Active » Closed (won't fix)