TestDQLComplexQueries tests complex real-world queries
(t *testing.T)
| 431 | |
| 432 | // TestDQLComplexQueries tests complex real-world queries |
| 433 | func TestDQLComplexQueries(t *testing.T) { |
| 434 | opts := DefaultCompareOptions() |
| 435 | opts.IgnoreRowOrder = true |
| 436 | |
| 437 | tests := []QueryTest{ |
| 438 | { |
| 439 | Name: "analytics_query", |
| 440 | Query: ` |
| 441 | WITH monthly_sales AS ( |
| 442 | SELECT |
| 443 | EXTRACT(month FROM sale_date) AS month, |
| 444 | region, |
| 445 | SUM(amount) AS total_sales |
| 446 | FROM sales |
| 447 | GROUP BY EXTRACT(month FROM sale_date), region |
| 448 | ) |
| 449 | SELECT |
| 450 | month, |
| 451 | region, |
| 452 | total_sales, |
| 453 | SUM(total_sales) OVER (PARTITION BY region ORDER BY month) AS cumulative_sales, |
| 454 | RANK() OVER (PARTITION BY month ORDER BY total_sales DESC) AS rank_in_month |
| 455 | FROM monthly_sales |
| 456 | ORDER BY month, region |
| 457 | `, |
| 458 | }, |
| 459 | { |
| 460 | Name: "multi_join_aggregation", |
| 461 | Query: ` |
| 462 | SELECT |
| 463 | u.name AS customer, |
| 464 | COUNT(DISTINCT o.id) AS order_count, |
| 465 | SUM(o.total_amount) AS total_spent, |
| 466 | AVG(o.total_amount) AS avg_order_value, |
| 467 | STRING_AGG(DISTINCT o.status, ', ' ORDER BY o.status) AS statuses |
| 468 | FROM users u |
| 469 | LEFT JOIN orders o ON u.id = o.user_id |
| 470 | GROUP BY u.id, u.name |
| 471 | HAVING COUNT(o.id) > 0 |
| 472 | ORDER BY total_spent DESC |
| 473 | `, |
| 474 | Options: opts, |
| 475 | }, |
| 476 | { |
| 477 | Name: "hierarchical_query", |
| 478 | Query: ` |
| 479 | WITH RECURSIVE category_path AS ( |
| 480 | SELECT id, name, parent_id, name::TEXT AS path, 1 AS depth |
| 481 | FROM categories WHERE parent_id IS NULL |
| 482 | UNION ALL |
| 483 | SELECT c.id, c.name, c.parent_id, cp.path || ' > ' || c.name, cp.depth + 1 |
| 484 | FROM categories c |
| 485 | JOIN category_path cp ON c.parent_id = cp.id |
| 486 | ) |
| 487 | SELECT * FROM category_path ORDER BY path |
| 488 | `, |
| 489 | }, |
| 490 | { |
nothing calls this directly
no test coverage detected