---
title: slice function
description: Learn the syntax of the slice function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/slice
---

# `slice` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns a subset of an array.

## Syntax

```
slice(expr, start, length)
```

## Arguments

* `expr`: An `ARRAY` expression.
* `start`: An `INTEGER` expression.
* `length`: An `INTEGER` expression that is greater or equal to 0.

## Returns

The result is of the type of `expr`.

The function subsets array `expr` starting from index `start` (array indices start at 1), or starting from the end if `start` is negative, with the specified `length`.
If the requested array slice does not overlap with the actual length of the array, an empty array is returned.

Databricks raises [INVALID\_PARAMETER\_VALUE](https://docs.databricks.com/aws/en/error-messages/invalid-parameter-value-error-class.md) if `start` is 0 or `length` is negative.

## Common error conditions

* [INVALID\_PARAMETER\_VALUE](https://docs.databricks.com/aws/en/error-messages/invalid-parameter-value-error-class.md)

## Examples

```sql
> SELECT slice(array(1, 2, 3, 4), 2, 2);
 [2,3]
> SELECT slice(array(1, 2, 3, 4), -2, 2);
 [3,4]

> SELECT slice(array(1, 2, 3), 0, 1);
  Error: INVALID_PARAMETER_VALUE.START
```

## Related functions

* [`array` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array.md)
