-
Hello, The following query produces the AST listed below Code fn test_process_sql_statements() {
let query = "SELECT country.country from country;";
let ast = Parser::parse_sql(&sqlparser::dialect::MySqlDialect {}, query).unwrap();
println!("{:?}", ast);
} AST [Query(Query {
with: None,
body: Select(Select {
distinct: None,
top: None,
top_before_distinct: false,
projection: [
UnnamedExpr(CompoundIdentifier([
Ident {
value: "country",
quote_style: None,
},
Ident {
value: "country",
quote_style: None,
},
])),
],
into: None,
from: [
TableWithJoins {
relation: Table {
name: ObjectName([
Ident {
value: "country",
quote_style: None,
},
]),
alias: None,
args: None,
with_hints: [],
version: None,
with_ordinality: false,
partitions: [],
},
joins: [],
},
],
lateral_views: [],
prewhere: None,
selection: None,
group_by: Expressions([], []),
cluster_by: [],
distribute_by: [],
sort_by: [],
having: None,
named_window: [],
qualify: None,
window_before_qualify: false,
value_table_mode: None,
connect_by: None,
}),
order_by: None,
limit: None,
limit_by: [],
offset: None,
fetch: None,
locks: [],
for_clause: None,
settings: None,
format_clause: None,
})] Now imagine we want to identify the table name in a projection, with the Can we assume the first element of vector is always the table name? whats a possible scenario where compound idents can have more than 2 elements? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok as per docs https://docs.rs/sqlparser/0.52.0/sqlparser/ast/enum.Expr.html#variant.CompoundIdentifier if the vec has 2 elements it looks like parser is evaluating it to |
Beta Was this translation helpful? Give feedback.
Ok as per docs https://docs.rs/sqlparser/0.52.0/sqlparser/ast/enum.Expr.html#variant.CompoundIdentifier
if the vec has 2 elements it looks like parser is evaluating it to
table_alias.col
and if its 3 elements itsschema.table.col