MCPcopy Create free account
hub / github.com/erans/pgsqlite / test_derived_table_subquery

Function test_derived_table_subquery

tests/subquery_cte_test.rs:141–168  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

139
140#[test]
141fn test_derived_table_subquery() {
142 let conn = setup_test_db();
143
144 // First test just the inner query
145 let inner_sql = "SELECT c.name as customer_name, AVG(o.total) as avg_order
146 FROM customers c
147 JOIN orders o ON c.id = o.customer_id
148 GROUP BY c.id, c.name";
149 let inner_result = rewrite_query(&conn, inner_sql).unwrap();
150 println!("Inner query rewritten to: {inner_result}");
151 assert!(inner_result.contains("decimal_from_text"), "Inner query should wrap AVG argument");
152
153 let sql = "SELECT customer_name, avg_order
154 FROM (
155 SELECT c.name as customer_name, AVG(o.total) as avg_order
156 FROM customers c
157 JOIN orders o ON c.id = o.customer_id
158 GROUP BY c.id, c.name
159 ) t
160 WHERE avg_order > 100";
161 let result = rewrite_query(&conn, sql).unwrap();
162
163 println!("Derived table query rewritten to: {result}");
164 assert!(result.contains("AVG"));
165 assert!(result.contains("decimal_from_text"));
166 // The WHERE clause on avg_order should use decimal comparison
167 assert!(result.contains("decimal_gt"), "WHERE clause should use decimal_gt for avg_order > 100");
168}
169
170#[test]
171fn test_cte_basic() {

Callers

nothing calls this directly

Calls 2

setup_test_dbFunction · 0.70
rewrite_queryFunction · 0.70

Tested by

no test coverage detected