📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

ARRAY_GENERATE_RANGE



Builds an array of evenly spaced integers between a start and end value. The end bound is exclusive.

Syntax

ARRAY_GENERATE_RANGE(<start>, <end>[, <step>])
  • <start>: First value to include.
  • <end>: Exclusive upper (or lower) bound.
  • <step>: Optional increment (default 1). Negative steps produce descending sequences.

Return Type

ARRAY

Examples

SELECT ARRAY_GENERATE_RANGE(1, 5) AS seq; ┌──────────┐ │ seq │ ├──────────┤ │ [1,2,3,4]│ └──────────┘
SELECT ARRAY_GENERATE_RANGE(0, 6, 2) AS seq_step; ┌────────────┐ │ seq_step │ ├────────────┤ │ [0,2,4] │ └────────────┘
SELECT ARRAY_GENERATE_RANGE(5, 0, -2) AS seq_down; ┌────────────┐ │ seq_down │ ├────────────┤ │ [5,3,1] │ └────────────┘

Was this page helpful?