fix: usage of limit and order by usage in recursive cte

This commit is contained in:
kolaente 2024-02-28 14:35:09 +01:00
parent 6b1e67485b
commit 5b70609ba7
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 3 additions and 7 deletions

View File

@ -443,12 +443,8 @@ SELECT p.* FROM projects p
INNER JOIN all_projects ap ON p.parent_project_id = ap.id`
currentProjects := []*Project{}
err = s.SQL(`WITH RECURSIVE all_projects as (
`+baseQuery+`
ORDER BY position
`+limitSQL+`
)
SELECT * FROM all_projects GROUP BY all_projects.id ORDER BY position`, args...).Find(&currentProjects)
err = s.SQL(`WITH RECURSIVE all_projects as (`+baseQuery+`)
SELECT DISTINCT * FROM all_projects ORDER BY position `+limitSQL, args...).Find(&currentProjects)
if err != nil {
return
}
@ -459,7 +455,7 @@ SELECT * FROM all_projects GROUP BY all_projects.id ORDER BY position`, args...)
totalCount, err = s.
SQL(`WITH RECURSIVE all_projects as (`+baseQuery+`)
SELECT count(*) FROM all_projects`, args...).
SELECT count(*) FROM all_projects GROUP BY all_projects.id`, args...).
Count(&Project{})
if err != nil {
return nil, 0, err