Pick the fix
A test asserts rows == [a, b] and fails 1 run in 50. The query has no ORDER BY. Fix?
Hint 1 of 1
What guarantees row order?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Add ORDER BY to the query (or compare as sets if order doesn't matter)
Correct. Order isn't guaranteed without it.
SQL returns rows in no particular order unless ORDER BY says so, and the order can change with plans, vacuums or parallel scans. Make the order explicit, or compare as a set.
Why not the others?
- B Retry the test three times. Hides the bug.
- C Add a sleep before the query. Order isn't about timing.
- D Run tests serially. Order still isn't guaranteed.