Skip to content

Commit ef50c46

Browse files
committed
Fix table alias parsing regression
1 parent 1cf913e commit ef50c46

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/sqlparser_common.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,44 @@ fn parse_update_with_table_alias() {
333333
}
334334
}
335335

336+
#[test]
337+
fn parse_select_with_table_alias_as() {
338+
// AS is optional
339+
one_statement_parses_to(
340+
"SELECT a, b, c FROM lineitem l (A, B, C)",
341+
"SELECT a, b, c FROM lineitem AS l (A, B, C)",
342+
);
343+
}
344+
345+
#[test]
346+
fn parse_select_with_table_alias() {
347+
let select = verified_only_select("SELECT a, b, c FROM lineitem AS l (A, B, C)");
348+
println!("Query was:\n{select:#?}");
349+
assert_eq!(
350+
select.projection,
351+
vec![
352+
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("a")),),
353+
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("b")),),
354+
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("c")),),
355+
]
356+
);
357+
assert_eq!(
358+
select.from,
359+
vec![TableWithJoins {
360+
relation: TableFactor::Table {
361+
name: ObjectName(vec![Ident::new("lineitem")]),
362+
alias: Some(TableAlias {
363+
name: Ident::new("l"),
364+
columns: vec![Ident::new("A"), Ident::new("B"), Ident::new("C"),],
365+
}),
366+
args: None,
367+
with_hints: vec![],
368+
},
369+
joins: vec![],
370+
},]
371+
);
372+
}
373+
336374
#[test]
337375
fn parse_invalid_table_name() {
338376
let ast = all_dialects()

0 commit comments

Comments
 (0)