array_distinct

SinceVersion 1.2.0

array_distinct

description

Syntax

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

Return the array which has been removed duplicate values. Return NULL for NULL input.

notice

Only supported in vectorized engine

example

1. mysql> set enable_vectorized_engine=true;

3. mysql> select k1, k2, array_distinct(k2) from array_test;
4. +------+-----------------------------+---------------------------+
5. | k1   | k2                          | array_distinct(k2)        |
6. +------+-----------------------------+---------------------------+
7. | 1    | [1, 2, 3, 4, 5]             | [1, 2, 3, 4, 5]           |
8. | 2    | [6, 7, 8]                   | [6, 7, 8]                 |
9. | 3    | []                          | []                        |
10. | 4    | NULL                        | NULL                      |
11. | 5    | [1, 2, 3, 4, 5, 4, 3, 2, 1] | [1, 2, 3, 4, 5]           |
12. | 6    | [1, 2, 3, NULL]             | [1, 2, 3, NULL]           |
13. | 7    | [1, 2, 3, NULL, NULL]       | [1, 2, 3, NULL]     |
14. +------+-----------------------------+---------------------------+

16. mysql> select k1, k2, array_distinct(k2) from array_test01;
17. +------+------------------------------------------+---------------------------+
18. | k1   | k2                                       | array_distinct(`k2`)      |
19. +------+------------------------------------------+---------------------------+
20. | 1    | ['a', 'b', 'c', 'd', 'e']                | ['a', 'b', 'c', 'd', 'e'] |
21. | 2    | ['f', 'g', 'h']                          | ['f', 'g', 'h']           |
22. | 3    | ['']                                     | ['']                      |
23. | 3    | [NULL]                                   | [NULL]                    |
24. | 5    | ['a', 'b', 'c', 'd', 'e', 'a', 'b', 'c'] | ['a', 'b', 'c', 'd', 'e'] |
25. | 6    | NULL                                     | NULL                      |
26. | 7    | ['a', 'b', NULL]                         | ['a', 'b', NULL]          |
27. | 8    | ['a', 'b', NULL, NULL]                   | ['a', 'b', NULL]    |
28. +------+------------------------------------------+---------------------------+

keywords

ARRAY, DISTINCT, ARRAY_DISTINCT