Skip to content

Commit 3f06f59

Browse files
psteinroeclaude
andcommitted
fix: add ORDER BY to combined SQL for deterministic result ordering
Individual SQL queries' ORDER BY clauses are not preserved when combined with UNION ALL. Wrap the entire result in SELECT and ORDER BY cache_key! to ensure consistent, deterministic ordering for tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7dd9257 commit 3f06f59

File tree

1 file changed

+5
-1
lines changed
  • crates/pgls_splinter/src

1 file changed

+5
-1
lines changed

crates/pgls_splinter/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ pub async fn run_splinter(
109109
}
110110
})
111111
.collect();
112-
let combined_sql = processed_queries.join("\n\nUNION ALL\n\n");
112+
// Add ORDER BY to ensure deterministic ordering across all results
113+
let combined_sql = format!(
114+
"SELECT * FROM (\n{}\n) AS all_results ORDER BY \"cache_key!\"",
115+
processed_queries.join("\n\nUNION ALL\n\n")
116+
);
113117

114118
// Execute the combined query
115119
let mut tx = params.conn.begin().await?;

0 commit comments

Comments
 (0)