> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SEQUENCE

> Builds an inclusive integer, date or timestamp sequence.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

Returns NULL for a typed NULL endpoint or a supplied typed NULL step. Omitting step uses the default for the sequence’s direction. An untyped NULL step is rejected; cast NULL to the required numeric or interval type if needed.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
sequence(start, stop [, step])
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| start | INTEGER, DATE or TIMESTAMP | Yes | Start value. |
| stop | Same type as start | Yes | Inclusive upper/lower bound. |
| step | INTEGER for numeric; INTERVAL for temporal | No | Increment. Must be nonzero and advance toward stop. For DATE inputs, use whole month/day increments with components of the same sign; sub-day-only or mixed-sign steps are unsafe. Default: +1/-1 for numeric; +1/-1 day for temporal, following direction. |

## Returns

* Type: ARRAY\<BIGINT>, ARRAY\<DATE> or ARRAY\<TIMESTAMP>
* Possible values: Values from start toward stop, including stop when reached exactly.
* NULL behavior: Returns NULL for a typed NULL endpoint or a supplied typed NULL step. Omitting step uses the default for the sequence’s direction. An untyped NULL step is rejected; cast NULL to the required numeric or interval type if needed.
* Shape: One element per increment that remains within the inclusive endpoint.
* Ordering: Increment direction.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* Bounds are converted to a compatible integer or date/time type. Integer sequences return BIGINT elements even when query tools report a narrower ARRAY element type.
* Temporal steps add calendar months first, adjusting an invalid day to the last day of the month, then days, then the time component for TIMESTAMP. Fractions below a microsecond are discarded. TIMESTAMP values use microsecond precision with no time zone or UTC.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT sequence(1, 7, 2) AS "value";
```

| value |
| - |
| \[1,3,5,7] |

### Generate a descending sequence

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT sequence(5, 1, -2) AS values_desc;
```

| values\_desc |
| - |
| \[5,3,1] |

## Limitations

* Zero step or a step directed away from stop raises an error.
* Very large sequences require large allocations; numeric endpoint subtraction is unchecked.
* DATE steps ignore the interval nanosecond component. A sub-day-only DATE step or a mixed-sign calendar step that does not advance toward stop can fail to terminate. Use nonzero month/day DATE increments and steps that consistently advance toward stop.
* The source checks interval direction lexicographically by first nonzero months, then days, then nanoseconds. That direction check does not prove a mixed-component step actually advances.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.