The Snowflake GENERATOR function is a powerful tool for creating synthetic rows of data based on a specified number of rows, a specified generation period, or both. This system-defined table function enables users to generate virtual tables with a specified number of rows, which can be useful for queries that require a large amount of data.
The syntax for the GENERATOR function is as follows:
GENERATOR(ROWCOUNT => <count> [ , TIMELIMIT => <sec> ] )
GENERATOR( [ TIMELIMIT => <sec> ] )
The ROWCOUNT
and TIMELIMIT
parameters are non-negative integer constants. If only ROWCOUNT
is specified, the resulting table will contain the specified number of rows. If only TIMELIMIT
is specified, the query will run for the specified number of seconds, generating as many rows as possible within the time frame.
ROWCOUNT
and TIMELIMIT
are specified, the function will generate rows until either the row count is reached or the time limit is exceeded.ROWCOUNT
or TIMELIMIT
is null, it will be ignored.The following examples demonstrate how to use the GENERATOR function to generate synthetic rows of data.
SELECT seq4(), uniform(1, 10, RANDOM(12))
FROM TABLE(GENERATOR(ROWCOUNT => 10)) v
ORDER BY 1;
This query generates 10 rows with a sequence of 4-byte integers and a random value between 1 and 10.
SELECT seq4(), uniform(1, 10, 42)
FROM TABLE(GENERATOR(ROWCOUNT => 10)) v
ORDER BY 1;
This query generates 10 rows with a sequence of 4-byte integers and a constant value of 10.
SELECT seq4(), uniform(1, 10, RANDOM(12))
FROM TABLE(GENERATOR()) v
ORDER BY 1;
This query returns 0 rows because both ROWCOUNT
and TIMELIMIT
are omitted.
SELECT COUNT(seq4())
FROM TABLE(GENERATOR(TIMELIMIT => 10)) v;
This query generates rows for 10 seconds and returns the count of rows generated.
The Snowflake GENERATOR function is a powerful tool for generating synthetic rows of data. By understanding the syntax and usage notes, users can leverage this function to create virtual tables with a specified number of rows, which can be useful for a variety of use cases. For more information on the GENERATOR function and other Snowflake features, visit the Snowflake documentation.
To learn more about Snowflake and its features, check out the following resources: