array_compact
SinceVersion 1.2.0
array_compact
description
Removes consecutive duplicate elements from an array. The order of result values is determined by the order in the source array.
Syntax
1. array_compact(arr)
Arguments
arr — The array to inspect.
Returned value
The array without continuous duplicate.
Type: Array.
notice
Only supported in vectorized engine
example
1. select array_compact([1, 2, 3, 3, null, null, 4, 4]);
3. +----------------------------------------------------+
4. | array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) |
5. +----------------------------------------------------+
6. | [1, 2, 3, NULL, 4] |
7. +----------------------------------------------------+
9. select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']);
11. +-------------------------------------------------------------------------------+
12. | array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) |
13. +-------------------------------------------------------------------------------+
14. | ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] |
15. +-------------------------------------------------------------------------------+
17. select array_compact(['2015-03-13','2015-03-13']);
19. +--------------------------------------------------+
20. | array_compact(ARRAY('2015-03-13', '2015-03-13')) |
21. +--------------------------------------------------+
22. | ['2015-03-13'] |
23. +--------------------------------------------------+
keywords
ARRAY,COMPACT,ARRAY_COMPACT
