see this forum topics: http://drupal.org/node/122580

Seems that the SQL rewriting is badly broken for postgreSQL in some cases.

CommentFileSizeAuthor
#1 db_distinct_field.patch796 byteswizztick

Comments

wizztick’s picture

Status: Active » Needs review
StatusFileSize
new796 bytes

The case I encountered where of the form COUNT(DISTINCT ON (node.nid) node.nid) which should be COUNT(DISTINCT node.nid). In the forum topic divamys suggest a fix for db_distinct_field, which works for me. I attached the patch.
note: I run postgres 7.4.11. I do not know if this works for all query rewrites or for all versions of postgres.

greggles’s picture

I had a similar but different error related to pgsql so I tried this patch, but it didn't help (I didn't expected it too, but thought perhaps it might).

Here is the issue I finally posted: http://drupal.org/node/141362

pwolanin and wizztick - can you describe a simple test case so that I could provide a review of the patch?

I tried this path:

1. Create some content
2. Visit the /tracker page

Expected results:
Errors

Actual Results:
Worked fine

I'm on pgsql8.1.8 if that matters.

pwolanin’s picture

Unfortunately, I don't have a functioning postgreSQL local/test host- I was only reading about it in the linked forum topic. It's somewhere on my TODO list.

pearcec@drupal.org’s picture

I am having a similar issue:

http://drupal.org/node/153672

It looks like this might help me. I will examine the patch and test it.

pearcec@drupal.org’s picture

I tested it and hand to comment out

# $query = preg_replace('/(ORDER BY )(?!'.$table.'\.'.$field.')/', '\1'."$table.$field, ", $query);

as well. I don't want it ordering off of the DISTINCT field name. Maybe there is cases were it should be added. But I think it was added because with DISTINCT ON you have to have the field name in the ORDER BY or it won't work. I am going to examine the CVS commits to see if there is anything else to this.

drumm’s picture

Status: Needs review » Closed (duplicate)