All Products
Search
Document Center

Hologres:Set returning functions

Last Updated:Mar 26, 2026

Hologres supports a subset of PostgreSQL set-returning functions. These functions expand a single call into a set of rows, making them useful for generating sequences and array subscripts inline in SQL queries.

For the full PostgreSQL specification, see Set Returning Functions in the PostgreSQL documentation.

Supported functions

FunctionArgument typesReturn typeDescription
GENERATE_SERIES(start, stop [, step])INT, BIGINT, or NUMERICsetof INT, BIGINT, or NUMERICGenerates a numeric sequence from start to stop.
GENERATE_SERIES(start, stop, step INTERVAL)TIMESTAMP or TIMESTAMP WITH TIME ZONEsetof TIMESTAMP or TIMESTAMP WITH TIME ZONEGenerates a timestamp sequence from start to stop.
GENERATE_SUBSCRIPTS(anyarray, dim)Any array type, INTsetof INTGenerates the valid subscripts for one dimension of an array.

GENERATE_SERIES

Generates a sequence of values from start to stop, stepping by step. Both start and stop are inclusive.

Signatures

GENERATE_SERIES(start, stop [, step])            -- numeric sequence
GENERATE_SERIES(start, stop, step INTERVAL)      -- timestamp sequence

Numeric sequence

Generates a sequence of INT, BIGINT, or NUMERIC values.

Parameters

ParameterRequiredData typeDescription
startYesINT, BIGINT, or NUMERICThe first value in the sequence.
stopYesINT, BIGINT, or NUMERICThe last value in the sequence (inclusive).
stepNoINT, BIGINT, or NUMERICThe increment between values. Defaults to 1.

Return type: A set of values with the same data type as the input parameters.

Examples

Ascending sequence with the default step:

SELECT GENERATE_SERIES(2, 4);
 generate_series
-----------------
               2
               3
               4

Descending sequence with a negative step:

SELECT GENERATE_SERIES(5, 1, -2);
 generate_series
-----------------
               5
               3
               1

Timestamp sequence

Generates a sequence of TIMESTAMP or TIMESTAMP WITH TIME ZONE values.

Parameters

ParameterRequiredData typeDescription
startYesTIMESTAMP or TIMESTAMP WITH TIME ZONEThe first value in the sequence.
stopYesTIMESTAMP or TIMESTAMP WITH TIME ZONEThe last value in the sequence (inclusive).
stepYesINTERVALThe time interval between values.

Return type: A set of values with the same data type as the input parameters.

Example

SELECT GENERATE_SERIES('2024-10-01 00:00'::timestamp, '2024-10-01 12:00', '10 hours');
   generate_series
---------------------
 2024-10-01 00:00:00
 2024-10-01 10:00:00

GENERATE_SUBSCRIPTS

Generates the valid subscripts for a given dimension of an array. Use this function to iterate over array elements by index.

Signature

GENERATE_SUBSCRIPTS(anyarray, dim)

Parameters

ParameterRequiredData typeDescription
anyarrayYesAny array typeA multidimensional array of any type whose subscripts are generated.
dimYesINTThe dimension of the array to generate subscripts for.

Return type: A set of integers representing the valid subscripts.

Example

SELECT GENERATE_SUBSCRIPTS('{NULL,1,NULL,2}'::int[], 1);
 generate_subscripts
---------------------
                   1
                   2
                   3
                   4