diff --git a/src/sqlparser/src/parser_v2/data_type.rs b/src/sqlparser/src/parser_v2/data_type.rs index 2544e54d1d542..73793de7e0b7e 100644 --- a/src/sqlparser/src/parser_v2/data_type.rs +++ b/src/sqlparser/src/parser_v2/data_type.rs @@ -152,8 +152,13 @@ fn data_type_stateful(input: &mut StatefulStream) -> PResult where S: TokenStream, { + let base = data_type_stateful_inner.parse_next(input)?; + // Shall not peek for `Token::LBracket` when `>>` is partially consumed. + if *input.state.remaining_close.borrow() { + return Ok(base); + } ( - data_type_stateful_inner, + empty.value(base), repeat(0.., (Token::LBracket, cut_err(Token::RBracket))), ) .map(|(mut dt, depth)| { diff --git a/src/sqlparser/tests/testdata/array.yaml b/src/sqlparser/tests/testdata/array.yaml index 20ed73ab9d910..2e676f7de141f 100644 --- a/src/sqlparser/tests/testdata/array.yaml +++ b/src/sqlparser/tests/testdata/array.yaml @@ -74,3 +74,6 @@ sql parser error: expected an expression, found: [ LINE 1: SELECT [1,2] ^ +- input: CREATE TABLE t (params STRUCT>[]) + formatted_sql: CREATE TABLE t (params STRUCT>[]) + formatted_ast: 'CreateTable { or_replace: false, temporary: false, if_not_exists: false, name: ObjectName([Ident { value: "t", quote_style: None }]), columns: [ColumnDef { name: Ident { value: "params", quote_style: None }, data_type: Some(Array(Struct([StructField { name: Ident { value: "a", quote_style: None }, data_type: Struct([StructField { name: Ident { value: "b", quote_style: None }, data_type: Int }]) }]))), collation: None, options: [] }], wildcard_idx: None, constraints: [], with_options: [], source_schema: None, source_watermarks: [], append_only: false, on_conflict: None, with_version_column: None, query: None, cdc_table_info: None, include_column_options: [] }'