Repository: tobymao/sqlglot

Issue:
Casting to array of struct with duckdb fails to parse
```
In [17]: import sqlglot as sg

In [18]: sg.__version__
Out[18]: '11.4.5'

In [19]: sg.parse_one("select cast([struct_pack(a := 1)] as struct(a bigint)[])", read="duckdb")
...
ParseError: Expected TYPE after CAST. Line 1, Col: 38.
  select cast([struct_pack(a := 1)] as struct(a bigint)[])
```

Discussion:

Patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 20c63dca..6df4145e 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -2636,7 +2636,7 @@ class Parser(metaclass=_Parser):
             self._match_r_paren()
             maybe_func = True
 
-        if not nested and self._match_pair(TokenType.L_BRACKET, TokenType.R_BRACKET):
+        if self._match_pair(TokenType.L_BRACKET, TokenType.R_BRACKET):
             this = exp.DataType(
                 this=exp.DataType.Type.ARRAY,
                 expressions=[exp.DataType.build(type_token.value, expressions=expressions)],


Test patch:
diff --git a/tests/dialects/test_duckdb.py b/tests/dialects/test_duckdb.py
index 3da52df1..245d82a9 100644
--- a/tests/dialects/test_duckdb.py
+++ b/tests/dialects/test_duckdb.py
@@ -432,6 +432,18 @@ class TestDuckDB(Validator):
                 "snowflake": "CAST(COL AS ARRAY)",
             },
         )
+        self.validate_all(
+            "CAST([STRUCT_PACK(a := 1)] AS STRUCT(a BIGINT)[])",
+            write={
+                "duckdb": "CAST(LIST_VALUE({'a': 1}) AS STRUCT(a BIGINT)[])",
+            },
+        )
+        self.validate_all(
+            "CAST([[STRUCT_PACK(a := 1)]] AS STRUCT(a BIGINT)[][])",
+            write={
+                "duckdb": "CAST(LIST_VALUE(LIST_VALUE({'a': 1})) AS STRUCT(a BIGINT)[][])",
+            },
+        )
 
     def test_bool_or(self):
         self.validate_all(