---
schema_version: "1"
id: 3e10eb362157fe951f375039ead4e4c1046eab45d6b5d4a6408df160b9507d3e
title: TRIM_ARRAY
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/references/data-cloud-sql-reference/scalar-func/array-func/trim-array.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/trim-array.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 1053fe18f2c5bd3e0b0af9ee48afc2338ca895f56ffb19ed25a340a73236ef7d
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# `TRIM_ARRAY`

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Trims an array by removing the last `n` elements.

## Syntax

```sql
trim_array(<array>, <count>)
```

## Arguments

### Required

- `<array>`: The source array.
- `<count>`: The number of elements to remove from the end.

## Returns

Returns an array with the specified number of elements removed from the end.

## Considerations

- If the count exceeds the array length, returns an empty array.
- The count must be a non-negative integer.

## Examples

### Trim Last Elements

Remove the last two elements from an array.

```sql
SELECT trim_array(array[1, 2, 3, 4], 2) AS result;
```

Returns `array[1, 2]`, removing the last 2 elements (3 and 4).

## Related Documentation

- [Array Data Type](https://developer.salesforce.com/docs/data/data-cloud-query-guide/datatype/array.md)
