I'm using postgreSQL 9, but I guess the exception could raise with any PG version. I also tried the TagClouds development version and got the same error.

PDOException: SQLSTATE[42703]: Undefined column: 7 ERROR: column "count" does not exist LINE 7:
    ... BY td.tid, td.vid, td.name, td.description HAVING count > 0 ^:
    SELECT td.tid AS tid, td.vid AS vid, td.name AS name, td.description AS description, tn.nid AS nid, COUNT(*) AS count
           FROM {taxonomy_term_data} td
          INNER JOIN {taxonomy_index} tn ON td.tid = tn.tid
          INNER JOIN {node} n ON tn.nid = n.nid
          WHERE (td.vid IN (:db_condition_placeholder_0))
          GROUP BY td.tid, td.vid, td.name, td.description
         HAVING count > 0
         ORDER BY count DESC LIMIT 12 OFFSET 0;
Array ( [:db_condition_placeholder_0] => 2 ) in tagclouds_get_tags() (line 225 of drupal-7.10/sites/all/modules/tagclouds/tagclouds.module).

The query resulting from the db_select should be (maybe... sorry I'm not a PHP developer. Anyway it does the job)

SELECT td.tid AS tid, td.vid AS vid, td.name AS name, td.description AS description, tn.nid AS nid, COUNT(*)
    FROM blog.taxonomy_term_data td
    INNER JOIN blog.taxonomy_index tn ON td.tid = tn.tid
    INNER JOIN blog.node n ON tn.nid = n.nid
    WHERE  (td.vid IN  ('2'))
    GROUP BY td.tid, td.vid, td.name, td.description, tn.nid HAVING COUNT(*) > 0
    ORDER BY COUNT(*) DESC
    LIMIT 12 OFFSET 0

PG should be smart enough to only process COUNT(*) once

Comments

MGParisi’s picture

Not sure how to fix this and/or test this as I don't have a setup that uses PG:(
PDO should handle this but it is not. Not sure as to why...

Uclio’s picture

Yep, I guessed. I saw somewhere a post talking about counting the resulting rows after the query. Maybe could be that a solution ? I'm willing of course to test any patch of you. I'm using Tagadelic (it works with PG) currently, but I'd like more showing the tags' count. It looks better and cleaner.

MGParisi’s picture

I would love to support PG. It would be a nice option.

MGParisi’s picture

Status: Active » Needs work

Set to Needs Work! Please submit a patch if you can get it to work:)

Uclio’s picture

Unfortunately not (I'm still using Tagadelic). Just replacing count with COUNT(*) doesn't work. This way the query completes with no errors, but the resulting weight for each tag is always 1. Likely the query should be in some way refactored, but I can't do that since I'm not in the PHP thing.

Hint: the PostgreSQL installation is pretty simple and in a Linux VM you have it almost for free ;-)

simonlnu’s picture

maybe single quoting the 'count' in the 'AS count' part?

i.e.:

SELECT td.tid AS tid, td.vid AS vid, td.name AS name, td.description AS description, tn.nid AS nid, COUNT(*) as 'count'
    FROM blog.taxonomy_term_data td
    INNER JOIN blog.taxonomy_index tn ON td.tid = tn.tid
    INNER JOIN blog.node n ON tn.nid = n.nid
    WHERE  (td.vid IN  ('2'))
    GROUP BY td.tid, td.vid, td.name, td.description, tn.nid HAVING COUNT(*) > 0
    ORDER BY COUNT(*) DESC
    LIMIT 12 OFFSET 0
simonlnu’s picture

ok, never mind that... didn't work

simonlnu’s picture

saw something here that might help:

http://archives.postgresql.org/pgsql-sql/2001-11/msg00366.php

http://stackoverflow.com/questions/3004887/how-to-do-a-postgresql-subque...

these are what were posted to second link. i'm including them here only as an example of how to do it.

select n1.name, n1.author_id, count_1, total_count
  from (select id, name, author_id, count(1) as count_1
          from names
          group by id, name, author_id) n1
