array_distinct

SinceVersion 1.2.0

array_distinct

description

Syntax

  1. ARRAY<T> array_distinct(ARRAY<T> arr)

返回去除了重复元素的数组,如果输入数组为NULL,则返回NULL。

notice

仅支持向量化引擎中使用

example

  1. mysql> set enable_vectorized_engine=true;
  2. mysql> select k1, k2, array_distinct(k2) from array_test;
  3. +------+-----------------------------+---------------------------+
  4. | k1 | k2 | array_distinct(k2) |
  5. +------+-----------------------------+---------------------------+
  6. | 1 | [1, 2, 3, 4, 5] | [1, 2, 3, 4, 5] |
  7. | 2 | [6, 7, 8] | [6, 7, 8] |
  8. | 3 | [] | [] |
  9. | 4 | NULL | NULL |
  10. | 5 | [1, 2, 3, 4, 5, 4, 3, 2, 1] | [1, 2, 3, 4, 5] |
  11. | 6 | [1, 2, 3, NULL] | [1, 2, 3, NULL] |
  12. | 7 | [1, 2, 3, NULL, NULL] | [1, 2, 3, NULL] |
  13. +------+-----------------------------+---------------------------+
  14. mysql> select k1, k2, array_distinct(k2) from array_test01;
  15. +------+------------------------------------------+---------------------------+
  16. | k1 | k2 | array_distinct(`k2`) |
  17. +------+------------------------------------------+---------------------------+
  18. | 1 | ['a', 'b', 'c', 'd', 'e'] | ['a', 'b', 'c', 'd', 'e'] |
  19. | 2 | ['f', 'g', 'h'] | ['f', 'g', 'h'] |
  20. | 3 | [''] | [''] |
  21. | 3 | [NULL] | [NULL] |
  22. | 5 | ['a', 'b', 'c', 'd', 'e', 'a', 'b', 'c'] | ['a', 'b', 'c', 'd', 'e'] |
  23. | 6 | NULL | NULL |
  24. | 7 | ['a', 'b', NULL] | ['a', 'b', NULL] |
  25. | 8 | ['a', 'b', NULL, NULL] | ['a', 'b', NULL] |
  26. +------+------------------------------------------+---------------------------+

keywords

ARRAY, DISTINCT, ARRAY_DISTINCT