Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute #36506

Merged

Conversation

kamipo
Copy link
Member

@kamipo kamipo commented Jun 17, 2019

GROUP BY with virtual count attribute is invalid for almost all
databases, but it is valid for PostgreSQL, and it had worked until Rails
5.2.2, so it is a regression for Rails 5.2.3 (caused by 311f001).

I can't find perfectly solution for fixing this for now, but I would not
like to break existing apps, so I decided to allow referencing virtual
count attribute in ORDER BY clause when GROUP BY aggrigation (it partly
revert the effect of 311f001) to fix the regression #36022.

Fixes #36022.

GROUP BY with virtual count attribute is invalid for almost all
databases, but it is valid for PostgreSQL, and it had worked until Rails
5.2.2, so it is a regression for Rails 5.2.3 (caused by 311f001).

I can't find perfectly solution for fixing this for now, but I would not
like to break existing apps, so I decided to allow referencing virtual
count attribute in ORDER BY clause when GROUP BY aggrigation (it partly
revert the effect of 311f001) to fix the regression rails#36022.

Fixes rails#36022.
@kamipo kamipo merged commit c104bfe into rails:master Jun 17, 2019
@kamipo kamipo deleted the group_by_with_order_by_virtual_count_attribute branch June 17, 2019 15:02
kamipo added a commit that referenced this pull request Jun 17, 2019
…count_attribute

PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute
kamipo added a commit that referenced this pull request Jun 17, 2019
…count_attribute

PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Combining .count with .group and ordering by :count generates invalid SQL in 5.2.3
1 participant