The Archive module does not work properly with PostgreSQL for the following reasons.

Quoting: In PostgreSQL, double quotes signify a column name. Several queries in the Archive module use double quotes where single quotes should be used.

GROUP and ORDER: The archive pages use the following query, which fails in PostgreSQL:

$result = db_query(db_rewrite_sql("SELECT t.type, t.name, COUNT(n.nid) AS node_count FROM {node} n INNER JOIN {node_type} t ON t.type = n.type WHERE n.status = 1 AND t.type IN ('". join($types, "', '") ."') GROUP BY n.type ORDER BY n.created"))

I'm assuming that MySQL ORDERs the results before it GROUPs them. I can't comment as to whether this is correct from a standards standpoint, but this query fails in PostgreSQL.

You can get around this with PostgreSQL by using a sub-select. Here's code that works:

$result = db_query(db_rewrite_sql("SELECT r.type, r.name, COUNT(r.nid) AS node_count FROM (SELECT t.type, t.name, n.nid FROM {node} n INNER JOIN {node_type} t USING (type) WHERE n.status = 1 AND t.type IN ('". join($types, "', '") ."') ORDER BY n.created) AS r GROUP BY r.type, r.name"));

Patch: I'm attaching a patch that fixes both of these issues. Since I cannot test whether the sub-select will work in MySQL, I've created a simple test to see if $db_type = "pgsql" and if so, use the sub-select query. If that query works in MySQL as well, you can probably just use that one and get rid of the other version.

CommentFileSizeAuthor
#5 archive.pages_.inc_.diff1.38 KBAnonymous (not verified)
#1 archive.pages_.inc_.patch1.77 KBAnonymous (not verified)
archive.module.patch502 bytesAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

FileSize
1.77 KB
Susurrus’s picture

Status: Active » Needs review

It seems like standard SQL requires all fields in the ORDER BY clause to be returned in the data set. Can you try the following instead? I'd really like to minimize switching on DB_TYPE:

$result = db_query(db_rewrite_sql('SELECT t.type, t.name, COUNT(n.nid) AS node_count, n.type, n.created FROM {node} n INNER JOIN {node_type} t ON t.type = n.type WHERE n.status = 1 AND t.type IN ("'. join($types, '", "') .'") GROUP BY n.type ORDER BY n.created'));
Susurrus’s picture

I've committed all the changes for the double-quotes for 5.x and 6.x.

I'd still like your input on my suggestion in #2, as I'd prefer not to branch on the database type, especially since this won't be an issue anymore in 7.x

Susurrus’s picture

Status: Needs review » Needs work
Anonymous’s picture

FileSize
1.38 KB

Sorry it's taken awhile to reply. Had to find time to play around with it.

You have the right idea, you just put the column names in the wrong place. This patch works in postgres without having to branch. Hopefully it doesn't break mysql!

R.Muilwijk’s picture

Status: Needs work » Fixed

Patch seems to work fine for me so I committed it, thanks! If someone wants to backport this to drupal 5 he can reopen the issue.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.