diff --git a/sqlglot/parser.py b/sqlglot/parser.py index 97f709e419..812bd617a4 100644 --- a/sqlglot/parser.py +++ b/sqlglot/parser.py @@ -2346,12 +2346,21 @@ def _parse_types(self, check_func: bool = False) -> t.Optional[exp.Expression]: maybe_func = True if not nested and self._match_pair(TokenType.L_BRACKET, TokenType.R_BRACKET): - return exp.DataType( + this = exp.DataType( this=exp.DataType.Type.ARRAY, expressions=[exp.DataType.build(type_token.value, expressions=expressions)], nested=True, ) + while self._match_pair(TokenType.L_BRACKET, TokenType.R_BRACKET): + this = exp.DataType( + this=exp.DataType.Type.ARRAY, + expressions=[this], + nested=True, + ) + + return this + if self._match(TokenType.L_BRACKET): self._retreat(index) return None diff --git a/tests/dialects/test_duckdb.py b/tests/dialects/test_duckdb.py index f6446ca347..3024cbd084 100644 --- a/tests/dialects/test_duckdb.py +++ b/tests/dialects/test_duckdb.py @@ -334,6 +334,14 @@ def test_cast(self): }, ) + self.validate_all( + "cast([[1]] as int[][])", + write={ + "duckdb": "CAST(LIST_VALUE(LIST_VALUE(1)) AS INT[][])", + "spark": "CAST(ARRAY(ARRAY(1)) AS ARRAY>)", + }, + ) + def test_bool_or(self): self.validate_all( "SELECT a, LOGICAL_OR(b) FROM table GROUP BY a",