Extract the first SELECT item expression from a simple `SELECT FROM `.
(sql: &str)
| 10 | |
| 11 | /// Extract the first SELECT item expression from a simple `SELECT <expr> FROM <tbl>`. |
| 12 | fn first_select_expr(sql: &str) -> Expr { |
| 13 | let stmts = parse_sql(sql).expect("parse failed"); |
| 14 | let Statement::Query(q) = &stmts[0] else { |
| 15 | panic!("expected query"); |
| 16 | }; |
| 17 | let sqlparser::ast::SetExpr::Select(sel) = q.body.as_ref() else { |
| 18 | panic!("expected select body"); |
| 19 | }; |
| 20 | match &sel.projection[0] { |
| 21 | SelectItem::UnnamedExpr(e) => e.clone(), |
| 22 | SelectItem::ExprWithAlias { expr, .. } => expr.clone(), |
| 23 | other => panic!("unexpected projection item: {other:?}"), |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | #[test] |
| 28 | fn compound_identifier_two_parts_is_column() { |
no test coverage detected