mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-10 05:52:13 +00:00
Support array indexing for duckdb (#1265)
This commit is contained in:
parent
eb36bd7138
commit
e3692f4681
2 changed files with 27 additions and 1 deletions
|
@ -2547,7 +2547,7 @@ impl<'a> Parser<'a> {
|
|||
expr: Box::new(expr),
|
||||
})
|
||||
} else if Token::LBracket == tok {
|
||||
if dialect_of!(self is PostgreSqlDialect | GenericDialect) {
|
||||
if dialect_of!(self is PostgreSqlDialect | DuckDbDialect | GenericDialect) {
|
||||
// parse index
|
||||
self.parse_array_index(expr)
|
||||
} else if dialect_of!(self is SnowflakeDialect) {
|
||||
|
|
|
@ -516,3 +516,29 @@ fn test_duckdb_named_argument_function_with_assignment_operator() {
|
|||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_index() {
|
||||
let sql = r#"SELECT ['a', 'b', 'c'][3] AS three"#;
|
||||
let select = duckdb().verified_only_select(sql);
|
||||
let projection = &select.projection;
|
||||
assert_eq!(1, projection.len());
|
||||
let expr = match &projection[0] {
|
||||
SelectItem::ExprWithAlias { expr, .. } => expr,
|
||||
_ => panic!("Expected an expression with alias"),
|
||||
};
|
||||
assert_eq!(
|
||||
&Expr::ArrayIndex {
|
||||
obj: Box::new(Expr::Array(Array {
|
||||
elem: vec![
|
||||
Expr::Value(Value::SingleQuotedString("a".to_owned())),
|
||||
Expr::Value(Value::SingleQuotedString("b".to_owned())),
|
||||
Expr::Value(Value::SingleQuotedString("c".to_owned()))
|
||||
],
|
||||
named: false
|
||||
})),
|
||||
indexes: vec![Expr::Value(number("3"))]
|
||||
},
|
||||
expr
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue