File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -2547,7 +2547,7 @@ impl<'a> Parser<'a> {
25472547 expr : Box :: new ( expr) ,
25482548 } )
25492549 } else if Token :: LBracket == tok {
2550- if dialect_of ! ( self is PostgreSqlDialect | GenericDialect ) {
2550+ if dialect_of ! ( self is PostgreSqlDialect | DuckDbDialect | GenericDialect ) {
25512551 // parse index
25522552 self . parse_array_index ( expr)
25532553 } else if dialect_of ! ( self is SnowflakeDialect ) {
Original file line number Diff line number Diff line change @@ -516,3 +516,29 @@ fn test_duckdb_named_argument_function_with_assignment_operator() {
516516 expr_from_projection( only( & select. projection) )
517517 ) ;
518518}
519+
520+ #[ test]
521+ fn test_array_index ( ) {
522+ let sql = r#"SELECT ['a', 'b', 'c'][3] AS three"# ;
523+ let select = duckdb ( ) . verified_only_select ( sql) ;
524+ let projection = & select. projection ;
525+ assert_eq ! ( 1 , projection. len( ) ) ;
526+ let expr = match & projection[ 0 ] {
527+ SelectItem :: ExprWithAlias { expr, .. } => expr,
528+ _ => panic ! ( "Expected an expression with alias" ) ,
529+ } ;
530+ assert_eq ! (
531+ & Expr :: ArrayIndex {
532+ obj: Box :: new( Expr :: Array ( Array {
533+ elem: vec![
534+ Expr :: Value ( Value :: SingleQuotedString ( "a" . to_owned( ) ) ) ,
535+ Expr :: Value ( Value :: SingleQuotedString ( "b" . to_owned( ) ) ) ,
536+ Expr :: Value ( Value :: SingleQuotedString ( "c" . to_owned( ) ) )
537+ ] ,
538+ named: false
539+ } ) ) ,
540+ indexes: vec![ Expr :: Value ( number( "3" ) ) ]
541+ } ,
542+ expr
543+ ) ;
544+ }
You can’t perform that action at this time.
0 commit comments