# Chalk SQL Reference: Array Functions
source: https://docs.chalk.ai/chalksql-docs#section-array-functions

## `all_match(array, predicate)`
source: https://docs.chalk.ai/chalksql-docs#all_match

Returns true if every element of the `array` satisfies the `predicate`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Overloads**

#### `all_match(array, predicate)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

#### `all_match(array, predicate)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

## `any_match(array, predicate)`
source: https://docs.chalk.ai/chalksql-docs#any_match

Returns true if any element of the `array` satisfies the `predicate`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Overloads**

#### `any_match(array, predicate)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

#### `any_match(array, predicate)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

## `array_add(array1, array2)`
source: https://docs.chalk.ai/chalksql-docs#array_add

Returns element-wise sum of two arrays.

**Examples**

```sql
SELECT array_add(ARRAY[120.5, 0.0, 42.25, 310.0], ARRAY[15.0, 60.75, 8.0, 0.0]) AS combined_daily_spend;
```

```text
[135.5, 60.75, 50.25, 310.0]
```

**Overloads**

#### `array_add(array1, array2)`

**Parameters**

- `array1`: `list<item: halffloat>`
  The first input array.
- `array2`: `list<item: halffloat>`
  The second input array.

#### `array_add(array1, array2)`

**Parameters**

- `array1`: `list<item: float>`
  The first input array.
- `array2`: `list<item: float>`
  The second input array.

#### `array_add(array1, array2)`

**Parameters**

- `array1`: `list<item: double>`
  The first input array.
- `array2`: `list<item: double>`
  The second input array.

#### `array_add(array1, array2)`

**Parameters**

- `array1`: `large_list<item: halffloat>`
  The first input array.
- `array2`: `large_list<item: halffloat>`
  The second input array.

#### `array_add(array1, array2)`

**Parameters**

- `array1`: `large_list<item: float>`
  The first input array.
- `array2`: `large_list<item: float>`
  The second input array.

#### `array_add(array1, array2)`

**Parameters**

- `array1`: `large_list<item: double>`
  The first input array.
- `array2`: `large_list<item: double>`
  The second input array.

## `array_all(array)`
source: https://docs.chalk.ai/chalksql-docs#array_all

Returns true if all elements in a boolean `array` are true.

**Examples**

```sql
SELECT array_all(transform(ARRAY['alice@example.com', 'bob@example.com', 'carol-at-example.com'], e -> strpos(e, '@') > 0)) AS all_emails_valid;
```

```text
false
```

```sql
SELECT array_all(ARRAY[true, NULL, true]) AS all_true_ignoring_nulls;
```

```text
true
```

**Overloads**

#### `array_all(array)`

**Parameters**

- `array`: `list<item: bool>`
  The input `array` or list.

#### `array_all(array)`

**Parameters**

- `array`: `large_list<item: bool>`
  The input `array` or list.

## `array_any(array)`
source: https://docs.chalk.ai/chalksql-docs#array_any

Returns true if any element in a boolean `array` is true.

**Examples**

```sql
SELECT array_any(transform(ARRAY['crypto', 'wire', 'gift card'], k -> strpos(lower('Urgent WIRE transfer to new payee'), k) > 0)) AS memo_is_risky;
```

```text
true
```

```sql
SELECT array_any(ARRAY[false, CAST(NULL AS BOOLEAN), false]) AS any_rule_fired;
```

```text
false
```

**Overloads**

#### `array_any(array)`

**Parameters**

- `array`: `list<item: bool>`
  The input `array` or list.

#### `array_any(array)`

**Parameters**

- `array`: `large_list<item: bool>`
  The input `array` or list.

## `array_append(array, element)`
source: https://docs.chalk.ai/chalksql-docs#array_append

Adds an `element` to the end of an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_append(ARRAY['login', 'view_cart'], 'checkout') AS session_events;
```

```text
[login, view_cart, checkout]
```

```sql
SELECT array_max(array_append(ARRAY[42.50, 18.99, 120.00], 310.75)) AS max_txn_amount_incl_current;
```

```text
310.75
```

**Overloads**

#### `array_append(array, element)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `element`: `$T`
  The `element` to search for. `T` means matching inputs and outputs use the same type.

#### `array_append(array, element)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `element`: `$T`
  The `element` to search for. `T` means matching inputs and outputs use the same type.

## `array_apply(x, y)`
source: https://docs.chalk.ai/chalksql-docs#array_apply

