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

# array_difference

> 计算数组中相邻两个元素的差值构成的数组。

对于数值型数组，返回相邻两个元素的差(从后者中减去前者)构成的数组。

## 语法

```Haskell theme={null}
output array_difference(input)
```

## 参数说明

* input：数值型数组。

## 返回值说明

返回一个与输入数组长度相同的数组。返回元素类型根据输入元素类型确定，具体映射如下：

| 输入元素类型 | 返回元素类型 |
| - | - |
| `BOOLEAN`、`TINYINT`、`SMALLINT`、`INT` 或 `BIGINT` | `BIGINT` |
| `LARGEINT` | `LARGEINT` |
| `FLOAT` 或 `DOUBLE` | `DOUBLE` |
| `DECIMAL(P, S)`，其中 `P <= 38` | `DECIMAL(min(P + 1, 38), S)` |

目前不支持 `ARRAY<DECIMAL256>`（`P > 38`）。

## 示例

**示例一**:

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

**示例二**:

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

**示例三**:

```plain text 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]                     |
+--------------------------------------------+
```

**示例四**:

```plain text 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.