# `ARRAY_GENERATE_SERIES` (Numerical)

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Creates an array of sequential values within a range.

## Syntax

```sql
array_generate_series(<start>, <stop>[, <step>])
```

## Arguments

### Required

- `<start>`: The starting value of the sequence.
- `<stop>`: The ending value of the sequence (inclusive).

### Optional

- `<step>`: The increment between values. The default is 1.

## Returns

Returns an array that contains sequential values from `start` to `stop`, incrementing by `step`.

## Considerations

- If you use a negative step, make sure `<start>` is greater than `<stop>`. If `<start>` is less than or equal to `<stop>`, the function returns an empty array.
- A negative step generates a descending sequence. A positive step generates an ascending sequence.
- This function is equivalent to the [generate_series (Numerical)](/docs/data/data-cloud-query-guide/references/dc-sql-reference/generate-series.md) function but returns an array instead of a set of rows.
- Both the `start` and `stop` values are included in the generated series.
- The step size must be non-zero.
- The step size can also be negative. For negative step sizes, `start` must be greater than `stop`.
- For positive step sizes, if `start` is greater than `stop`, the function returns no rows.
- For negative step sizes, if `start` is less than `stop`, the function returns no rows.
- If any input is `null`, the function returns no rows.

## Examples

### Basic Usage

Create an array of integers from 1 to 5.

```sql
SELECT array_generate_series(1, 5) AS result;
```

Returns `[1, 2, 3, 4, 5]`.

### Generate Sequence with Step

Create an array of integers from 1 to 5 with step 2.

```sql
SELECT array_generate_series(1, 5, 2) AS result;
```

Returns `[1, 3, 5]`.

### Reverse Sequence with Negative Step

Create an array counting down from 5 to 1 in increments of 2.

```sql
SELECT array_generate_series(5, 1, -2) AS result;
```

Returns `[5, 3, 1]`.

### Decimal Reverse Sequence

Create a descending array with decimal values.

```sql
SELECT array_generate_series(3.7, 3.0, -0.3) AS result;
```

Returns `[3.7, 3.4, 3.1]`.

### Negative Step with Increasing Range (Empty Result)

When the step direction doesn't match the range direction, an empty array is returned.

```sql
SELECT array_generate_series(1, 5, -1) AS result;
```

Returns `[]`.

### Additional Examples

The examples in [generate_series examples](/docs/data/data-cloud-query-guide/references/dc-sql-reference/generate-series.md#examples) apply to `array_generate_series`.

## Related Documentation

- [Array Data Type](/docs/data/data-cloud-query-guide/references/dc-sql-reference/array.md)
- [`ARRAY_GENERATE_SERIES` (Time-based)](/docs/data/data-cloud-query-guide/references/dc-sql-reference/array-generate-series-time.md) - the time-based version of this function
- [`generate_series` (Numerical)](/docs/data/data-cloud-query-guide/references/dc-sql-reference/generate-series.md) - the set-returning version of this function
