Skip to content

Commit 8d0b343

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

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/sqlparser_common.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,43 @@ 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+
assert_eq!(
349+
select.projection,
350+
vec![
351+
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("a")),),
352+
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("b")),),
353+
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("c")),),
354+
]
355+
);
356+
assert_eq!(
357+
select.from,
358+
vec![TableWithJoins {
359+
relation: TableFactor::Table {
360+
name: ObjectName(vec![Ident::new("lineitem")]),
361+
alias: Some(TableAlias {
362+
name: Ident::new("l"),
363+
columns: vec![Ident::new("A"), Ident::new("B"), Ident::new("C"),],
364+
}),
365+
args: None,
366+
with_hints: vec![],
367+
},
368+
joins: vec![],
369+
}]
370+
);
371+
}
372+
336373
#[test]
337374
fn parse_invalid_table_name() {
338375
let ast = all_dialects()

0 commit comments

Comments
 (0)