ARRAY_GENERATE_SERIES (Numerical)

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Creates an array of sequential values within a range.

  • <start>: The starting value of the sequence.
  • <stop>: The ending value of the sequence (inclusive).
  • <step>: The increment between values. The default is 1.

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

  • 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) 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.

Create an array of integers from 1 to 5.

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

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

Returns [1, 3, 5].

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

Returns [5, 3, 1].

Create a descending array with decimal values.

Returns [3.7, 3.4, 3.1].

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

Returns [].

The examples in generate_series examples apply to array_generate_series.