middlebury/moodle-mod_adaptivequiz

Postgresql Group By error

Closed this issue · 2 comments

There are two locations where a " GROUP BY clause or be used in an aggregate function" error occurs.
In fetchquestion.class.php -> function retrieve_tags_with_question_count(...)
(Approx ln 437) $records = $DB->get_records_sql_menu($sql, $params);
And....
In viewreport.php (Approx ln 142)

Will return the following error (this output is from fetchquestion) :
//===========================
Error reading from database

More information about this error
Debug info: ERROR: column "t.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 9: ORDER BY t.id ASC
^
SELECT SUBSTR(t.name, 6) AS difflevel, count(*) AS numofquest
FROM mdl_tag t
JOIN mdl_tag_instance ti ON t.id = ti.tagid
JOIN mdl_question q ON q.id = ti.itemid
WHERE ti.itemtype = $1
AND ti.tagid IN ($2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25)
AND q.category IN ($26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45)
GROUP BY t.name
ORDER BY t.id ASC
[array (
0 => 'question',
1 => '407',
2 => '408',
3 => '409',
4 => '410',
5 => '411',
6 => '412',
7 => '413',
8 => '414',
9 => '415',
10 => '416',
11 => '417',
12 => '418',
13 => '419',
14 => '420',
15 => '421',
16 => '422',
17 => '423',
18 => '424',
19 => '425',
20 => '426',
21 => '427',
22 => '428',
23 => '429',
24 => '430',
25 => '2431',
26 => '2432',
27 => '2433',
28 => '2434',
29 => '2435',
30 => '2436',
31 => '2437',
32 => '2438',
33 => '2439',
34 => '2440',
35 => '2441',
36 => '2442',
37 => '2443',
38 => '2444',
39 => '2445',
40 => '2446',
41 => '2447',
42 => '2448',
43 => '2449',
44 => '2450',
)]
Error code: dmlreadexception
Stack trace:

line 443 of /lib/dml/moodle_database.php: dml_read_exception thrown
line 239 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end()
line 744 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
line 1352 of /lib/dml/moodle_database.php: call to pgsql_native_moodle_database->get_records_sql()
line 437 of /mod/adaptivequiz/fetchquestion.class.php: call to moodle_database->get_records_sql_menu()
line 259 of /mod/adaptivequiz/fetchquestion.class.php: call to fetchquestion->retrieve_tags_with_question_count()
line 288 of /mod/adaptivequiz/fetchquestion.class.php: call to fetchquestion->initalize_tags_with_quest_count()
line 373 of /mod/adaptivequiz/adaptiveattempt.class.php: call to fetchquestion->fetch_questions()
line 352 of /mod/adaptivequiz/adaptiveattempt.class.php: call to adaptiveattempt->get_question_ready()
line 211 of /mod/adaptivequiz/attempt.php: call to adaptiveattempt->start_attempt()

//===========================

I added t.id and it works but I'm not sure how that affects everything else
"GROUP BY t.id,t.name"

Thoughts?
Thx.

Looks at http://www.thetravelingprogrammer.com/postgres-support-moodle-elis-2-6/ for error explanation.

Would it be possible that some tags with the same name may be different records ?

Thank you for submitting this issue. This repository is now archived: The sponsor of this plugin, Middlebury College, is no longer using Moodle. Development is continuing on other forks of the project. See https://moodle.org/plugins/mod_adaptivequiz for more information and latest releases.