From 879e4b5046f12828940ef39b6ed26456ed8271ed Mon Sep 17 00:00:00 2001 From: TennyZhuang Date: Wed, 8 May 2024 17:42:37 +0800 Subject: [PATCH] fix again Signed-off-by: TennyZhuang --- src/sqlparser/src/parser.rs | 11 ++++++----- src/sqlparser/tests/testdata/array.yaml | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sqlparser/src/parser.rs b/src/sqlparser/src/parser.rs index 0989cfc69ecaf..9ceebb48c66b8 100644 --- a/src/sqlparser/src/parser.rs +++ b/src/sqlparser/src/parser.rs @@ -1238,6 +1238,12 @@ impl Parser { expected_depth: &mut Option, ) -> Result { Ok(if self.consume_token(&Token::LBracket) { + if self.consume_token(&Token::RBracket) { + return Ok(Expr::Array(Array { + elem: vec![], + named: false, + })); + } let exprs = self.parse_comma_separated(|parser| { parser.parse_array_inner(depth + 1, expected_depth) })?; @@ -1247,11 +1253,6 @@ impl Parser { // Only top-level array is named. named: false, }) - } else if self.peek_token() == Token::RBracket { - Expr::Array(Array { - elem: vec![], - named: false, - }) } else { if let Some(expected_depth) = *expected_depth { match depth.cmp(&expected_depth) { diff --git a/src/sqlparser/tests/testdata/array.yaml b/src/sqlparser/tests/testdata/array.yaml index 99fb57f0e6202..4296f701e60f3 100644 --- a/src/sqlparser/tests/testdata/array.yaml +++ b/src/sqlparser/tests/testdata/array.yaml @@ -29,6 +29,8 @@ formatted_sql: SELECT ARRAY[[1, 2], [3, 4]] - input: SELECT ARRAY[ARRAY[1,2],ARRAY[3,4]] formatted_sql: SELECT ARRAY[ARRAY[1, 2], ARRAY[3, 4]] +- input: SELECT ARRAY[[],[]] + formatted_sql: SELECT ARRAY[[], []] - input: SELECT ARRAY[[1,2],3] error_msg: |- sql parser error: Expected ], found: 3 at line:1, column:21