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

V7.0.5 with Postgres: list(max:...) causes exception on totalCount #297

Closed
Grestorn opened this issue Jul 21, 2021 · 2 comments · Fixed by #756
Closed

V7.0.5 with Postgres: list(max:...) causes exception on totalCount #297

Grestorn opened this issue Jul 21, 2021 · 2 comments · Fixed by #756

Comments

@Grestorn
Copy link

I've just updated my rather large project to Grails 4.0.11 from 3.3. One problem which I couldn't fix seems to be a regression with GORM 7.0.5 on Postgres:

This simple code:

   def activity(Integer max) {
        max = max ?: 50
        params.max = max
        if(!params.sort)
            params.sort = "created"
        if(!params.order)
            params.order = "desc"

        def activityList = Activity.list(params)

        render view:"activity", model:[activityList: activityList, count: activityList.getTotalCount()]
    }

is translated by GORM into

select distinct count(activity0_.id) as col_0_0_ from grails_activity activity0_ order by activity0_.created desc

which, on postgresql causes the following exception

ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list

For "totalCount" there seems to be no necessity to even include the order clause to the SQL statement.

@Grestorn
Copy link
Author

It can be worked around by changing the above code to:

def activity(Integer max) {
        max = max ?: 50
        params.max = max
        if(!params.sort)
            params.sort = "created"
        if(!params.order)
            params.order = "desc"

        def activityList = Activity.findAll(params) {
            created != null
        }

        render view:"activity", model:[activityList: activityList, count: activityList.getTotalCount()]
    }

still the bug deserves to be fixed.

@darxriggs
Copy link
Contributor

There is a similar problem with MySQL when using sql_mode with ONLY_FULL_GROUP_BY.

It results in the following error:
ERROR 1140 (42000): Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants