File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -1945,7 +1945,7 @@ impl fmt::Display for TableFactor {
19451945 TableFactor :: PassThroughQuery { query, alias } => {
19461946 write ! ( f, "({query})" ) ?;
19471947 if let Some ( alias) = alias {
1948- write ! ( f, " AS {alias}" ) ?;
1948+ write ! ( f, " {alias}" ) ?;
19491949 }
19501950 Ok ( ( ) )
19511951 }
Original file line number Diff line number Diff line change @@ -15219,6 +15219,30 @@ fn ast_with_pass_through_query() {
1521915219 }),
1522015220 };
1522115221
15222+ // After modifying the AST, the SQL representation should be different
15223+ assert_eq!(ast.to_string(), "SELECT * FROM (SELECT * FROM tx) ty");
15224+ }
15225+
15226+ #[test]
15227+ fn ast_with_pass_through_query_with_explicit_alias() {
15228+ let sql = "SELECT * FROM t1 AS t2";
15229+ let mut ast = all_dialects().verified_stmt(sql);
15230+ let Statement::Query(ref mut query) = ast else {
15231+ panic!("Expected Query");
15232+ };
15233+ let SetExpr::Select(ref mut select) = *query.body else {
15234+ panic!("Expected SetExpr::Select");
15235+ };
15236+ let from = select.from.get_mut(0).unwrap();
15237+ from.relation = TableFactor::PassThroughQuery {
15238+ query: "SELECT * FROM tx".to_string(),
15239+ alias: Some(TableAlias {
15240+ explicit: true,
15241+ name: Ident::new("ty"),
15242+ columns: vec![],
15243+ }),
15244+ };
15245+
1522215246 // After modifying the AST, the SQL representation should be different
1522315247 assert_eq!(ast.to_string(), "SELECT * FROM (SELECT * FROM tx) AS ty");
1522415248}
You can’t perform that action at this time.
0 commit comments