Alias for [transform](https://docs.chalk.ai/chalksql-docs#transform).

**Examples**

```sql
SELECT array_apply(ARRAY['  Groceries', 'FUEL ', 'Dining'], tag -> lower(trim(tag))) AS normalized_tags;
```

```text
[groceries, fuel, dining]
```

```sql
SELECT array_apply(ARRAY[19.99, 5.0, 120.5], x -> round(x * 1.08, 2)) AS prices_with_tax;
```

```text
[21.59, 5.4, 130.14]
```

## `array_arg_max(array)`
source: https://docs.chalk.ai/chalksql-docs#array_arg_max

Returns the index of the maximum element in an `array`.

**Examples**

```sql
SELECT element_at(ARRAY['groceries', 'travel', 'dining', 'utilities'], array_arg_max(ARRAY[0.12, 0.71, 0.05, 0.12]) + 1) AS predicted_category;
```

```text
travel
```

```sql
SELECT array_arg_max(ARRAY[42, 87, NULL, 87, 15]) AS busiest_hour_index;
```

```text
1
```

**Overloads**

#### `array_arg_max(array)`

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.

#### `array_arg_max(array)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.

#### `array_arg_max(array)`

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.

#### `array_arg_max(array)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.

## `array_arg_min(array)`
source: https://docs.chalk.ai/chalksql-docs#array_arg_min

Returns the index of the minimum element in an `array`.

**Examples**

```sql
SELECT element_at(ARRAY['ups', 'fedex', 'usps', 'dhl'], array_arg_min(ARRAY[412.50, 389.99, 405.00, 395.25]) + 1) AS cheapest_carrier;
```

```text
fedex
```

```sql
SELECT array_arg_min(ARRAY[CAST(NULL AS DOUBLE), 0.42, 0.17, 0.88, 0.17]) AS nearest_centroid_idx;
```

```text
2
```

**Overloads**

#### `array_arg_min(array)`

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.

#### `array_arg_min(array)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.

#### `array_arg_min(array)`

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.

#### `array_arg_min(array)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.

## `array_average(array)`
source: https://docs.chalk.ai/chalksql-docs#array_average

Calculates the average of numeric values in an `array`.

**Examples**

```sql
SELECT round(array_average(ARRAY[42.50, 18.99, 120.00, 7.25, 61.30]), 2) AS avg_recent_txn_amount;
```

```text
50.01
```

```sql
SELECT array_average(ARRAY[4.5, NULL, 5.0, 2.5]) AS avg_review_rating;
```

```text
4.0
```

**Overloads**

#### `array_average(array)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.

#### `array_average(array)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.

## `array_compact(array)`
source: https://docs.chalk.ai/chalksql-docs#array_compact

Removes all null values from an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_compact(ARRAY[CASE WHEN 1250.00 > 1000 THEN 'large_amount' END, CASE WHEN 'US' <> 'BR' THEN 'cross_border' END, CASE WHEN 3 > 5 THEN 'high_velocity' END]) AS triggered_rules;
```

```text
[large_amount, cross_border]
```

```sql
SELECT cardinality(array_compact(ARRAY['ada@example.com', NULL, '+1-555-0100', NULL])) AS contact_methods_on_file;
```

```text
2
```

**Overloads**

#### `array_compact(array)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `array_compact(array)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

## `array_constructor(values)`
source: https://docs.chalk.ai/chalksql-docs#array_constructor

Creates an array from zero or more `values`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_constructor(1, 2, 3);
```

```text
[1, 2, 3]
```

**Overloads**

#### `array_constructor()`

Creates an empty array.

**Parameters**

None

#### `array_constructor(values)`

Creates an array from a variable number of arguments.

**Parameters**

- `values`: `$T...`
  The input `values`. `T` means matching inputs and outputs use the same type.

## `array_contains(array, element)`
source: https://docs.chalk.ai/chalksql-docs#array_contains

Alias for [contains](https://docs.chalk.ai/chalksql-docs#contains).

**Examples**

```sql
SELECT array_contains(split(lower('Refund for order 8812 - duplicate charge'), ' '), 'refund') AS memo_mentions_refund;
```

```text
true
```

```sql
SELECT array_contains(ARRAY[5411, 5812, 7995], 7995) AS has_gambling_mcc;
```

```text
true
```

## `array_contains_element(array, element)`
source: https://docs.chalk.ai/chalksql-docs#array_contains_element

Returns true if the `array` contains the given `element`.

**Examples**

```sql
SELECT array_contains_element(split(lower('Wire transfer to Crypto exchange'), ' '), 'crypto') AS memo_mentions_crypto;
```

```text
true
```

```sql
SELECT array_contains_element(ARRAY[5411, 5812, 5541], 7995) AS used_gambling_mcc;
```

```text
false
```

**Overloads**

#### `array_contains_element(array, element)`

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.
- `element`: `int64`
  The `element` to search for.

#### `array_contains_element(array, element)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.
- `element`: `double`
  The `element` to search for.

#### `array_contains_element(array, element)`

**Parameters**

- `array`: `list<item: string>`
  The input `array` or list.
- `element`: `string`
  The `element` to search for.

#### `array_contains_element(array, element)`

**Parameters**

- `array`: `list<item: large_string>`
  The input `array` or list.
- `element`: `large_string`
  The `element` to search for.

#### `array_contains_element(array, element)`

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.
- `element`: `int64`
  The `element` to search for.

#### `array_contains_element(array, element)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.
- `element`: `double`
  The `element` to search for.

#### `array_contains_element(array, element)`

**Parameters**

- `array`: `large_list<item: string>`
  The input `array` or list.
- `element`: `string`
  The `element` to search for.

#### `array_contains_element(array, element)`

**Parameters**

- `array`: `large_list<item: large_string>`
  The input `array` or list.
- `element`: `large_string`
  The `element` to search for.

## `array_cum_sum(array)`
source: https://docs.chalk.ai/chalksql-docs#array_cum_sum

Calculates the cumulative sum of numeric values in an `array`.

**Examples**

```sql
SELECT array_cum_sum(ARRAY[500.00, -120.50, -45.25, 250.00, -80.00]) AS running_balance;
```

```text
[500.0, 379.5, 334.25, 584.25, 504.25]
```

```sql
SELECT array_cum_sum(transform(ARRAY[3, 5, NULL, 2], x -> coalesce(x, 0))) AS running_total;
```

```text
[3, 8, 8, 10]
```

**Overloads**

#### `array_cum_sum(array)`

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.

#### `array_cum_sum(array)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.

#### `array_cum_sum(array)`

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.

#### `array_cum_sum(array)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.

## `array_distinct(array)`
source: https://docs.chalk.ai/chalksql-docs#array_distinct

Returns an `array` with duplicate elements removed, preserving order.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_distinct(ARRAY['card_present', 'online', 'card_present', 'atm', 'online', 'online']) AS distinct_channels;
```

```text
[card_present, online, atm]
```

```sql
SELECT cardinality(array_distinct(ARRAY['dev_a1', 'dev_b7', 'dev_a1', 'dev_c3', 'dev_b7'])) AS distinct_device_count;
```

```text
3
```

**Overloads**

#### `array_distinct(array)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `array_distinct(array)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

## `array_duplicates(array)`
source: https://docs.chalk.ai/chalksql-docs#array_duplicates

Returns an `array` containing only the duplicate elements from the input `array`.

**Examples**

```sql
SELECT array_duplicates(split('INV-1042,INV-2210,INV-1042,INV-3301,INV-2210,INV-1042', ',')) AS repeated_invoice_ids;
```

```text
[INV-1042, INV-2210]
```

```sql
SELECT cardinality(array_duplicates(ARRAY[4417, 9012, 4417, 3388, 9012, 4417])) AS reused_device_count;
```

```text
2
```

**Overloads**

#### `array_duplicates(array)`

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.

#### `array_duplicates(array)`

**Parameters**

- `array`: `list<item: large_string>`
  The input `array` or list.

#### `array_duplicates(array)`

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.

#### `array_duplicates(array)`

**Parameters**

- `array`: `large_list<item: large_string>`
  The input `array` or list.

## `array_except(array1, array2)`
source: https://docs.chalk.ai/chalksql-docs#array_except

Returns elements from the first array that are not present in the second array.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_except(ARRAY['electronics', 'books', 'garden', 'toys'], ARRAY['books', 'toys']) AS unexplored_categories;
```

```text
[electronics, garden]
```

```sql
SELECT array_except(ARRAY[412, 205, 412, 309, 205, 118], ARRAY[309, 777]) AS new_merchant_ids;
```

```text
[412, 205, 118]
```

**Overloads**

#### `array_except(array1, array2)`

**Parameters**

- `array1`: `list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `list<item: $T>`
  The second input array. `T` means matching inputs and outputs use the same type.

#### `array_except(array1, array2)`

**Parameters**

- `array1`: `large_list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `large_list<item: $T>`
  The second input array. `T` means matching inputs and outputs use the same type.

## `array_filter(array, predicate)`
source: https://docs.chalk.ai/chalksql-docs#array_filter

Filters an `array` using a callback function `predicate`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_filter(ARRAY[12.50, -3.00, 249.99, -45.00, 8.75], x -> x < 0) AS refund_amounts;
```

```text
[-3.0, -45.0]
```

```sql
SELECT array_filter(split('urgent,billing,,refund,priority:high', ','), t -> t <> '' AND NOT starts_with(t, 'priority:')) AS ticket_tags;
```

```text
[urgent, billing, refund]
```

## `array_frequency(array)`
source: https://docs.chalk.ai/chalksql-docs#array_frequency

Returns a map of elements to their frequency counts in an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_frequency(ARRAY['card_present','online','online','atm','online']) AS channel_counts;
```

```text
{card_present: 1, online: 3, atm: 1}
```

```sql
SELECT element_at(array_frequency(split(lower('Refund please. I asked for a refund twice and still no refund'), ' ')), 'refund') AS refund_mentions;
```

```text
3
```

## `array_has_duplicates(array)`
source: https://docs.chalk.ai/chalksql-docs#array_has_duplicates

Checks if an `array` contains duplicate elements.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_has_duplicates(ARRAY['dev_a1', 'dev_b7', 'dev_a1', 'dev_c3']) AS reused_device;
```

```text
true
```

```sql
SELECT array_has_duplicates(transform(split('Alice@Example.com,bob@example.com,alice@example.com', ','), e -> lower(e))) AS shared_email;
```

```text
true
```

**Overloads**

#### `array_has_duplicates(array)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `array_has_duplicates(array)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

## `array_indexof(array, element)`
source: https://docs.chalk.ai/chalksql-docs#array_indexof

Alias for [array_position](https://docs.chalk.ai/chalksql-docs#array_position).

**Examples**

```sql
SELECT array_indexof(ARRAY['approved', 'approved', 'declined', 'approved'], 'declined') AS first_decline_attempt;
```

```text
3
```

```sql
SELECT array_indexof(ARRAY['low', 'medium', 'high', 'urgent'], 'critical') AS priority_rank;
```

```text
0
```

## `array_intersect(array1, array2)`
source: https://docs.chalk.ai/chalksql-docs#array_intersect

Returns the intersection of two arrays (elements present in both arrays).

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_intersect(ARRAY['refund','urgent','billing','shipping'], ARRAY['billing','refund','chargeback']) AS escalation_tags;
```

```text
[refund, billing]
```

```sql
SELECT cardinality(array_intersect(split(lower('Wireless Noise Cancelling Headphones Black'), ' '), split(lower('noise cancelling headphones'), ' '))) AS query_term_matches;
```

```text
3
```

```sql
SELECT array_intersect(ARRAY[3, 1, 3, 2], ARRAY[3, 3, 2]) AS shared;
```

```text
[3, 2]
```

**Overloads**

#### `array_intersect(array1, array2)`

**Parameters**

- `array1`: `list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `list<item: $T>`
  The second input array. `T` means matching inputs and outputs use the same type.

#### `array_intersect(array1, array2)`

**Parameters**

- `array1`: `large_list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `large_list<item: $T>`
  The second input array. `T` means matching inputs and outputs use the same type.

## `array_join(array, delimiter, ...)`
source: https://docs.chalk.ai/chalksql-docs#array_join

Joins `array` elements into a string using a separator and optional null replacement.

**Type parameters.** `K` is the key type of the input map.

**Examples**

```sql
SELECT array_join(array_constructor('a', 'b', 'c'), ',');
```

```text
a,b,c
```

**Overloads**

#### `array_join(array, delimiter, null_replacement)`

Joins elements of an `array` into a string using a separator, replacing nulls with `null_replacement`.

**Parameters**

- `array`: `list<item: $K>`
  The input `array` or list. `K` is the key type of the input map.
- `delimiter`: `large_string`
  The `delimiter` used to split or join the string.
- `null_replacement`: `large_string`
  The string used in place of null elements.

#### `array_join(array, delimiter, null_replacement)`

Joins elements of a large `array` into a string using a separator, replacing nulls.

**Parameters**

- `array`: `large_list<item: $K>`
  The input `array` or list. `K` is the key type of the input map.
- `delimiter`: `large_string`
  The `delimiter` used to split or join the string.
- `null_replacement`: `large_string`
  The string used in place of null elements.

#### `array_join(array, delimiter)`

Joins elements of an `array` into a string using a separator.

**Parameters**

- `array`: `list<item: $K>`
  The input `array` or list. `K` is the key type of the input map.
- `delimiter`: `large_string`
  The `delimiter` used to split or join the string.

#### `array_join(array, delimiter)`

Joins elements of a large `array` into a string using a separator.

**Parameters**

- `array`: `large_list<item: $K>`
  The input `array` or list. `K` is the key type of the input map.
- `delimiter`: `large_string`
  The `delimiter` used to split or join the string.

## `array_length(array)`
source: https://docs.chalk.ai/chalksql-docs#array_length

Alias for [cardinality](https://docs.chalk.ai/chalksql-docs#cardinality).

**Examples**

```sql
SELECT array_length(split('refund requested for order 4821 damaged in shipping', ' ')) AS memo_word_count;
```

```text
8
```

```sql
SELECT array_length(array_distinct(ARRAY['US','US','GB','NG','US'])) AS distinct_login_countries;
```

```text
3
```

## `array_max(array)`
source: https://docs.chalk.ai/chalksql-docs#array_max

Returns the maximum element in an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_max(ARRAY[42.50, 18.99, 129.00, 7.25]) AS largest_purchase;
```

```text
129.0
```

```sql
SELECT array_max(remove_nulls(ARRAY[0.12, NULL, 0.87, 0.45])) AS peak_fraud_score;
```

```text
0.87
```

```sql
SELECT array_max(ARRAY[DATE '2026-03-14', DATE '2026-09-02', DATE '2026-07-21']) AS latest_login_date;
```

```text
2026-09-02
```

**Overloads**

#### `array_max(array)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `array_max(array)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

## `array_median(array)`
source: https://docs.chalk.ai/chalksql-docs#array_median

Calculates the median value of numeric elements in an `array`.

**Examples**

```sql
SELECT array_median(ARRAY[42.50, 38.00, 2499.99, 45.25, 40.10]) AS median_txn_amount;
```

```text
42.5
```

```sql
SELECT array_median(ARRAY[120, 95, 310, 140]) AS median_response_ms;
```

```text
130.0
```

```sql
SELECT array_median(remove_nulls(ARRAY[4.5, NULL, 3.0, 5.0])) AS median_rating;
```

```text
4.5
```

**Overloads**

#### `array_median(array)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.

#### `array_median(array)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.

## `array_min(array)`
source: https://docs.chalk.ai/chalksql-docs#array_min

Returns the minimum element in an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_min(ARRAY[42.5, 18.0, 7.25, 63.1]) AS smallest_txn_amount;
```

```text
7.25
```

```sql
SELECT array_min(ARRAY[TIMESTAMP '2024-03-14 09:12:00', TIMESTAMP '2024-01-02 18:40:00', TIMESTAMP '2024-02-27 07:05:00']) AS first_login_at;
```

```text
2024-01-02 18:40:00 UTC
```

**Overloads**

#### `array_min(array)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `array_min(array)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

## `array_mode(array, ...)`
source: https://docs.chalk.ai/chalksql-docs#array_mode

Returns the most frequently occurring element in an `array`.

**Examples**

```sql
SELECT array_mode(array_constructor(1, 2, 2, 3));
```

```text
2
```

**Overloads**

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `list<item: date32[day]>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `list<item: time64[us]>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `list<item: timestamp[us, tz=UTC]>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `list<item: month_day_nano_interval>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `list<item: $Decimal>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `list<item: string>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `list<item: large_string>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `large_list<item: date32[day]>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `large_list<item: time64[us]>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `large_list<item: timestamp[us, tz=UTC]>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `large_list<item: month_day_nano_interval>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `large_list<item: $Decimal>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `large_list<item: string>`
  The input `array` or list.

#### `array_mode(array)`

Returns the most frequently occurring element in an `array`.

**Parameters**

- `array`: `large_list<item: large_string>`
  The input `array` or list.

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `list<item: date32[day]>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `list<item: time64[us]>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `list<item: timestamp[us, tz=UTC]>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `list<item: month_day_nano_interval>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `list<item: $Decimal>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `list<item: string>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `list<item: large_string>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `large_list<item: date32[day]>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `large_list<item: time64[us]>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `large_list<item: timestamp[us, tz=UTC]>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `large_list<item: month_day_nano_interval>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `large_list<item: $Decimal>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `large_list<item: string>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

#### `array_mode(array, tiebreak_mode)`

Returns the most frequently occurring element in an `array` with mode selection option.

**Parameters**

- `array`: `large_list<item: large_string>`
  The input `array` or list.
- `tiebreak_mode`: `int64`
  How to break frequency ties: 0 (first seen), 1 (highest), or 2 (lowest).

## `array_multimode(array)`
source: https://docs.chalk.ai/chalksql-docs#array_multimode

Returns all most frequently occurring elements in an `array`.

**Examples**

```sql
SELECT array_multimode(ARRAY['grocery','fuel','grocery','dining','fuel','travel']) AS top_categories;
```

```text
[grocery, fuel]
```

```sql
SELECT cardinality(array_multimode(ARRAY['card','ach','card','wire','ach'])) > 1 AS has_tied_payment_method;
```

```text
true
```

**Overloads**

#### `array_multimode(array)`

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.

#### `array_multimode(array)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.

#### `array_multimode(array)`

**Parameters**

- `array`: `list<item: string>`
  The input `array` or list.

#### `array_multimode(array)`

**Parameters**

- `array`: `list<item: large_string>`
  The input `array` or list.

#### `array_multimode(array)`

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.

#### `array_multimode(array)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.

#### `array_multimode(array)`

**Parameters**

- `array`: `large_list<item: string>`
  The input `array` or list.

#### `array_multimode(array)`

**Parameters**

- `array`: `large_list<item: large_string>`
  The input `array` or list.

## `array_n_unique(array)`
source: https://docs.chalk.ai/chalksql-docs#array_n_unique

Returns the number of distinct non-null elements in an `array`.

**Examples**

```sql
SELECT array_n_unique(ARRAY['US', 'US', 'MX', NULL, 'BR', 'US']) AS distinct_card_countries;
```

```text
3
```

```sql
SELECT array_n_unique(split(lower('Refund refund REFUND please'), ' ')) AS distinct_memo_words;
```

```text
2
```

**Overloads**

#### `array_n_unique(array)`

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.

#### `array_n_unique(array)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.

#### `array_n_unique(array)`

**Parameters**

- `array`: `list<item: string>`
  The input `array` or list.

#### `array_n_unique(array)`

**Parameters**

- `array`: `list<item: large_string>`
  The input `array` or list.

#### `array_n_unique(array)`

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.

#### `array_n_unique(array)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.

#### `array_n_unique(array)`

**Parameters**

- `array`: `large_list<item: string>`
  The input `array` or list.

#### `array_n_unique(array)`

**Parameters**

- `array`: `large_list<item: large_string>`
  The input `array` or list.

## `array_normalize(array, p)`
source: https://docs.chalk.ai/chalksql-docs#array_normalize

Computes the L_p normalization of a Vector.

**Examples**

```sql
SELECT array_normalize(ARRAY[2.0, -1.0, 4.0, 2.0], 2.0) AS unit_embedding;
```

```text
[0.4, -0.2, 0.8, 0.4]
```

```sql
SELECT array_normalize(ARRAY[12.0, 3.0, 0.0, 5.0], 1.0) AS category_spend_share;
```

```text
[0.6, 0.15, 0.0, 0.25]
```

**Overloads**

#### `array_normalize(array, p)`

**Parameters**

- `array`: `list<item: float>`
  The input `array` or list.
- `p`: `float`

#### `array_normalize(array, p)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.
- `p`: `double`

#### `array_normalize(array, p)`

**Parameters**

- `array`: `list<item: halffloat>`
  The input `array` or list.
- `p`: `halffloat`

#### `array_normalize(array, p)`

**Parameters**

- `array`: `large_list<item: float>`
  The input `array` or list.
- `p`: `float`

#### `array_normalize(array, p)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.
- `p`: `double`

#### `array_normalize(array, p)`

**Parameters**

- `array`: `large_list<item: halffloat>`
  The input `array` or list.
- `p`: `halffloat`

## `array_position(array, element, ...)`
source: https://docs.chalk.ai/chalksql-docs#array_position

Returns the 1-based position of an `element` in an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_position(array_constructor('a', 'b', 'a'), 'a');
```

```text
1
```

**Overloads**

#### `array_position(array, element)`

Returns the 1-based position of the first occurrence of an `element` in an `array`.

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `element`: `$T`
  The `element` to search for. `T` means matching inputs and outputs use the same type.

#### `array_position(array, element)`

Returns the 1-based position of the first occurrence of an `element` in an `array`.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `element`: `$T`
  The `element` to search for. `T` means matching inputs and outputs use the same type.

#### `array_position(array, element, instance)`

Returns the 1-based position of the ```instance```th value in an `array`.

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `element`: `$T`
  The `element` to search for. `T` means matching inputs and outputs use the same type.
- `instance`: `int64`
  Which occurrence to locate, 1-based.

#### `array_position(array, element, instance)`

Returns the 1-based position of the ```instance```th value in an `array`.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `element`: `$T`
  The `element` to search for. `T` means matching inputs and outputs use the same type.
- `instance`: `int64`
  Which occurrence to locate, 1-based.

## `array_reduce(array, initialState, ...+2)`
source: https://docs.chalk.ai/chalksql-docs#array_reduce

Applies a reduce function to each element in an `array` and returns the accumulated value.

**Type parameters.** `T` means matching inputs and outputs use the same type. `U` is a second generic value type. `V` is the value type of the input map.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `initialState`: `$U`
  `U` is a second generic value type.
- `inputFunction`: `($U, $T) => $U`
  `T` means matching inputs and outputs use the same type. `U` is a second generic value type.
- `outputFunction`: `($U) => $V`
  `V` is the value type of the input map. `U` is a second generic value type.

**Examples**

```sql
SELECT array_reduce(ARRAY[0.02, -0.01, 0.03, 0.015], 1.0, (growth, r) -> growth * (1 + r), growth -> round((growth - 1) * 100, 2)) AS cumulative_return_pct;
```

```text
5.57
```

```sql
SELECT array_reduce(ARRAY['ok', 'fail', 'fail', 'ok', 'fail', 'fail', 'fail', 'ok'], struct_pack(cur := 0, best := 0), (s, status) -> IF(status = 'fail', struct_pack(cur := s.cur + 1, best := greatest(s.best, s.cur + 1)), struct_pack(cur := 0, best := s.best)), s -> s.best) AS longest_failure_streak;
```

```text
3
```

## `array_reduce_while(array, initial_state, function)`
source: https://docs.chalk.ai/chalksql-docs#array_reduce_while

Reduces an `array` with Python-style loop control. Lambda returns (new_state, control_code, result), where control_code is 0=normal, 1=return, 2=continue, 3=break. Returns row(final_state, control_code, result|null).

**Type parameters.** `T` means matching inputs and outputs use the same type. `S` is the callback state type. `R` is the callback result type.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `initial_state`: `$S`
  The initial accumulator state. `S` is the callback state type.
- `function`: `($S, $T) => struct<state: $S, control: int64, result: $R>`
  The callback `function` applied to the elements. `T` means matching inputs and outputs use the same type. `R` is the callback result type. `S` is the callback state type.

## `array_remove(array, element)`
source: https://docs.chalk.ai/chalksql-docs#array_remove

Removes all occurrences of a specified `element` from an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT array_remove(split('POS  PURCHASE   ACME COFFEE', ' '), '') AS memo_tokens;
```

```text
[POS, PURCHASE, ACME, COFFEE]
```

```sql
SELECT cardinality(array_remove(ARRAY[42, -1, 17, -1, 8], -1)) AS valid_reading_count;
```

```text
3
```

**Overloads**

#### `array_remove(array, element)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `element`: `$T`
  The `element` to search for. `T` means matching inputs and outputs use the same type.

#### `array_remove(array, element)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `element`: `$T`
  The `element` to search for. `T` means matching inputs and outputs use the same type.

## `array_reverse(array)`
source: https://docs.chalk.ai/chalksql-docs#array_reverse

Returns the `array` with elements in reverse order.

**Examples**

```sql
SELECT array_reverse(ARRAY['login', 'view_cart', 'add_payment', 'checkout']) AS events_newest_first;
```

```text
[checkout, add_payment, view_cart, login]
```

```sql
SELECT element_at(array_reverse(split('electronics/computers/laptops/gaming', '/')), 1) AS leaf_category;
```

```text
gaming
```

**Overloads**

#### `array_reverse(array)`

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.

#### `array_reverse(array)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.

#### `array_reverse(array)`

**Parameters**

- `array`: `list<item: string>`
  The input `array` or list.

#### `array_reverse(array)`

**Parameters**

- `array`: `list<item: large_string>`
  The input `array` or list.

#### `array_reverse(array)`

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.

#### `array_reverse(array)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.

#### `array_reverse(array)`

**Parameters**

- `array`: `large_list<item: string>`
  The input `array` or list.

#### `array_reverse(array)`

**Parameters**

- `array`: `large_list<item: large_string>`
  The input `array` or list.

## `array_slice(...)`
source: https://docs.chalk.ai/chalksql-docs#array_slice

Returns a slice from an array, string, or binary value.

**Type parameters.** `E` is the element type of the input array or list.

**Examples**

```sql
SELECT array_slice(array_constructor(1, 2, 3, 4), 2, 3);
```

```text
[2, 3, 4]
```

**Overloads**

#### `array_slice(list, begin, end)`

Extract a sublist from a `list`

**Parameters**

- `list`: `list<item: $E>`
  `E` is the element type of the input array or list.
- `begin`: `int64`
- `end`: `int64`

#### `array_slice(list, begin, ...+2)`

Extract a sublist from a `list`

**Parameters**

- `list`: `list<item: $E>`
  `E` is the element type of the input array or list.
- `begin`: `int64`
- `end`: `int64`
- `step`: `int64`
  The `step` between successive values.

#### `array_slice(list, begin, end)`

Extract a sublist from a `list`

**Parameters**

- `list`: `large_list<item: $E>`
  `E` is the element type of the input array or list.
- `begin`: `int64`
- `end`: `int64`

#### `array_slice(list, begin, ...+2)`

Extract a sublist from a `list`

**Parameters**

- `list`: `large_list<item: $E>`
  `E` is the element type of the input array or list.
- `begin`: `int64`
- `end`: `int64`
- `step`: `int64`
  The `step` between successive values.

#### `array_slice(strlike, begin, end)`

Returns a substring starting at the specified position with the given length.

**Parameters**

- `strlike`: `string`
- `begin`: `int64`
- `end`: `int64`

#### `array_slice(strlike, begin, ...+2)`

Returns a substring starting at the specified position with the given length.

**Parameters**

- `strlike`: `string`
- `begin`: `int64`
- `end`: `int64`
- `step`: `int64`
  The `step` between successive values.

#### `array_slice(strlike, begin, end)`

Returns a substring starting at the specified position with the given length.

**Parameters**

- `strlike`: `large_string`
- `begin`: `int64`
- `end`: `int64`

#### `array_slice(strlike, begin, ...+2)`

Returns a substring starting at the specified position with the given length.

**Parameters**

- `strlike`: `large_string`
- `begin`: `int64`
- `end`: `int64`
- `step`: `int64`
  The `step` between successive values.

#### `array_slice(strlike, begin, end)`

Returns a substring starting at the specified position with the given length.

**Parameters**

- `strlike`: `binary`
- `begin`: `int64`
- `end`: `int64`

#### `array_slice(strlike, begin, ...+2)`

Returns a substring starting at the specified position with the given length.

**Parameters**

- `strlike`: `binary`
- `begin`: `int64`
- `end`: `int64`
- `step`: `int64`
  The `step` between successive values.

#### `array_slice(strlike, begin, end)`

Returns a substring starting at the specified position with the given length.

**Parameters**

- `strlike`: `large_binary`
- `begin`: `int64`
- `end`: `int64`

#### `array_slice(strlike, begin, ...+2)`

Returns a substring starting at the specified position with the given length.

**Parameters**

- `strlike`: `large_binary`
- `begin`: `int64`
- `end`: `int64`
- `step`: `int64`
  The `step` between successive values.

## `array_sort(array, ...)`
source: https://docs.chalk.ai/chalksql-docs#array_sort

Sorts an `array` in ascending order, optionally using a key extraction `function`.

**Type parameters.** `T` means matching inputs and outputs use the same type. `U` is a second generic value type.

**Examples**

```sql
SELECT array_sort(array_constructor(3, 1, 2));
```

```text
[1, 2, 3]
```

**Overloads**

#### `array_sort(array)`

Sorts an `array` in ascending order.

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `array_sort(array)`

Sorts an `array` in ascending order.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `array_sort(array, function)`

Sorts an `array` using a key extraction `function`.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `function`: `($T) => $U`
  The callback `function` applied to the elements. `T` means matching inputs and outputs use the same type. `U` is a second generic value type.

## `array_sort_desc(array, ...)`
source: https://docs.chalk.ai/chalksql-docs#array_sort_desc

Sorts an `array` in descending order, optionally using a key extraction `function`.

**Type parameters.** `T` means matching inputs and outputs use the same type. `U` is a second generic value type.

**Examples**

```sql
SELECT array_sort_desc(array_constructor(3, 1, 2));
```

```text
[3, 2, 1]
```

**Overloads**

#### `array_sort_desc(array, function)`

Sorts an `array` in descending order using a key extraction `function`.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `function`: `($T) => $U`
  The callback `function` applied to the elements. `T` means matching inputs and outputs use the same type. `U` is a second generic value type.

#### `array_sort_desc(array)`

Sorts an `array` in descending order.

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `array_sort_desc(array)`

Sorts an `array` in descending order.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

## `array_stddev(array, sample)`
source: https://docs.chalk.ai/chalksql-docs#array_stddev

Calculates the standard deviation of numeric values in an `array`.

**Examples**

```sql
SELECT round(array_stddev(ARRAY[42.50, 38.75, 45.10, 40.00, 512.99], false), 2) AS txn_amount_stddev;
```

```text
188.57
```

```sql
SELECT round(array_stddev(ARRAY[1200.0, 1350.0, 1180.0, 1420.0], true), 2) AS daily_spend_sample_stddev;
```

```text
116.44
```

**Overloads**

#### `array_stddev(array, sample)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.
- `sample`: `bool`
  Whether to compute the `sample` rather than population statistic.

#### `array_stddev(array, sample)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.
- `sample`: `bool`
  Whether to compute the `sample` rather than population statistic.

## `array_sum(array)`
source: https://docs.chalk.ai/chalksql-docs#array_sum

Calculates the sum of numeric values in an `array`.

**Examples**

```sql
SELECT array_sum(ARRAY[3, NULL, 0, 5, NULL, 2, 4]) AS logins_last_7_days;
```

```text
14
```

```sql
SELECT array_sum(transform(ARRAY[2, 1, 3], qty -> qty * 19.99)) AS order_total;
```

```text
119.94
```

**Overloads**

#### `array_sum(array)`

**Parameters**

- `array`: `list<item: int64>`
  The input `array` or list.

#### `array_sum(array)`

**Parameters**

- `array`: `list<item: double>`
  The input `array` or list.

#### `array_sum(array)`

**Parameters**

- `array`: `large_list<item: int64>`
  The input `array` or list.

#### `array_sum(array)`

**Parameters**

- `array`: `large_list<item: double>`
  The input `array` or list.

## `array_to_string(array, delimiter)`
source: https://docs.chalk.ai/chalksql-docs#array_to_string

Alias for [array_join](https://docs.chalk.ai/chalksql-docs#array_join).

**Examples**

```sql
SELECT array_to_string(array_sort(ARRAY['travel', 'electronics', 'grocery']), '|') AS category_key;
```

```text
electronics|grocery|travel
```

```sql
SELECT array_to_string(ARRAY['US', NULL, 'CA'], ',') AS ship_countries;
```

```text
US,CA
```

## `array_transform(array, function)`
source: https://docs.chalk.ai/chalksql-docs#array_transform

Applies a transformation `function` to each element in an `array` and returns a new `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type. `U` is a second generic value type.

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `function`: `($T) => $U`
  The callback `function` applied to the elements. `T` means matching inputs and outputs use the same type. `U` is a second generic value type.

**Examples**

```sql
SELECT array_transform(ARRAY['  Groceries', 'DINING ', 'Travel'], tag -> lower(trim(tag))) AS normalized_tags;
```

```text
[groceries, dining, travel]
```

```sql
SELECT array_transform(ARRAY[1200, 45, 8800], amount_cents -> amount_cents >= 5000) AS is_large_txn;
```

```text
[false, false, true]
```

## `array_unique(x)`
source: https://docs.chalk.ai/chalksql-docs#array_unique

Alias for [array_distinct](https://docs.chalk.ai/chalksql-docs#array_distinct).

**Examples**

```sql
SELECT array_unique(split('login,view,login,purchase,view,login', ',')) AS distinct_events;
```

```text
[login, view, purchase]
```

```sql
SELECT cardinality(array_unique(ARRAY['US', 'US', 'MX', 'US', 'BR', 'MX'])) AS distinct_card_countries;
```

```text
3
```

## `array_value(values)`
source: https://docs.chalk.ai/chalksql-docs#array_value

Alias for [array_constructor](https://docs.chalk.ai/chalksql-docs#array_constructor).

**Examples**

```sql
SELECT array_value('electronics', 'books', 'toys') AS categories;
```

```text
[electronics, books, toys]
```

```sql
SELECT contains(array_value('US', 'CA', 'GB'), upper('ca')) AS is_supported_country;
```

```text
true
```

```sql
SELECT array_max(array_value(0.12, 0.87, 0.35)) AS max_risk_signal;
```

```text
0.87
```

## `arrays_overlap(array1, array2)`
source: https://docs.chalk.ai/chalksql-docs#arrays_overlap

Checks if two arrays have any elements in common.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT arrays_overlap(split(lower('Wire transfer to CRYPTO exchange'), ' '), ARRAY['crypto', 'casino', 'gift']) AS memo_mentions_risky_merchant;
```

```text
true
```

```sql
SELECT arrays_overlap(ARRAY['electronics', 'gaming'], ARRAY['groceries', 'pharmacy']) AS shares_category;
```

```text
false
```

**Overloads**

#### `arrays_overlap(array1, array2)`

**Parameters**

- `array1`: `list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `list<item: $T>`
  The second input array. `T` means matching inputs and outputs use the same type.

#### `arrays_overlap(array1, array2)`

**Parameters**

- `array1`: `large_list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `large_list<item: $T>`
  The second input array. `T` means matching inputs and outputs use the same type.

## `arrays_union(array1, array2)`
source: https://docs.chalk.ai/chalksql-docs#arrays_union

Returns a list of the distinct elements of the common elements

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT arrays_union(ARRAY['electronics', 'gift', 'sale'], ARRAY['sale', 'clearance', 'gift']) AS merged_tags;
```

```text
[electronics, gift, sale, clearance]
```

```sql
SELECT cardinality(arrays_union(ARRAY['ios', 'web', 'ios'], ARRAY['web', 'android'])) AS distinct_device_platforms;
```

```text
3
```

**Overloads**

#### `arrays_union(array1, array2)`

**Parameters**

- `array1`: `list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `list<item: $T>`
  The second input array. `T` means matching inputs and outputs use the same type.

#### `arrays_union(array1, array2)`

**Parameters**

- `array1`: `large_list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `large_list<item: $T>`
  The second input array. `T` means matching inputs and outputs use the same type.

## `cardinality(...)`
source: https://docs.chalk.ai/chalksql-docs#cardinality

Returns the number of elements in an `array` or entries in a `map`.

**Type parameters.** `V` is the value type of the input map. `K` is the key type of the input map.

**Examples**

```sql
SELECT cardinality(array_constructor(1, 2, 3));
```

```text
3
```

**Overloads**

#### `cardinality(array)`

Returns the number of elements in a list.

**Parameters**

- `array`: `list<item: $V>`
  The input `array` or list. `V` is the value type of the input map.

#### `cardinality(array)`

Returns the number of elements in a list.

**Parameters**

- `array`: `large_list<item: $V>`
  The input `array` or list. `V` is the value type of the input map.

#### `cardinality(map)`

Returns the number of entries in a `map`.

**Parameters**

- `map`: `map<$K, $V>`
  The input `map`. `K` is the key type of the input map. `V` is the value type of the input map.

## `combinations(array, n)`
source: https://docs.chalk.ai/chalksql-docs#combinations

Returns all possible combinations of the given size from an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT combinations(array_sort(array_distinct(ARRAY['laptop','mouse','laptop','usb_hub'])), 2) AS basket_pairs;
```

```text
[[laptop, mouse], [laptop, usb_hub], [mouse, usb_hub]]
```

```sql
SELECT transform(combinations(ARRAY['card','wallet','bank'], 2), p -> array_join(p, '+')) AS channel_pairs;
```

```text
[card+wallet, card+bank, wallet+bank]
```

**Overloads**

#### `combinations(array, n)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `n`: `int32`
  The number of elements in each combination.

#### `combinations(array, n)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `n`: `int32`
  The number of elements in each combination.

## `contains(array, element)`
source: https://docs.chalk.ai/chalksql-docs#contains

Checks if a list contains a specific `element`.

**Type parameters.** `V` is the value type of the input map.

**Parameters**

- `array`: `large_list<item: $V>`
  The input `array` or list. `V` is the value type of the input map.
- `element`: `$V`
  The `element` to search for. `V` is the value type of the input map.

**Examples**

```sql
SELECT contains(split(lower('Wire transfer for CRYPTO exchange deposit'), ' '), 'crypto') AS memo_mentions_crypto;
```

```text
true
```

```sql
SELECT contains(ARRAY[7995, 6051, 4829], 5411) AS is_high_risk_mcc;
```

```text
false
```

## `element_at(...)`
source: https://docs.chalk.ai/chalksql-docs#element_at

Returns an element from an `array` or `map`.

**Type parameters.** `E` is the element type of the input array or list. `K` is the key type of the input map. `V` is the value type of the input map.

**Examples**

```sql
SELECT element_at(array_constructor('a', 'b'), 2);
```

```text
b
```

**Overloads**

#### `element_at(array, index)`

Returns the element at the specified `index` in a list.

**Parameters**

- `array`: `list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `index`: `int64`
  The `index` to read.

#### `element_at(array, index)`

Returns the element at the specified `index` in a list.

**Parameters**

- `array`: `large_list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `index`: `int64`
  The `index` to read.

#### `element_at(array, index)`

Returns the element at the specified `index` in a list.

**Parameters**

- `array`: `list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `index`: `int64`
  The `index` to read.

#### `element_at(array, index)`

Returns the element at the specified `index` in a list.

**Parameters**

- `array`: `large_list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `index`: `int64`
  The `index` to read.

#### `element_at(map, key)`

Retrieves the value associated with a `key` from a `map`.

**Parameters**

- `map`: `map<$K, $V>`
  The input `map`. `K` is the key type of the input map. `V` is the value type of the input map.
- `key`: `$K`
  The map `key` to read or update. `K` is the key type of the input map.

## `find_first(array, ...)`
source: https://docs.chalk.ai/chalksql-docs#find_first

Returns the first element in an `array` that matches the given `predicate` function.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT find_first(ARRAY[120.0, 45.5, 980.0, 2500.0, 60.0], x -> x > 500) AS first_large_txn;
```

```text
980.0
```

```sql
SELECT find_first(ARRAY['gmail.com', 'acme-corp.com', 'yahoo.com'], d -> d NOT IN ('gmail.com', 'yahoo.com', 'hotmail.com')) AS work_domain;
```

```text
acme-corp.com
```

**Overloads**

#### `find_first(array, predicate)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

#### `find_first(array, index, predicate)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `index`: `int64`
  The `index` to read.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

#### `find_first(array, predicate)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

#### `find_first(array, index, predicate)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `index`: `int64`
  The `index` to read.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

## `find_first_index(array, ...)`
source: https://docs.chalk.ai/chalksql-docs#find_first_index

Returns the 1-based index of the first element in an `array` that matches the given `predicate` function.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT find_first_index(ARRAY[42.10, 18.75, 1250.00, 9.99, 3400.00], x -> x > 1000) AS first_large_txn_position;
```

```text
3
```

```sql
SELECT find_first_index(ARRAY['viewed', 'added_to_cart', 'viewed', 'purchased'], e -> e = 'purchased') AS steps_to_purchase;
```

```text
4
```

**Overloads**

#### `find_first_index(array, predicate)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

#### `find_first_index(array, index, predicate)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `index`: `int64`
  The `index` to read.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

#### `find_first_index(array, predicate)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

#### `find_first_index(array, index, predicate)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `index`: `int64`
  The `index` to read.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

## `flatten(array)`
source: https://docs.chalk.ai/chalksql-docs#flatten

Flattens a nested `array` by one level, combining all sub-arrays into a single `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT flatten(ARRAY[ARRAY['electronics', 'audio'], ARRAY['audio', 'accessories'], ARRAY['books']]) AS order_categories;
```

```text
[electronics, audio, audio, accessories, books]
```

```sql
SELECT flatten(ARRAY[ARRAY[ARRAY[1, 2], ARRAY[3]], ARRAY[ARRAY[4]]]) AS one_level;
```

```text
[[1, 2], [3], [4]]
```

**Overloads**

#### `flatten(array)`

**Parameters**

- `array`: `list<item: list<item: $T>>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `flatten(array)`

**Parameters**

- `array`: `large_list<item: large_list<item: $T>>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

## `greatest(value1, value2)`
source: https://docs.chalk.ai/chalksql-docs#greatest

Returns the largest value from a list of values.

**Type parameters.** `T_ord` can be any orderable type, such as a number, string, date, timestamp, or boolean.

**Examples**

```sql
SELECT greatest(3.0, 7.0, 5.0);
```

```text
7.0
```

```sql
SELECT greatest(3, 7, 5);
```

```text
7
```

**Overloads**

#### `greatest(value1, value2)`

Returns the maximum value from a list of float values.

**Parameters**

- `value1`: `double`
  The first value.
- `value2`: `double...`
  The second value.

#### `greatest(value1, value2)`

Returns the maximum value from a list of integer values.

**Parameters**

- `value1`: `int64`
  The first value.
- `value2`: `int64...`
  The second value.

#### `greatest(value1, value2)`

Returns the maximum value from a list of integer values.

**Parameters**

- `value1`: `$T_ord`
  The first value. `T_ord` can be any orderable type, such as a number, string, date, timestamp, or boolean.
- `value2`: `$T_ord...`
  The second value. `T_ord` can be any orderable type, such as a number, string, date, timestamp, or boolean.

## `least(value1, value2)`
source: https://docs.chalk.ai/chalksql-docs#least

Returns the smallest value from a list of values.

**Type parameters.** `T_ord` can be any orderable type, such as a number, string, date, timestamp, or boolean.

**Examples**

```sql
SELECT least(3.0, 7.0, 5.0);
```

```text
3.0
```

```sql
SELECT least(3, 7, 5);
```

```text
3
```

**Overloads**

#### `least(value1, value2)`

Returns the minimum value from a list of float values.

**Parameters**

- `value1`: `double`
  The first value.
- `value2`: `double...`
  The second value.

#### `least(value1, value2)`

Returns the minimum value from a list of integer values.

**Parameters**

- `value1`: `int64`
  The first value.
- `value2`: `int64...`
  The second value.

#### `least(value1, value2)`

Returns the minimum value from a list of float values.

**Parameters**

- `value1`: `$T_ord`
  The first value. `T_ord` can be any orderable type, such as a number, string, date, timestamp, or boolean.
- `value2`: `$T_ord...`
  The second value. `T_ord` can be any orderable type, such as a number, string, date, timestamp, or boolean.

## `list_apply(x, y)`
source: https://docs.chalk.ai/chalksql-docs#list_apply

Alias for [transform](https://docs.chalk.ai/chalksql-docs#transform).

**Examples**

```sql
SELECT list_apply(ARRAY['  Groceries ', 'GAS', 'groceries'], t -> lower(trim(t))) AS normalized_tags;
```

```text
[groceries, gas, groceries]
```

```sql
SELECT list_apply(ARRAY[12.5, 250.0, 4999.99], amt -> amt > 1000) AS is_large_txn;
```

```text
[false, false, true]
```

## `list_avg(x)`
source: https://docs.chalk.ai/chalksql-docs#list_avg

Alias for [array_average](https://docs.chalk.ai/chalksql-docs#array_average).

**Examples**

```sql
SELECT list_avg(ARRAY[42.50, 18.99, 120.00, 7.25]) AS avg_txn_amount;
```

```text
47.185
```

```sql
SELECT list_avg(ARRAY[4, 5, NULL, 3, 5]) AS avg_review_rating;
```

```text
4.25
```

## `list_concat(...)`
source: https://docs.chalk.ai/chalksql-docs#list_concat

Alias for [concat](https://docs.chalk.ai/chalksql-docs#concat).

**Examples**

```sql
SELECT list_concat(ARRAY['electronics','laptops'], ARRAY['clearance'], ARRAY['back_to_school']) AS merged_tags;
```

```text
[electronics, laptops, clearance, back_to_school]
```

```sql
SELECT array_max(list_concat(ARRAY[42.50, 18.00, 7.25], ARRAY[310.00, 299.99])) AS max_txn_amount;
```

```text
310.0
```

## `list_contains(array, element)`
source: https://docs.chalk.ai/chalksql-docs#list_contains

Alias for [contains](https://docs.chalk.ai/chalksql-docs#contains).

**Examples**

```sql
SELECT list_contains(split(lower('Wire transfer to CRYPTO exchange'), ' '), 'crypto') AS memo_mentions_crypto;
```

```text
true
```

```sql
SELECT list_contains(ARRAY[5411, 5812, 7995], 7995) AS is_gambling_mcc;
```

```text
true
```

## `list_count(array)`
source: https://docs.chalk.ai/chalksql-docs#list_count

Alias for [cardinality](https://docs.chalk.ai/chalksql-docs#cardinality).

**Examples**

```sql
SELECT list_count(regexp_split_to_array('Refund request: duplicate charge on order #4821, card ending 1234', ' ')) AS memo_word_count;
```

```text
10
```

```sql
SELECT list_count(array_distinct(ARRAY['electronics', 'gift_card', 'electronics', 'jewelry'])) AS distinct_category_count;
```

```text
3
```

## `list_distinct(x)`
source: https://docs.chalk.ai/chalksql-docs#list_distinct

Alias for [array_distinct](https://docs.chalk.ai/chalksql-docs#array_distinct).

**Examples**

```sql
SELECT list_distinct(regexp_split(lower('Refund refund REFUND card fee card'), ' ')) AS memo_tokens;
```

```text
[refund, card, fee]
```

```sql
SELECT cardinality(list_distinct(ARRAY['ios', 'web', 'ios', 'android', 'web', 'ios'])) AS distinct_devices;
```

```text
3
```

## `list_extract(...)`
source: https://docs.chalk.ai/chalksql-docs#list_extract

Either:

- Returns the element at the specified index in a list.
- Retrieves the value associated with a key from a map.

**Type parameters.** `E` is the element type of the input array or list. `K` is the key type of the input map. `V` is the value type of the input map.

**Examples**

```sql
SELECT list_extract(split('Amazon Mktplace*2K4LP1 Seattle WA', ' '), 1) AS merchant_token;
```

```text
Amazon
```

```sql
SELECT list_extract(split('Amazon Mktplace*2K4LP1 Seattle WA', ' '), -1) AS state_code;
```

```text
WA
```

```sql
SELECT list_extract(MAP(ARRAY['US', 'CA', 'MX'], ARRAY[0.02, 0.05, 0.11]), 'CA') AS country_risk;
```

```text
0.05
```

**Overloads**

#### `list_extract(array, index)`

Returns the element at the specified `index` in a list.

**Parameters**

- `array`: `list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `index`: `int64`
  The `index` to read.

#### `list_extract(array, index)`

Returns the element at the specified `index` in a list.

**Parameters**

- `array`: `large_list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `index`: `int64`
  The `index` to read.

#### `list_extract(array, index)`

Returns the element at the specified `index` in a list.

**Parameters**

- `array`: `list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `index`: `int64`
  The `index` to read.

#### `list_extract(array, index)`

Returns the element at the specified `index` in a list.

**Parameters**

- `array`: `large_list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `index`: `int64`
  The `index` to read.

#### `list_extract(map, key)`

Retrieves the value associated with a `key` from a `map`.

**Parameters**

- `map`: `map<$K, $V>`
  The input `map`. `K` is the key type of the input map. `V` is the value type of the input map.
- `key`: `$K`
  The map `key` to read or update. `K` is the key type of the input map.

## `list_filter(list, predicate)`
source: https://docs.chalk.ai/chalksql-docs#list_filter

Filters a `list` using a callback function `predicate`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT list_filter([12.50, 899.00, 3.25, 1450.00, 64.10], amt -> amt > 500) AS large_transactions;
```

```text
[899.0, 1450.0]
```

```sql
SELECT list_filter(['wire transfer to acct', 'grocery store', 'crypto exchange deposit', 'coffee'], memo -> memo LIKE '%wire%' OR memo LIKE '%crypto%') AS risky_memos;
```

```text
[wire transfer to acct, crypto exchange deposit]
```

```sql
SELECT cardinality(list_filter(['success', 'failed', 'failed', 'success', 'failed'], status -> status = 'failed')) AS failed_login_count;
```

```text
3
```

**Overloads**

#### `list_filter(list, predicate)`

**Parameters**

- `list`: `list<item: $T>`
  `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

#### `list_filter(list, predicate)`

**Parameters**

- `list`: `large_list<item: $T>`
  `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

## `list_has(array, element)`
source: https://docs.chalk.ai/chalksql-docs#list_has

Alias for [contains](https://docs.chalk.ai/chalksql-docs#contains).

**Examples**

```sql
SELECT list_has(split(lower('POS PURCHASE ACH REVERSAL 0423'), ' '), 'reversal') AS is_reversal;
```

```text
true
```

```sql
SELECT list_has(ARRAY[200, 201, 204], 404) AS is_success_status;
```

```text
false
```

## `list_has_any(array1, array2)`
source: https://docs.chalk.ai/chalksql-docs#list_has_any

Alias for [arrays_overlap](https://docs.chalk.ai/chalksql-docs#arrays_overlap).

**Examples**

```sql
SELECT list_has_any(['refund', 'chargeback', 'dispute'], split(lower('Customer filed a DISPUTE for order 4412'), ' ')) AS mentions_dispute_term;
```

```text
true
```

```sql
SELECT list_has_any(['gift_cards', 'crypto', 'wire_transfer'], ['electronics', 'books', 'groceries']) AS has_high_risk_category;
```

```text
false
```

## `list_intersect(array1, array2)`
source: https://docs.chalk.ai/chalksql-docs#list_intersect

Alias for [array_intersect](https://docs.chalk.ai/chalksql-docs#array_intersect).

**Examples**

```sql
SELECT cardinality(list_intersect(split(lower('Refund for DUPLICATE charge, possible fraud'), ' '), ARRAY['refund','chargeback','dispute','duplicate','fraud'])) AS dispute_keyword_hits;
```

```text
3
```

```sql
SELECT list_intersect(ARRAY[101, 205, 205, 330, 412], ARRAY[205, 412, 412, 999]) AS shared_merchant_ids;
```

```text
[205, 412]
```

## `list_max(x)`
source: https://docs.chalk.ai/chalksql-docs#list_max

Alias for [array_max](https://docs.chalk.ai/chalksql-docs#array_max).

**Examples**

```sql
SELECT list_max(ARRAY[42.50, 1299.99, 18.75, 310.00]) AS largest_purchase;
```

```text
1299.99
```

```sql
SELECT list_max(ARRAY['2026-03-14', '2026-09-30', '2026-07-02']) AS latest_login_date;
```

```text
2026-09-30
```

## `list_median(array)`
source: https://docs.chalk.ai/chalksql-docs#list_median

Alias for [array_median](https://docs.chalk.ai/chalksql-docs#array_median).

**Examples**

```sql
SELECT list_median([42.5, 18.0, 1250.0, 37.25, 29.99]) AS median_order_amount;
```

```text
37.25
```

```sql
SELECT list_median([12, 45, 8, 30]) AS median_session_minutes;
```

```text
21.0
```

## `list_min(x)`
source: https://docs.chalk.ai/chalksql-docs#list_min

Alias for [array_min](https://docs.chalk.ai/chalksql-docs#array_min).

**Examples**

```sql
SELECT list_min(ARRAY[42.50, 18.99, 7.25, 103.00]) AS smallest_txn_amount;
```

```text
7.25
```

```sql
SELECT list_min(ARRAY[DATE '2026-03-14', DATE '2025-11-02', DATE '2026-01-20']) AS first_order_date;
```

```text
2025-11-02
```

## `list_mode(array, ...)`
source: https://docs.chalk.ai/chalksql-docs#list_mode

Alias for [array_mode](https://docs.chalk.ai/chalksql-docs#array_mode).

**Examples**

```sql
SELECT array_mode(array_constructor(1, 2, 2, 3));
```

```text
2
```

## `list_pack(values)`
source: https://docs.chalk.ai/chalksql-docs#list_pack

Alias for [array_constructor](https://docs.chalk.ai/chalksql-docs#array_constructor).

**Examples**

```sql
SELECT remove_nulls(list_pack(CASE WHEN 950.0 > 500 THEN 'large_amount' END, CASE WHEN 'NG' <> 'US' THEN 'foreign_ip' END, CASE WHEN 2 > 5 THEN 'high_velocity' END)) AS risk_flags;
```

```text
[large_amount, foreign_ip]
```

```sql
SELECT array_max(list_pack(120.0, 87.5, 342.0, 15.25)) AS max_txn_amount;
```

```text
342.0
```

## `list_position(array, element)`
source: https://docs.chalk.ai/chalksql-docs#list_position

Alias for [array_position](https://docs.chalk.ai/chalksql-docs#array_position).

**Examples**

```sql
SELECT list_position(ARRAY['card_present', 'ecommerce', 'atm_withdrawal', 'wire'], 'atm_withdrawal') AS channel_index;
```

```text
3
```

```sql
SELECT list_position(ARRAY['low', 'medium', 'high', 'critical'], 'unknown') AS severity_rank;
```

```text
0
```

## `list_slice(...)`
source: https://docs.chalk.ai/chalksql-docs#list_slice

Alias for [array_slice](https://docs.chalk.ai/chalksql-docs#array_slice).

**Examples**

```sql
SELECT list_slice(ARRAY[12.50, 8.99, 240.00, 15.25, 980.00, 1250.00], -3, -1) AS last_3_txn_amounts;
```

```text
[15.25, 980.0, 1250.0]
```

```sql
SELECT list_slice(ARRAY['login','view_item','add_to_cart','view_item','checkout','purchase'], 1, 6, 2) AS every_other_event;
```

```text
[login, add_to_cart, checkout]
```

```sql
SELECT list_slice('ACCT-2024-00918', 6, 9) AS account_year;
```

```text
2024
```

## `list_sort(x, ...)`
source: https://docs.chalk.ai/chalksql-docs#list_sort

Alias for [array_sort](https://docs.chalk.ai/chalksql-docs#array_sort).

**Examples**

```sql
SELECT list_sort(ARRAY[42.50, NULL, 7.99, 120.00, 15.25]) AS sorted_amounts;
```

```text
[7.99, 15.25, 42.5, 120.0, NULL]
```

```sql
SELECT slice(list_sort(ARRAY[42.50, 7.99, 120.00, 15.25, 89.00], x -> -x), 1, 3) AS top_3_amounts;
```

```text
[120.0, 89.0, 42.5]
```

## `list_stddev_pop(array, sample)`
source: https://docs.chalk.ai/chalksql-docs#list_stddev_pop

Alias for [array_stddev](https://docs.chalk.ai/chalksql-docs#array_stddev).

**Examples**

```sql
SELECT round(list_stddev_pop([12.5, 48.0, 9.99, 130.0, 22.75], false), 2) AS txn_amount_stddev;
```

```text
44.74
```

```sql
SELECT round(list_stddev_pop([12.5, 48.0, 9.99, 130.0, 22.75], true), 2) AS txn_amount_sample_stddev;
```

```text
50.03
```

## `list_sum(x)`
source: https://docs.chalk.ai/chalksql-docs#list_sum

Alias for [array_sum](https://docs.chalk.ai/chalksql-docs#array_sum).

**Examples**

```sql
SELECT list_sum(ARRAY[3, 0, 7, 2]) AS failed_logins_last_4h;
```

```text
12
```

```sql
SELECT list_sum(ARRAY[19.99, NULL, 5.01]) AS cart_total;
```

```text
25.0
```

## `list_transform(x, y)`
source: https://docs.chalk.ai/chalksql-docs#list_transform

Alias for [transform](https://docs.chalk.ai/chalksql-docs#transform).

**Examples**

```sql
SELECT list_transform(split('  Electronics , HOME_garden,Toys ', ','), t -> lower(trim(t))) AS normalized_tags;
```

```text
[electronics, home_garden, toys]
```

```sql
SELECT list_transform(ARRAY[1299, 450, 8000], cents -> cents / 100.0) AS line_item_dollars;
```

```text
[12.99, 4.5, 80.0]
```

## `list_unique(x)`
source: https://docs.chalk.ai/chalksql-docs#list_unique

Alias for [array_distinct](https://docs.chalk.ai/chalksql-docs#array_distinct).

**Examples**

```sql
SELECT list_unique(split('electronics,books,electronics,toys,books', ',')) AS purchased_categories;
```

```text
[electronics, books, toys]
```

```sql
SELECT cardinality(list_unique(ARRAY['dev-a1', 'dev-b7', 'dev-a1', 'dev-a1', 'dev-c3'])) AS distinct_devices_used;
```

```text
3
```

## `list_value(values)`
source: https://docs.chalk.ai/chalksql-docs#list_value

Alias for [array_constructor](https://docs.chalk.ai/chalksql-docs#array_constructor).

**Examples**

```sql
SELECT list_value(0.42, 1.0, 3.7) AS score_vector;
```

```text
[0.42, 1.0, 3.7]
```

```sql
SELECT cardinality(array_distinct(list_value('visa', 'mastercard', 'visa', 'amex'))) AS distinct_card_networks;
```

```text
3
```

## `ngrams(array, n)`
source: https://docs.chalk.ai/chalksql-docs#ngrams

Returns all N-grams (contiguous subsequences of length `n`) from an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT transform(ngrams(split(lower('WIRE TRANSFER INTL FEE'), ' '), 2), g -> array_join(g, ' ')) AS memo_bigrams;
```

```text
[wire transfer, transfer intl, intl fee]
```

```sql
SELECT contains(ngrams(ARRAY['login', 'reset_password', 'change_email', 'withdraw', 'logout'], 3), ARRAY['reset_password', 'change_email', 'withdraw']) AS has_takeover_pattern;
```

```text
true
```

```sql
SELECT ngrams(ARRAY['login', 'reset_password', 'change_email'], 5) AS short_session_ngrams;
```

```text
[[login, reset_password, change_email]]
```

**Overloads**

#### `ngrams(array, n)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `n`: `int32`
  The number of elements in each `n`-gram.

#### `ngrams(array, n)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `n`: `int32`
  The number of elements in each `n`-gram.

## `none_match(array, predicate)`
source: https://docs.chalk.ai/chalksql-docs#none_match

Returns true if no element of the `array` satisfies the `predicate`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Overloads**

#### `none_match(array, predicate)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

#### `none_match(array, predicate)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `predicate`: `($T) => bool`
  `T` means matching inputs and outputs use the same type.

## `python_element_at(array, index)`
source: https://docs.chalk.ai/chalksql-docs#python_element_at

Returns the element at the specified Python-style `index` in a list.

**Type parameters.** `E` is the element type of the input array or list.

**Examples**

```sql
SELECT python_element_at(split('Home > Electronics > Audio > Headphones', ' > '), -1) AS leaf_category;
```

```text
Headphones
```

```sql
SELECT python_element_at(ARRAY['login','browse','add_to_cart','checkout'], 0) AS first_event;
```

```text
login
```

**Overloads**

#### `python_element_at(array, index)`

**Parameters**

- `array`: `list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `index`: `int64`
  The `index` to read.

#### `python_element_at(array, index)`

**Parameters**

- `array`: `large_list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `index`: `int64`
  The `index` to read.

## `python_range(...)`
source: https://docs.chalk.ai/chalksql-docs#python_range

Creates a range of integers with Python-like semantics.

**Examples**

```sql
SELECT transform(python_range(0, length('STARBUCKS') - 2), i -> substr('STARBUCKS', i + 1, 3)) AS merchant_trigrams;
```

```text
[STA, TAR, ARB, RBU, BUC, UCK, CKS]
```

```sql
SELECT python_range(90, 0, -30) AS lookback_days;
```

```text
[90, 60, 30]
```

**Overloads**

#### `python_range(stop)`

**Parameters**

- `stop`: `int64`
  The ending value or index, exclusive.

#### `python_range(start, stop)`

**Parameters**

- `start`: `int64`
  The starting value or index, inclusive.
- `stop`: `int64`
  The ending value or index, exclusive.

#### `python_range(start, stop, step)`

**Parameters**

- `start`: `int64`
  The starting value or index, inclusive.
- `stop`: `int64`
  The ending value or index, exclusive.
- `step`: `int64`
  The `step` between successive values.

## `python_zip(list1, list2, ...)`
source: https://docs.chalk.ai/chalksql-docs#python_zip

Combines multiple lists element-wise into a list of paired structures with Python semantics.

**Type parameters.** `E` is the element type of the input array or list.

**Examples**

```sql
SELECT python_zip(ARRAY['groceries', 'fuel', 'dining', 'travel'], ARRAY[0.42, 0.31]) AS category_shares;
```

```text
[{f0: groceries, f1: 0.42}, {f0: fuel, f1: 0.31}]
```

```sql
SELECT transform(python_zip(ARRAY[100, 105, 98, 120], slice(ARRAY[100, 105, 98, 120], 2, 3)), p -> p.f1 - p.f0) AS balance_deltas;
```

```text
[5, -7, 22]
```

**Overloads**

#### `python_zip(list1, list2)`

**Parameters**

- `list1`: `large_list<item: $A>`
- `list2`: `large_list<item: $B>`

#### `python_zip(list1, list2, list3)`

**Parameters**

- `list1`: `large_list<item: $A>`
- `list2`: `large_list<item: $B>`
- `list3`: `large_list<item: $C>`

#### `python_zip(list1, list2, ...+2)`

**Parameters**

- `list1`: `large_list<item: $A>`
- `list2`: `large_list<item: $B>`
- `list3`: `large_list<item: $C>`
- `list4`: `large_list<item: $D>`

#### `python_zip(list1, list2, ...+3)`

**Parameters**

- `list1`: `large_list<item: $A>`
- `list2`: `large_list<item: $B>`
- `list3`: `large_list<item: $C>`
- `list4`: `large_list<item: $D>`
- `list5`: `large_list<item: $E>`
  `E` is the element type of the input array or list.

#### `python_zip(list1, list2, ...+4)`

**Parameters**

- `list1`: `large_list<item: $A>`
- `list2`: `large_list<item: $B>`
- `list3`: `large_list<item: $C>`
- `list4`: `large_list<item: $D>`
- `list5`: `large_list<item: $E>`
  `E` is the element type of the input array or list.
- `list6`: `large_list<item: $F>`

#### `python_zip(list1, list2, ...+5)`

**Parameters**

- `list1`: `large_list<item: $A>`
- `list2`: `large_list<item: $B>`
- `list3`: `large_list<item: $C>`
- `list4`: `large_list<item: $D>`
- `list5`: `large_list<item: $E>`
  `E` is the element type of the input array or list.
- `list6`: `large_list<item: $F>`
- `list7`: `large_list<item: $G>`

## `range(...)`
source: https://docs.chalk.ai/chalksql-docs#range

Alias for [python_range](https://docs.chalk.ai/chalksql-docs#python_range).

**Examples**

```sql
SELECT range(0, 25, 5) AS score_bucket_edges;
```

```text
[0, 5, 10, 15, 20]
```

```sql
SELECT transform(range(0, 30, 7), d -> date_add('day', -d, DATE '2024-03-31')) AS weekly_lookback_dates;
```

```text
[2024-03-31 00:00:00 UTC, 2024-03-24 00:00:00 UTC, 2024-03-17 00:00:00 UTC, 2024-03-10 00:00:00 UTC, 2024-03-03 00:00:00 UTC]
```

```sql
SELECT range(10, 0, -3) AS countdown;
```

```text
[10, 7, 4, 1]
```

## `reduce(array, initialState, ...+2)`
source: https://docs.chalk.ai/chalksql-docs#reduce

Alias for [array_reduce](https://docs.chalk.ai/chalksql-docs#array_reduce).

## `remove_nulls(array)`
source: https://docs.chalk.ai/chalksql-docs#remove_nulls

Removes all null values from an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT remove_nulls(ARRAY[CASE WHEN 0.92 > 0.8 THEN 'high_risk_score' END, CASE WHEN 'US' <> 'NG' THEN 'geo_mismatch' END, CASE WHEN 3 > 5 THEN 'velocity_spike' END]) AS fired_rules;
```

```text
[high_risk_score, geo_mismatch]
```

```sql
SELECT cardinality(remove_nulls(ARRAY['+1-415-555-0100', NULL, 'alice@example.com', NULL])) AS verified_contact_count;
```

```text
2
```

**Overloads**

#### `remove_nulls(array)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `remove_nulls(array)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

## `repeat(element, count)`
source: https://docs.chalk.ai/chalksql-docs#repeat

Returns an array containing the `element` repeated `count` times.

**Type parameters.** `E` is the element type of the input array or list.

**Parameters**

- `element`: `$E`
  The `element` to search for. `E` is the element type of the input array or list.
- `count`: `int32`
  The number of values to return or repeat.

**Examples**

```sql
SELECT concat(ARRAY['wire', 'refund'], repeat('<pad>', CAST(greatest(0, 4 - cardinality(ARRAY['wire', 'refund'])) AS INTEGER))) AS padded_tokens;
```

```text
[wire, refund, <pad>, <pad>]
```

## `sequence(start, stop, ...)`
source: https://docs.chalk.ai/chalksql-docs#sequence

Generates a sequence of integers with an optional `step`.

**Examples**

```sql
SELECT sequence(1, 5);
```

```text
[1, 2, 3, 4, 5]
```

**Overloads**

#### `sequence(start, stop)`

Generates a sequence of integers from `start` to `stop` (inclusive).

**Parameters**

- `start`: `int64`
  The starting value or index, inclusive.
- `stop`: `int64`
  The ending value or index, exclusive.

#### `sequence(start, stop, step)`

Generates a sequence of integers from `start` to `stop` (inclusive) with a specified `step`.

**Parameters**

- `start`: `int64`
  The starting value or index, inclusive.
- `stop`: `int64`
  The ending value or index, exclusive.
- `step`: `int64`
  The `step` between successive values.

## `shuffle(array)`
source: https://docs.chalk.ai/chalksql-docs#shuffle

Randomly shuffles the elements of an `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT slice(shuffle(ARRAY['sku_101', 'sku_202', 'sku_303', 'sku_404', 'sku_505']), 1, 2) AS sampled_recs;
```

```text
[sku_303, sku_101]
```

```sql
SELECT array_sort(shuffle(ARRAY['sku_303', 'sku_101', 'sku_505', 'sku_202'])) = array_sort(ARRAY['sku_303', 'sku_101', 'sku_505', 'sku_202']) AS is_permutation;
```

```text
true
```

**Overloads**

#### `shuffle(array)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

#### `shuffle(array)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.

## `slice(array, start, length)`
source: https://docs.chalk.ai/chalksql-docs#slice

Returns a slice of a list starting at the given position for the specified `length`.

**Type parameters.** `E` is the element type of the input array or list.

**Examples**

```sql
SELECT slice(ARRAY['login', 'view_item', 'add_to_cart', 'checkout', 'purchase'], 1, 3) AS first_three_events;
```

```text
[login, view_item, add_to_cart]
```

```sql
SELECT slice(ARRAY[120.0, 45.5, 300.0, 18.25, 999.99, 62.0], -3, 3) AS last_three_amounts;
```

```text
[18.25, 999.99, 62.0]
```

```sql
SELECT array_join(slice(split('Wireless Noise Cancelling Over-Ear Headphones with Mic', ' '), 1, 3), ' ') AS title_prefix;
```

```text
Wireless Noise Cancelling
```

**Overloads**

#### `slice(array, start, length)`

**Parameters**

- `array`: `list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `start`: `int64`
  The starting value or index, inclusive.
- `length`: `int64`

#### `slice(array, start, length)`

**Parameters**

- `array`: `large_list<item: $E>`
  The input `array` or list. `E` is the element type of the input array or list.
- `start`: `int64`
  The starting value or index, inclusive.
- `length`: `int64`

## `subscript(array, index)`
source: https://docs.chalk.ai/chalksql-docs#subscript

Returns the element at the specified 1-based `index` in the `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT subscript(split('jane.doe@acme-corp.com', '@'), 2) AS email_domain;
```

```text
acme-corp.com
```

```sql
SELECT subscript(split('/shop/electronics/audio/headphones', '/'), cardinality(split('/shop/electronics/audio/headphones', '/'))) AS leaf_category;
```

```text
headphones
```

**Overloads**

#### `subscript(array, index)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `index`: `int64`
  The `index` to read.

#### `subscript(array, index)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `index`: `int64`
  The `index` to read.

## `transform(array, function)`
source: https://docs.chalk.ai/chalksql-docs#transform

Applies a transformation `function` to each element in an `array` and returns a new `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type. `U` is a second generic value type.

**Examples**

```sql
SELECT transform(ARRAY['  AMZN Mktp US ', 'Uber *Trip', 'STARBUCKS #1234'], m -> upper(trim(m))) AS merchant_keys;
```

```text
[AMZN MKTP US, UBER *TRIP, STARBUCKS #1234]
```

```sql
SELECT transform(ARRAY[12.50, 840.00, 45.10, 2300.00], amt -> CASE WHEN amt >= 500 THEN 'high' ELSE 'normal' END) AS amount_buckets;
```

```text
[normal, high, normal, high]
```

**Overloads**

#### `transform(array, function)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `function`: `($T) => $U`
  The callback `function` applied to the elements. `T` means matching inputs and outputs use the same type. `U` is a second generic value type.

#### `transform(array, function)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `function`: `($T) => $U`
  The callback `function` applied to the elements. `T` means matching inputs and outputs use the same type. `U` is a second generic value type.

## `trim_array(array, n)`
source: https://docs.chalk.ai/chalksql-docs#trim_array

Removes the last `n` elements from the `array`.

**Type parameters.** `T` means matching inputs and outputs use the same type.

**Examples**

```sql
SELECT trim_array(ARRAY['login', 'view_cart', 'checkout', 'heartbeat', 'heartbeat'], 2) AS user_actions;
```

```text
[login, view_cart, checkout]
```

```sql
SELECT array_average(trim_array(ARRAY[120.0, 95.5, 143.0, 110.25, 18.0], 1)) AS avg_complete_day_spend;
```

```text
117.1875
```

**Overloads**

#### `trim_array(array, n)`

**Parameters**

- `array`: `list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `n`: `int64`
  The number of elements to remove from the end of the array.

#### `trim_array(array, n)`

**Parameters**

- `array`: `large_list<item: $T>`
  The input `array` or list. `T` means matching inputs and outputs use the same type.
- `n`: `int64`
  The number of elements to remove from the end of the array.

## `zip(array1, array2)`
source: https://docs.chalk.ai/chalksql-docs#zip

Combines two lists element-wise into a list of paired structures.

**Type parameters.** `T` means matching inputs and outputs use the same type. `U` is a second generic value type.

**Parameters**

- `array1`: `large_list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `large_list<item: $U>`
  The second input array. `U` is a second generic value type.

**Examples**

```sql
SELECT zip(ARRAY['amount', 'velocity', 'geo_mismatch'], ARRAY[0.42, 0.31, 0.27]) AS feature_weights;
```

```text
[{f1: amount, f2: 0.42}, {f1: velocity, f2: 0.31}, {f1: geo_mismatch, f2: 0.27}]
```

```sql
SELECT zip(ARRAY['ord_1001', 'ord_1002', 'ord_1003'], ARRAY[5, 4]) AS order_ratings;
```

```text
[{f1: ord_1001, f2: 5}, {f1: ord_1002, f2: 4}, {f1: ord_1003, f2: NULL}]
```

## `zip_with(array1, array2, function)`
source: https://docs.chalk.ai/chalksql-docs#zip_with

Combines two lists element-wise using a callback `function` to transform paired elements.

**Type parameters.** `T` means matching inputs and outputs use the same type. `U` is a second generic value type. `R` is the callback result type.

**Parameters**

- `array1`: `large_list<item: $T>`
  The first input array. `T` means matching inputs and outputs use the same type.
- `array2`: `large_list<item: $U>`
  The second input array. `U` is a second generic value type.
- `function`: `($T, $U) => $R`
  The callback `function` applied to the elements. `T` means matching inputs and outputs use the same type. `U` is a second generic value type. `R` is the callback result type.

**Examples**

```sql
SELECT zip_with(ARRAY[2, 1, 3], ARRAY[4.99, 19.50, 2.25], (qty, price) -> qty * price) AS line_totals;
```

```text
[9.98, 19.5, 6.75]
```

```sql
SELECT zip_with(ARRAY['US', 'GB', 'DE'], ARRAY['US', 'FR'], (billing, shipping) -> billing = shipping) AS country_matches;
```

```text
[true, false, NULL]
```

## `array1 && array2`
source: https://docs.chalk.ai/chalksql-docs#%26%26

operator alias for list_has_any

**Type parameters.** `E` is the element type of the input array or list.

**Examples**

```sql
SELECT split(lower('Wire transfer to Binance via Coinbase'), ' ') && ARRAY['binance','coinbase','kraken'] AS mentions_crypto_exchange;
```

```text
true
```

```sql
SELECT ARRAY['US','CA'] && ARRAY['KP','IR','SY'] AS ships_to_sanctioned_country;
```

```text
false
```

**Overloads**

#### `array1 && array2`

**Parameters**

- `array1`: `list<item: $E>`
  The first input array. `E` is the element type of the input array or list.
- `array2`: `list<item: $E>`
  The second input array. `E` is the element type of the input array or list.

#### `array1 && array2`

**Parameters**

- `array1`: `large_list<item: $E>`
  The first input array. `E` is the element type of the input array or list.
- `array2`: `large_list<item: $E>`
  The second input array. `E` is the element type of the input array or list.
