Feature request: Support "unnesting" Array columns in the select clause
See original GitHub issueUse case: Aggregate queries on Array columns
Feature description: We need to be able to run aggregations on array columns. For example, if we have a table which looks like this…
+----+---------------+
| id | tags |
+----+---------------+
| 1 | ["abc", "def"]|
| 2 | ["abc", "xyz"]|
+----+---------------+
…we need to be able to find counts for the unique values found in the tags column. For example (using UNNEST
as a placeholder for this functionality):
select count(id) as tag_count, UNNEST(tags) as tag
from my_table group by tag order by tag_count desc;
Which would produce:
+----+---------------+
| tag_count | tag |
+----+---------------+
| 2 | "abc" |
| 1 | "def" |
| 1 | "xyz" |
+----+---------------+
Other products typically provide an UNNEST function which turns an array column into a set of rows so that aggregates over the array column will work. For example:
https://www.postgresql.org/docs/9.2/static/functions-array.html https://www.mapd.com/docs/latest/mapd-core-guide/dml/#array-support https://docs.snowflake.net/manuals/user-guide/querying-semistructured.html#using-the-flatten-function-to-parse-arrays
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:10 (5 by maintainers)
Top GitHub Comments
Currently it doesn’t, but you’re right that we could make it work. We’ll have a look at enabling that as well.
We’ve just merged support for table functions in the select list (https://github.com/crate/crate/pull/7716). This will be available in
3.2
and can be used for your use case: