COLLECT_SET

SinceVersion 1.2.0

COLLECT_SET

description

Syntax

ARRAY<T> collect_set(expr[,max_size])

Creates an array containing distinct elements from expr,with the optional max_size parameter limits the size of the resulting array to max_size elements. It has an alias group_uniq_array.

notice

  1. Only supported in vectorized engine

example

  1. mysql> set enable_vectorized_engine=true;
  2. mysql> select k1,k2,k3 from collect_set_test order by k1;
  3. +------+------------+-------+
  4. | k1 | k2 | k3 |
  5. +------+------------+-------+
  6. | 1 | 2023-01-01 | hello |
  7. | 2 | 2023-01-01 | NULL |
  8. | 2 | 2023-01-02 | hello |
  9. | 3 | NULL | world |
  10. | 3 | 2023-01-02 | hello |
  11. | 4 | 2023-01-02 | doris |
  12. | 4 | 2023-01-03 | sql |
  13. +------+------------+-------+
  14. mysql> select collect_set(k1),collect_set(k1,2) from collect_set_test;
  15. +-------------------------+--------------------------+
  16. | collect_set(`k1`) | collect_set(`k1`,2) |
  17. +-------------------------+--------------------------+
  18. | [4,3,2,1] | [1,2] |
  19. +----------------------------------------------------+
  20. mysql> select k1,collect_set(k2),collect_set(k3,1) from collect_set_test group by k1 order by k1;
  21. +------+-------------------------+--------------------------+
  22. | k1 | collect_set(`k2`) | collect_set(`k3`,1) |
  23. +------+-------------------------+--------------------------+
  24. | 1 | [2023-01-01] | [hello] |
  25. | 2 | [2023-01-01,2023-01-02] | [hello] |
  26. | 3 | [2023-01-02] | [world] |
  27. | 4 | [2023-01-02,2023-01-03] | [sql] |
  28. +------+-------------------------+--------------------------+

keywords

COLLECT_SET,GROUP_UNIQ_ARRAY,COLLECT_LIST,ARRAY