inner join (select id, author_id, count(1) as total_count
              from names
              group by id, author_id) n2
  on (n2.id = n1.id and n2.author_id = n1.author_id)
select n1.name, n1.author_id, cast(count_1 as numeric)/total_count
  from (select id, name, author_id, count(1) as count_1
          from names
          group by id, name, author_id) n1
inner join (select author_id, count(1) as total_count
              from names
              group by author_id) n2
  on (n2.author_id = n1.author_id)

this, is what i think might work:

SELECT td.tid AS tid, td.vid AS vid, td.name AS name, td.description AS description, tn.nid AS nid, COUNT(*) AS count_all
           FROM {taxonomy_term_data} td
          INNER JOIN {taxonomy_index} tn ON td.tid = tn.tid
          INNER JOIN {node} n ON tn.nid = n.nid
          WHERE (td.vid IN (:db_condition_placeholder_0))
          GROUP BY td.tid, td.vid, td.name, td.description
         HAVING count_all > 0
         ORDER BY count DESC LIMIT 12 OFFSET 0;
brylie’s picture

Version: 7.x-1.1 » 7.x-1.x-dev

I am also interested in this bug. Watching.

daftu’s picture

Same issue here. Please fix.
Watching.

iuvanham’s picture

Possible fix, works for pgsql 8.4
In tagscloud.module modify as follows:
(line 222 to 234)

    $query = db_select('taxonomy_term_data', 'td');
    $query->addExpression('COUNT(*)', 'count');
    $query->fields('td',array('tid', 'vid', 'name', 'description'));
 //   $query->fields('tn',array('nid'));
    $query->addExpression('max(n.nid)', 'nid');
    $query->join('taxonomy_index', 'tn', 'td.tid = tn.tid');
    $query->join('node', 'n', 'tn.nid = n.nid');
    if (variable_get('tagclouds_language_separation', 0)) $query->condition('n.language', $language->language);
    $query->condition('td.vid', $vids);
    $query->condition('n.status', 1);
    $query->groupBy('td.tid')->groupBy('td.vid')->groupBy('td.name');//->groupBy('tn.nid');
    $query->groupBy('td.description HAVING COUNT(*) > 0');
    $query->orderBy('COUNT(*)', 'DESC');
MGParisi’s picture

Can I get a .patch?

ben coleman’s picture

Status: Needs work » Needs review
StatusFileSize
new1.55 KB

This is a patch corresponding to the code changes in #11. This appears to work ok in PostgreSQL 9.1.

joseph.olstad’s picture

The patch from #13 works also in Postgres 8.4 and also works in Postgres 9.3 (tested here)

Thanks!

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

This patch works on postgres and needs to be taken upstream as we and others use postgresql with drupal.

Asking for co-maintainer priviledges.

I have various environments am able to test this against mysql and postgresql.

MGParisi’s picture

Your wish has been granted. I just dont have the time to apply pacths right now. Would love the help!

Mike

joseph.olstad’s picture

Assigned: Unassigned » joseph.olstad

The patch works in either MySQL 5.1.73 or PostgresSQL 8.4 or 9.3

I don't see any reason why it wouldn't work with other versions of those and other db's as the change is on the user side of the drupal data abstraction layer.

Obviously the original code exposed some weakness in the postgres portion of the drupal database abstraction layer but the patch completely avoids that and it works.

*asking for co-maintainer access again* to commit this patch (the was a problem with my drupal.org account that seems to be resolved now (knock on wood))

  • joseph.olstad committed 4fcc849 on 7.x-1.x
    Issue #1425844 by Uclio, Ben Coleman, simonlnu, iuvanham, joseph.olstad...
joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed

Committed patch to the dev branch and attributed contributions to Uclio, Ben Coleman, simonlnu, iuvanham.

Thanks Uclio, Ben Coleman, simonlnu, and iuvanham.

MGParisi’s picture

Thanks Joseph!

joseph.olstad’s picture

Status: Fixed » Closed (fixed)