Skip to content

Commit

Permalink
Ensure stable ordering of assessments (#9866)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwalters512 committed May 17, 2024
1 parent c98380c commit 87ca7c4
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions apps/prairielearn/src/sprocs/sync_assessments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,26 @@ BEGIN
FROM (
SELECT
tid,
row_number() OVER (ORDER BY (
SELECT string_agg(convert_to(coalesce(r[2],
length(length(r[1])::text) || length(r[1])::text || r[1]),
'SQL_ASCII'),'\x00')
FROM regexp_matches(number, '0*([0-9]+)|([^0-9]+)', 'g') r
) ASC) AS order_by
row_number() OVER (
ORDER BY (
SELECT
string_agg(
convert_to(
coalesce(
r[2],
length(length(r[1])::text) || length(r[1])::text || r[1]
),
'SQL_ASCII'
),
'\x00'
)
FROM
regexp_matches(number, '0*([0-9]+)|([^0-9]+)', 'g') r
) ASC,
-- In case two assessments have the same number, fall back to
-- ordering by the ID to ensure a stable sort.
id ASC
) AS order_by
FROM assessments
WHERE
course_instance_id = syncing_course_instance_id
Expand Down

0 comments on commit 87ca7c4

Please sign in to comment.