Search code examples
sqlcratedb

How to "GROUP BY" array column in Cratedb


For example I have the following script:

CREATE TABLE test 
(
     items  array(string)
)

INSERT INTO test (items) VALUES (array['a', 'b']);
INSERT INTO test (items) VALUES (array['a'])

Is it possible to count number of items in the table? Something similar to ES terms aggregation.

I expected something like this:

SELECT COUNT(\*), items 
FROM test 
GROUP BY items;

But this raises an error

Cannot GROUP BY 'items': invalid data type 'string_array'


Solution

  • As of CrateDB 1.0 this is not supported. See this GH issue and this