> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# array_difference

> Calculates the difference between every two neighboring elements of an array by subtracting each element from its following element and returns an array...

Calculates the difference between every two neighboring elements of an array by subtracting each element from its following element and returns an array that consists of the differences.

## Syntax

```SQL theme={null}
array_difference(input)
```

## Parameters

`input`: the array for which you want to calculate the differences between every two neighboring elements.

## Return value

Returns an array with the same length as `input`. The return element type is determined by the input element type as follows:

| Input element type | Return element type |
| - | - |
| `BOOLEAN`, `TINYINT`, `SMALLINT`, `INT`, or `BIGINT` | `BIGINT` |
| `LARGEINT` | `LARGEINT` |
| `FLOAT` or `DOUBLE` | `DOUBLE` |
| `DECIMAL(P, S)`, where `P <= 38` | `DECIMAL(min(P + 1, 38), S)` |

`ARRAY<DECIMAL256>` (`P > 38`) is not supported.

## Examples

Example 1:

```Plain theme={null}
mysql> SELECT array_difference([342, 32423, 213, 23432]);
+-----------------------------------------+
| array_difference([342,32423,213,23432]) |
+-----------------------------------------+
| [0,32081,-32210,23219]                  |
+-----------------------------------------+
```

Example 2:

```Plain theme={null}
mysql> SELECT array_difference([342, 32423, 213, null, 23432]);
+----------------------------------------------+
| array_difference([342,32423,213,NULL,23432]) |
+----------------------------------------------+
| [0,32081,-32210,null,null]                   |
+----------------------------------------------+
```

Example 3:

```Plain theme={null}
mysql> SELECT array_difference([1.2, 2.3, 3.2, 4324242.55]);
+--------------------------------------------+
| array_difference([1.2,2.3,3.2,4324242.55]) |
+--------------------------------------------+
| [0,1.1,0.9,4324239.35]                     |
+--------------------------------------------+
```

Example 4:

```Plain theme={null}
mysql> SELECT array_difference([false, true, false]);
+----------------------------------------+
| array_difference([FALSE, TRUE, FALSE]) |
+----------------------------------------+
| [0,1,-1]                               |
+----------------------------------------+
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.