DDC-2836: DQL errors when attempting to use GROUP BY MAX(field) #3589

Closed
doctrinebot opened this Issue Mar 26, 2013 · 6 comments

2 participants

@doctrinebot

Jira issue originally created by user intel352:

Attempting to run DQL similar to:
SELECT a FROM ClassName a GROUP BY MAX(a.depth)

Throws error:
[Semantical Error] line 0, col 250 near 'MAX(ao.depth)': Error: Cannot group by undefined identification or result variable.

Per docs, MAX is allowed within GROUP BY: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#aggregate-functions

If this error is due to some omission on my part, then perhaps the docs should be extended to show a valid GROUP BY MAX() usage, or the error message expanded for a better hint.

@doctrinebot

Comment created by @ocramius:

Grouping by MAX() is not supported, as MAX() is already an aggregation

@doctrinebot

Issue was closed with resolution "Invalid"

@doctrinebot

Comment created by intel352:

Shame, because that is useful functionality in SQL. So I assume this means the documentation will be correct then?

@doctrinebot

Comment created by @ocramius:

[~intel352] did you check if the EBNF allows that?

@doctrinebot

Comment created by intel352:

Per the doc link in my initial report, the docs say that the aggregation functions are allowed in both SELECT and GROUP BY clauses.

{quote}The following aggregate functions are allowed in SELECT and GROUP BY clauses: AVG, COUNT, MIN, MAX, SUM{quote}

Searching EBNF in same page, one of items supported for GROUP BY is:
{quote}/** ResultVariable identifier usage of mapped field aliases (the "total" of "COUNT() AS total") */
ResultVariable = identifier{quote}

So I assume that means we'd have to move AVG, COUNT, MIN, MAX, SUM into the SELECT statement, using SELECT AS , and then GROUP BY ?

@doctrinebot

Comment created by @ocramius:

[~intel352] I think the syntax allows that, but you should give it a try. I don't see how that is supposed to work given how GROUP BY works in various RDBMS implementations

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment