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