mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Add arrayLastOrNull function
This commit is contained in:
parent
fb07a2f5ed
commit
dd64145bc8
@ -2131,12 +2131,24 @@ arrayFirstOrNull(func, arr1, …)
|
||||
|
||||
**Implementation details**
|
||||
|
||||
Note that the `arrayFirst` is a [higher-order function](../../sql-reference/functions/index.md#higher-order-functions). You must pass a lambda function to it as the first argument, and it can’t be omitted.
|
||||
Note that the `arrayFirstOrNull` is a [higher-order function](../../sql-reference/functions/index.md#higher-order-functions). You must pass a lambda function to it as the first argument, and it can’t be omitted.
|
||||
|
||||
**Example**
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
SELECT arrayFirstOrNull(x -> x >= 2, [1, 2, 3]);
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
```response
|
||||
2
|
||||
```
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
SELECT arrayFirstOrNull(x -> x >= 2, emptyArrayUInt8());
|
||||
```
|
||||
@ -2155,7 +2167,53 @@ Note that the `arrayLast` is a [higher-order function](../../sql-reference/funct
|
||||
|
||||
## arrayLastOrNull
|
||||
|
||||
Returns the last element in the `arr1` array for which `func(arr1[i], …, arrN[i])` returns something other than 0, otherwise returns `NULL`.
|
||||
|
||||
**Syntax**
|
||||
|
||||
```sql
|
||||
arrayLastOrNull(func, arr1, …)
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `func`: lambda function.
|
||||
- `arr1`: array to operate on. [Array](../)
|
||||
|
||||
**Returned value**
|
||||
|
||||
- The last element in the passed array.
|
||||
- Otherwise, returns `NULL`
|
||||
|
||||
**Implementation details**
|
||||
|
||||
Note that the `arrayLastOrNull` is a [higher-order function](../../sql-reference/functions/index.md#higher-order-functions). You must pass a lambda function to it as the first argument, and it can’t be omitted.
|
||||
|
||||
**Example**
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
SELECT arrayLastOrNull(x -> x >= 2, [1, 2, 3]);
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
```response
|
||||
3
|
||||
```
|
||||
|
||||
Query:
|
||||
|
||||
```sql
|
||||
SELECT arrayLastOrNull(x -> x >= 2, emptyArrayUInt8());
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
```response
|
||||
\N
|
||||
```
|
||||
|
||||
## arrayFirstIndex(func, arr1, …)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user