Update insert-new-latest-status-entries

To use the status first for ordering, then the timestamp. This ensures
sensible behaviour regardless of what timestamps are present.
This commit is contained in:
Christopher Baines 2020-10-21 20:25:59 +01:00
parent 2e859ed981
commit 5124f3be3e

View file

@ -120,11 +120,11 @@ WHERE build_id IN ("
WINDOW rows_for_build AS ( WINDOW rows_for_build AS (
PARTITION BY build_id PARTITION BY build_id
ORDER BY ORDER BY
timestamp DESC,
CASE WHEN status = 'scheduled' THEN -2 CASE WHEN status = 'scheduled' THEN -2
WHEN status = 'started' THEN -1 WHEN status = 'started' THEN -1
ELSE 0 ELSE 0
END DESC END DESC,
timestamp DESC
RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
)")) )"))