⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ impl fmt::Display for TableFactor {
TableFactor::PassThroughQuery { query, alias } => {
write!(f, "({query})")?;
if let Some(alias) = alias {
write!(f, " AS {alias}")?;
write!(f, " {alias}")?;
}
Ok(())
}
Expand Down
24 changes: 24 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15219,6 +15219,30 @@ fn ast_with_pass_through_query() {
}),
};

// After modifying the AST, the SQL representation should be different
assert_eq!(ast.to_string(), "SELECT * FROM (SELECT * FROM tx) ty");
}

#[test]
fn ast_with_pass_through_query_with_explicit_alias() {
let sql = "SELECT * FROM t1 AS t2";
let mut ast = all_dialects().verified_stmt(sql);
let Statement::Query(ref mut query) = ast else {
panic!("Expected Query");
};
let SetExpr::Select(ref mut select) = *query.body else {
panic!("Expected SetExpr::Select");
};
let from = select.from.get_mut(0).unwrap();
from.relation = TableFactor::PassThroughQuery {
query: "SELECT * FROM tx".to_string(),
alias: Some(TableAlias {
explicit: true,
name: Ident::new("ty"),
columns: vec![],
}),
};

// After modifying the AST, the SQL representation should be different
assert_eq!(ast.to_string(), "SELECT * FROM (SELECT * FROM tx) AS ty");
}
Expand Down
Loading