ARRAY_GENERATE_RANGE
functionsupportedCore SQL functionsReturns an ARRAY of integer values within a specified range (e.g. [2, 3, 4]).
Syntax
supportedpartialnot supportednot scored
ARRAY_GENERATE_RANGE( <start> , <stop> [ , <step> ] )
Parameters
| Name | Required | Description |
|---|---|---|
start | required | The first number in the range of numbers to return. You must specify an expression that evaluates to an INTEGER value. |
stop | required | The last number in the range. Note that this number is not included in the range of numbers returned. For example, ARRAY_GENERATE_RANGE(1, 5) returns [1, 2, 3, 4] (which does not include 5). You must specify an expression that evaluates to an INTEGER value. |
step | optional | The amount to increment or decrement each subsequent number in the array. For example: ARRAY_GENERATE_RANGE(0, 16, 5) returns [0, 5, 10, 15] ARRAY_GENERATE_RANGE(0, -16, -5) returns [0, -5, -10, -15] You can specify a positive or negative number. You cannot specify 0. The default value is 1. |
Returns
An ARRAY of integers in the specified range. If any of the arguments is NULL, the function returns NULL.
Usage notes
- After start, each subsequent element increases or decreases by step (depending on whether step is positive or negative) up to (but not including) stop. For example: ARRAY_GENERATE_RANGE(10, 50, 10) returns [10, 20, 30, 40].
- ARRAY_GENERATE_RANGE(-10, -50, -10) returns [-10, -20, -30, -40].
- The function returns an empty ARRAY under any of the following conditions: start = stop.
- step is a positive number and start > stop.
- step is a negative number and start < stop.
- For example:
- ARRAY_GENERATE_RANGE(2, 2, 4) returns [].
- ARRAY_GENERATE_RANGE(8, 2, 2) returns [].
- ARRAY_GENERATE_RANGE(2, 8, -2) returns [].