To reproduce
create table t (a int, b int, c STRING[]);
insert into t values (1, 1, ARRAY['a', 'b']);
insert into t values (1, 2, ARRAY['c', 'd']);
insert into t values (2, 2, ARRAY['c']);
insert into t values (1, 1, ARRAY['e', 'f']);
It returns an error if try to aggregate the c column with unnest after any other type of aggregation:
> select a, max(b), array_agg(unnest(c)) from t group by a;
ERROR: column "c" must appear in the GROUP BY clause or be used in an aggregate function
SQLSTATE: 42803
but if the select has that array aggregation before any other aggregation, it works
> select a, array_agg(unnest(c)), max(b) from t group by a;
a | array_agg | max
----+---------------+------
1 | {a,b,c,d,e,f} | 2
2 | {c} | 2
If I run the unnest first, it also works
> select a, max(b), array_agg(x) from (select a, b, unnest(c) as x from t) group by a;
a | max | array_agg
----+-----+----------------
1 | 2 | {a,b,c,d,e,f}
2 | 2 | {c}
(2 rows)
Jira issue: CRDB-17765
To reproduce
It returns an error if try to aggregate the c column with unnest after any other type of aggregation:
but if the select has that array aggregation before any other aggregation, it works
If I run the unnest first, it also works
Jira issue: CRDB-17765