()
| 16 | /// must produce exactly 5 rows with values 1..5. |
| 17 | #[tokio::test(flavor = "multi_thread", worker_threads = 4)] |
| 18 | async fn recursive_cte_generates_sequence() { |
| 19 | let server = TestServer::start().await; |
| 20 | |
| 21 | let rows = server |
| 22 | .query_text( |
| 23 | "WITH RECURSIVE c(n) AS (\ |
| 24 | SELECT 1 \ |
| 25 | UNION ALL \ |
| 26 | SELECT n + 1 FROM c WHERE n < 5\ |
| 27 | ) \ |
| 28 | SELECT n FROM c", |
| 29 | ) |
| 30 | .await; |
| 31 | |
| 32 | let values = rows.expect("recursive CTE counter should succeed"); |
| 33 | assert_eq!( |
| 34 | values.len(), |
| 35 | 5, |
| 36 | "recursive CTE should produce 5 rows (1..5): got {values:?}" |
| 37 | ); |
| 38 | let mut nums: Vec<i64> = values |
| 39 | .iter() |
| 40 | .map(|v| v.trim().parse().expect("expected i64 row value")) |
| 41 | .collect(); |
| 42 | nums.sort(); |
| 43 | assert_eq!( |
| 44 | nums, |
| 45 | vec![1, 2, 3, 4, 5], |
| 46 | "rows should be 1..5: got {nums:?}" |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | // ── Test 2: UNION ALL preserves duplicates ──────────────────────────────────── |
| 51 |
nothing calls this directly
no test coverage detected