While doing the "getting started" exercise I began to get error messages when I was at the part where you add an argument based on the User role. The issue related to the syntax of the GROUP BY clause in the generated query. I'm using postgres and postgres requires all non-aggregate select fields in an aggregate query to be matched by the group by fields.
I have made a patch that touches query.inc and argument.handlers.inc that fixes this problem but needs a review.
All the source files can be found here: http://placeofdreams.org/views-group-by.zip
I've attached 2 ed style diff files with my changes for your perusal.
Cheers
Cal
PS I'm using postgres version 7.4 - however my changes should work with any version.
Comment | File | Size | Author |
---|---|---|---|
#10 | 291079_query.inc_group_by_2.patch | 1.48 KB | jaydub |
#9 | 291079_query.inc_group_by_2.patch | 1.53 KB | sammys |
#6 | 291079_query.inc_group_by.patch | 1.52 KB | sammys |
argument.handlers.inc_.diff | 246 bytes | cwoodruf | |
query.inc_.diff | 809 bytes | cwoodruf | |
Comments
Comment #1
sammys CreditAttribution: sammys commentedI have run into the same issue. Will patch and report back.
--
Sammy Spets
Drupal core maintainer (PostgreSQL)
Synerger Pty Ltd
http://synerger.com
Comment #2
sammys CreditAttribution: sammys commentedok. I've tested out the patch and it appears to work. Nice work on fixing the issue cwoodruf. The patch appears to deal with two problems so we'll have to split this out into more manageable issues.
I'll add an issue to the queue for the second one and follow-up with a link to that. This issue is dependent on that one.
Comment #3
sammys CreditAttribution: sammys commentedOk the issue for 2) above is http://drupal.org/node/291292. Setting issue to critical priority as views does not function on postgresql. Also setting it to CNW because patches are in ed format, doesn't use drupal code style and uses an 'and' instead of an 'or' for $isaggregate and $this->groupby.
Comment #4
sammys CreditAttribution: sammys commentedAssigning to me.
Comment #5
sammys CreditAttribution: sammys commentedRerolled the ed format patch and drupalized the code (true to TRUE etc). Tested it on PostgreSQL 8.2 and it works. No difference between 8.2 and 7.4 in this department so assuming it works for 7.4. Needs review on MySQL before we can set it to RTBC.
Comment #6
sammys CreditAttribution: sammys commentedAlways too quick to hit the submit button. Here's the patch. This requires the patch in http://drupal.org/node/291292 before it'll work.
Comment #7
merlinofchaos CreditAttribution: merlinofchaos commentedOk, so I don't have pgsql available to test on, but you are the recognized expert. The patch looks ok on a visual inspection, so I have committed this. Let's see who notices!
Comment #8
merlinofchaos CreditAttribution: merlinofchaos commentedHmm. I just had to roll this back; it broke MySQL.
Comment #9
sammys CreditAttribution: sammys commentedThanks for having a go at it merlinofchaos!
Yeah the patch in this issue requires the patch in http://drupal.org/node/291292 to work. Definitely won't work otherwise.
Also, the queries you pasted have group by fields duplicated. I've rerolled the patch to have a call to array_unique() around the array_merge(). Now to get that other patch thru. :)
Marking as CNR again since it wasn't reviewed with the dependency in place.
Comment #10
jaydub CreditAttribution: jaydub commentedI too ran into this after trying out the Views 2 documentation 'Getting Started' examples. I use PostgreSQL for 90% of my tinkering and try to help where I can. I've generated updated patches to this issue and to #291292: Count and distinct field properties not set for summaries. I certainly don't know enough of the Views 2 internals to call this a true patch review but I'll settle for submitting a re-roll in hopes that some progress can be made here.
After applying the 2 re-rolled patches I don't run into the problems with the GROUP BY in PostgreSQL. I exported the view to a MySQL based d6 install running on the same drupal codebase and the the view runs without error.
Tested on PostgreSQL 8.3
Comment #11
merlinofchaos CreditAttribution: merlinofchaos commentedHopefully this time all will work!
Comment #13
johanneshahn CreditAttribution: johanneshahn commentedHi,
new postgreSQL functionality breaks grouping with mysql.
can we clear $non_aggregates if Database is mysql?
Comment #14
MarcusF CreditAttribution: MarcusF commentedAny changes in this topic?
Comment #15
iamjon CreditAttribution: iamjon commentedAdding tag
Comment #16
AlexisWilke CreditAttribution: AlexisWilke commentedI got that problem for a long time too. Still happening in 6.x-3.x-dev...
The actual PostgreSQL error:
Query failed: ERROR: column "node.nid" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: SELECT DISTINCT(node.nid) AS nid_1
Thank you.
Alexis Wilke
Comment #17
dawehnerThis distinct is added by node.module or?
No idea how this can be fixed out of views.
Comment #18
dawehner@AlexisWilke
By just looking at your message, there is no groupby involved here.
In general can you try to help to reproduce this problem? For example post an export with just default fields.
Comment #19
AlexisWilke CreditAttribution: AlexisWilke commentedOkay, good point. The GRANT system adds the DISTINCT because of the Node privacy byrole module I'm using...
The DISTINCT is added with this function:
and as you can see, they do not do anything else than add the DISTINCT (i.e. no consideration for a GROUP BY.)
Someone, somewhere, calls db_rewrite_sql(), which calls the _db_rewrite_sql() internal function. That function calls all the module-name_db_rewrite_sql() functions. The node implementation looks like this:
and as we can see the $return array includes the 'distinct' flag set to 1.
On return in the db_rewrite_sql() function, this is tested first and the distinct function is called:
What looks surprising is that in the error I get, the node.nid is between parenthesis. This may be because someone adds them later? (views? to and the "AS nid_1"?)
The GRANT system is something from Core so it should be fully supported by views, I think.
I would suggest a hack, something like this, forcing distinct because the GRANT system adds it and thus whether the user select that flag is not significant anymore, it is required. But I'm not too sure where it would need to be checked or whether it would be too late anyway (i.e. the db_rewrite_sql() is called after you generate the SQL order... in which case you'd have to re-generate the SQL with distinct turn on, but only if the DB is psql.)
That reminds me I have a few fixes (i.e. added a few GROUP BY) in Core so it works properly with PostgreSQL... So Core is really doing it wrong.
Below is my view export. Really nothing extraordinary...
Thank you.
Alexis
Comment #20
AlexisWilke CreditAttribution: AlexisWilke commentedNevermind...
(1) my view uses Distinct;
(2) I tried with the Disable SQL rewriting flag and it still doesn't work (no group by.)
Therefore, this is 100% a view bug!
The following is the SQL generated by Views when I edit the view with the problem (notice the lack of node protected by role references):
Since right now I do not need the DISTINCT I removed that flag so at least that view works. But that means the Distinct flag doesn't work and since it is set by default, that's a problem...
Thank you.
Alexis
Comment #21
Liam MorlandTagging
Comment #22
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe Drupal 6 branch is no longer supported, please check with the D6LTS project if you need further support. For more information as to why this issue was closed, please see issue #3030347: Plan to clean process issue queue