array_difference

SinceVersion 1.2.0

array_difference

description

Syntax

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

Calculates the difference between adjacent array elements. Returns an array where the first element will be 0, the second is the difference between a[1] - a[0]. need notice that NULL will be return NULL

notice

Only supported in vectorized engine

example

1. mysql> set enable_vectorized_engine=true;

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

keywords

ARRAY, DIFFERENCE, ARRAY_DIFFERENCE