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

ORA-00979: not a GROUP BY #646

Open
kdima71 opened this issue Oct 5, 2024 · 9 comments
Open

ORA-00979: not a GROUP BY #646

kdima71 opened this issue Oct 5, 2024 · 9 comments

Comments

@kdima71
Copy link

kdima71 commented Oct 5, 2024

Moodle 4.1.13+
Customcert Version 2022112813 Release 4.1.6

Scheduled task failed: Issue certificates task (mod_customcert\task\issue_certificates_task
ORA-00979: not a GROUP BY expression SELECT c., ct.id as templateid, ct.name as templatename, ct.contextid, co.id as courseid, co.fullname as coursefullname, co.shortname as courseshortname FROM m_customcert c JOIN m_customcert_templates ct ON c.templateid = ct.id JOIN m_course co ON c.course = co.id JOIN m_course_categories cat ON co.category = cat.id LEFT JOIN m_customcert_issues ci ON c.id = ci.customcertid WHERE (c.emailstudents = :o_emailstudents OR c.emailteachers = :o_emailteachers OR LENGTH(c.emailothers) >= 3) AND co.visible = 1 AND cat.visible = 1 AND (co.enddate > :o_enddate OR (co.enddate = 0 AND ci.timecreated > :o_enddate2)) GROUP BY c.id, ct.id, ct.name, ct.contextid, co.id, co.fullname, co.shortname [array ( 'o_emailstudents' => 1, 'o_emailteachers' => 1, 'o_enddate' => 1696624757, 'o_enddate2' => 1696624757, )]) Debug info: ORA-00979: not a GROUP BY expression SELECT c., ct.id as templateid, ct.name as templatename, ct.contextid, co.id as courseid, co.fullname as coursefullname, co.shortname as courseshortname FROM m_customcert c JOIN m_customcert_templates ct ON c.templateid = ct.id JOIN m_course co ON c.course = co.id JOIN m_course_categories cat ON co.category = cat.id LEFT JOIN m_customcert_issues ci ON c.id = ci.customcertid WHERE (c.emailstudents = :o_emailstudents OR c.emailteachers = :o_emailteachers OR LENGTH(c.emailothers) >= 3) AND co.visible = 1 AND cat.visible = 1 AND (co.enddate > :o_enddate OR (co.enddate = 0 AND ci.timecreated > :o_enddate2)) GROUP BY c.id, ct.id, ct.name, ct.contextid, co.id, co.fullname, co.shortname [array ( 'o_emailstudents' => 1, 'o_emailteachers' => 1, 'o_enddate' => 1696624757, 'o_enddate2' => 1696624757, )] Backtrace: * line 277 of \lib\dml\oci_native_moodle_database.php: call to moodle_database->query_end() * line 1169 of \lib\dml\oci_native_moodle_database.php: call to oci_native_moodle_database->query_end() * line 94 of \mod\customcert\classes\task\issue_certificates_task.php: call to oci_native_moodle_database->get_records_sql() * line 263 of \lib\cronlib.php: call to mod_customcert\task\issue_certificates_task->execute() * line 120 of \lib\cronlib.php: call to cron_run_inner_scheduled_task() * line 73 of \lib\cronlib.php: call to cron_run_scheduled_tasks() * line 81 of \admin\cron.php: call to cron_run()

@mdjnelson
Copy link
Owner

mdjnelson commented Oct 6, 2024

Can you tell me if the following SQL helps with this?

SELECT 
    c.id, 
    c.templateid, 
    c.course, 
    c.emailstudents, 
    c.emailteachers, 
    c.emailothers,
    ct.id AS templateid, 
    ct.name AS templatename, 
    ct.contextid, 
    co.id AS courseid, 
    co.fullname AS coursefullname, 
    co.shortname AS courseshortname 
FROM 
    m_customcert c
JOIN 
    m_customcert_templates ct ON c.templateid = ct.id
JOIN 
    m_course co ON c.course = co.id
JOIN 
    m_course_categories cat ON co.category = cat.id
LEFT JOIN 
    m_customcert_issues ci ON c.id = ci.customcertid
WHERE 
    (c.emailstudents = :o_emailstudents 
    OR c.emailteachers = :o_emailteachers 
    OR LENGTH(c.emailothers) >= 3)
    AND co.visible = 1
    AND cat.visible = 1
    AND (co.enddate > :o_enddate 
        OR (co.enddate = 0 AND ci.timecreated > :o_enddate2))
GROUP BY 
    c.id, 
    c.templateid, 
    c.course, 
    c.emailstudents, 
    c.emailteachers, 
    c.emailothers, 
    ct.id, 
    ct.name, 
    ct.contextid, 
    co.id, 
    co.fullname, 
    co.shortname

It's basically just changing the fields that are selected.

@kdima71
Copy link
Author

kdima71 commented Oct 7, 2024

GROUP BY is used only when some group function in SELECT is used, for example COUNT, SUM, etc.

Therefore, it is necessary to remove the GROUP BY from the SQL query.

@mdjnelson
Copy link
Owner

Would you like to do a PR I can have a look at and contribute you to the code change?

@kdima71
Copy link
Author

kdima71 commented Oct 7, 2024

Unfortunately, I do not have the opportunity to participate.

At the moment, I have commented out this line in the «issue_certificates_task.php» class code as a temporary solution (workaround) and am awaiting the release of an official fix.

// $sql .= " GROUP BY c.id, ct.id, ct.name, ct.contextid, co.id, co.fullname, co.shortname";

mdjnelson added a commit that referenced this issue Oct 12, 2024
mdjnelson added a commit that referenced this issue Oct 12, 2024
mdjnelson added a commit that referenced this issue Oct 12, 2024
Also removed confusing comment.
mdjnelson added a commit that referenced this issue Oct 12, 2024
Also removed confusing comment.
mdjnelson added a commit that referenced this issue Oct 12, 2024
Also removed confusing comment.
mdjnelson added a commit that referenced this issue Oct 12, 2024
Also removed confusing comment.
mdjnelson added a commit that referenced this issue Oct 12, 2024
Also removed confusing comment.
mdjnelson added a commit that referenced this issue Oct 12, 2024
Also removed confusing comment.
@mdjnelson
Copy link
Owner

Pushed a fix to all branches, this should be solved now. :)

@kdima71
Copy link
Author

kdima71 commented Oct 13, 2024

Thank you very much!
Where can I download the fix?

@mdjnelson
Copy link
Owner

I've released a new version on the plugins DB. :)

@mdjnelson mdjnelson reopened this Nov 17, 2024
@mdjnelson
Copy link
Owner

This is still broken. On SQL server as well, see #649. Setting up Oracle and MSSQL docker images to test this against.

@kdima71
Copy link
Author

kdima71 commented Nov 18, 2024

Most likely, your task in this sql query is to arrange (sort) the data, instead of aggregating, so use ORDER BY instead of GROUP BY.

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

No branches or pull requests

2 participants