Repository: DerekStride/tree-sitter-sql (language: python)

Issue:
Postgres Array function is not parsed correctly
```sql
select array(select 'x')
```

Is a valid SQL statement in Postgres. The odd thing is, that it does not seems to be documented.

Since we have the `array` node for statements like this
```sql
select array['x']
```

This actually gives the same result.


Discussion / hints:

Fix patch:
diff --git a/grammar.js b/grammar.js
index 9edac624..d4ed828b 100644
--- a/grammar.js
+++ b/grammar.js
@@ -485,9 +485,18 @@ module.exports = grammar({
 
     array: $ => seq(
       $.keyword_array,
-      "[",
-      comma_list($._expression),
-      "]"
+      choice(
+        seq(
+          "[",
+          comma_list($._expression),
+          "]"
+        ),
+        seq(
+          "(",
+          $._dml_read,
+          ")",
+        )
+      )
     ),
 
     comment: _ => seq('--', /.*/),


Test patch:
diff --git a/test/corpus/select.txt b/test/corpus/select.txt
index 3b72b03f..688e9c4a 100644
--- a/test/corpus/select.txt
+++ b/test/corpus/select.txt
@@ -2513,6 +2513,34 @@ SELECT array[1, 2, 3 + 4, '5'::int, int_please()];
               (object_reference
                 name: (identifier)))))))))
 
+================================================================================
+Select Array with nested dml_read
+================================================================================
+
+SELECT ARRAY(SELECT col FROM tab)
+
+--------------------------------------------------------------------------------
+
+(program
+  (statement
+    (select
+      (keyword_select)
+      (select_expression
+        (term
+          (array
+            (keyword_array)
+            (select
+              (keyword_select)
+              (select_expression
+                (term
+                  (field
+                    (identifier)))))
+            (from
+              (keyword_from)
+              (relation
+                (object_reference
+                  (identifier))))))))))
+
 ================================================================================
 Select with positive and negative integers
 ================================================================================