What you will be able to do
- Generate a chosen number of rows with TABLE(GENERATOR(ROWCOUNT => n)) and fill them with SEQ, UNIFORM and RANDOM
- Explain why SEQ values can have gaps and produce a gap-free ID with ROW_NUMBER
- Call GENERATE_SYNTHETIC_DATA to make a statistically similar copy of a sensitive table, with join keys that stay consistent
- State the procedure's input limits, the privacy filter's NULL rule and the privileges it needs
1.Synthetic rows from nothing with GENERATOR
Synthetic data is data you make instead of collecting it. Typical uses are test rows for a pipeline that has no real input yet, volume for a load test, or a shareable stand-in for records too sensitive to hand over. Snowflake offers two routes. The data generation functions build rows from nothing, with values you describe. The GENERATE_SYNTHETIC_DATA procedure builds a statistically similar copy of a real table.
GENERATOR is a system table function that creates rows and nothing else. TABLE(GENERATOR(ROWCOUNT => n)) returns n rows with no columns of their own. The functions in your SELECT list supply all the content. TIMELIMIT => sec instead generates as many rows as it can in that many seconds, so the row count depends on system speed. If you pass neither parameter, you get zero rows.
SELECT seq4(), uniform(1, 10, RANDOM(12)) FROM TABLE(GENERATOR(ROWCOUNT => 10)) v ORDER BY 1;Three function families fill those rows:
SEQ1,SEQ2,SEQ4andSEQ8return increasing integers 1, 2, 4 or 8 bytes wide, starting at 0. They wrap around after the largest integer that width can hold, soSEQ1cannot number more than a few hundred rows without repeating.RANDOMreturns pseudo-random 64-bit integers. An optional seed, as inRANDOM(12), makes the sequence repeatable.UNIFORM(min, max, gen)returns a uniformly distributed number in the inclusive range [min, max], drawn from the expressiongen, which is usuallyRANDOM(). It returns an integer when both bounds are integers and a float when either bound is a float.
The third argument to UNIFORM is the source of randomness, not a seed. Pass RANDOM() for values that differ on every run. Pass RANDOM(12) for values that differ by row but repeat on every run, which makes test results comparable between runs.
SEQ functions give unique, increasing integers, which makes them the usual ID column for generated rows. They do not promise a run without gaps: on large volumes, gaps can appear. If an ID must run 1, 2, 3 … with nothing missing, number the rows with ROW_NUMBER() OVER (ORDER BY seq4()), a window function from Snowflake's function categories.
SELECT ROW_NUMBER() OVER (ORDER BY seq4()) FROM TABLE(generator(rowcount => 10));Combined, these functions fill a realistic test table in one statement. Indexing into an ARRAY_CONSTRUCT list with a UNIFORM value picks a category at random, such as one of five flavours.
INSERT INTO icecream_orders
SELECT
SEQ4() AS ID,
UNIFORM(1, 100, RANDOM()) AS STORE_ID,
ARRAY_CONSTRUCT('VANILLA','CHOCOLATE','STRAWBERRY','MANGO','PISTACHIO')
[UNIFORM(0,4,RANDOM())]::STRING AS FLAVOR,
UNIFORM(1, 5, RANDOM()) AS NUM_SCOOPS
FROM TABLE(GENERATOR(ROWCOUNT => 10000));Checkpoint 1 of 3· Check yourself
A data engineer is building a new ingestion pipeline. No real source data exists yet, and they need 10,000 test rows with an ID, a store number and a random flavour. Which approach fits?
GENERATE_SYNTHETIC_DATA makes a statistically similar copy of an existing table, so it needs real source data. GENERATOR creates rows from nothing, but those rows have no columns of their own. The SEQ, RANDOM and UNIFORM functions in the SELECT list supply the values.
“Snowflake can generate synthetic data from a source table, producing a table with the same number of columns as the source table”Source: docs.snowflake.com
2.Synthetic copies of real tables with GENERATE_SYNTHETIC_DATA
Random ranges are not enough when test data has to behave like production, with the same distributions and the same correlations between columns. SNOWFLAKE.DATA_PRIVACY.GENERATE_SYNTHETIC_DATA is a stored procedure that reads one or more source tables and writes output tables filled with statistically similar artificial data. Each output table has the same number of columns as its source, with the same names and data types, and the same number of rows or fewer. The synthetic rows match the source statistically but have no direct link to any source row. That is what makes them safe to share with testers or partners who must not see the original. The synthetic tables also appear in the data lineage graph, and the role that calls the procedure owns them.
| Column kind | How it is recognised | What the output contains |
|---|---|---|
| Statistical | Number, boolean, date, time or timestamp | Same type, with values similar to the source |
| Categorical string | Fewer unique values than half the row count | Actual values taken from the source |
| Non-categorical string | More unique values than half the row count | Redacted, unless you set an output format with the replace option |
| Join key | Designated with join_key | Consistent but artificial values of the same type |
The redaction rule catches people out. A column of email addresses or free-text notes is almost all unique values, so it comes back redacted unless you ask for replacement values. You can override the automatic choice by marking a non-join-key string column as categorical or non-categorical.
Join keys keep a multi-table copy usable. Mark every column you will join on with 'join_key': TRUE, and give that column identical arguments in every dataset object. Within one run, the same source value then becomes the same synthetic value in every table, so joins return results similar to the source. To keep the values consistent across separate runs, create a symmetric-key SECRET and pass it as consistency_secret. This works only for string columns and requires READ or OWNERSHIP on the secret.
CALL SNOWFLAKE.DATA_PRIVACY.GENERATE_SYNTHETIC_DATA({
'datasets':[
{
'input_table': 'CLINICAL_DB.PUBLIC.PATIENTS1',
'output_table': 'MY_DB.PUBLIC.PATIENTS1',
'columns': { 'patient_id': {'join_key': TRUE}, 'age':{'join_key': TRUE}}
},
{
'input_table': 'CLINICAL_DB.PUBLIC.PATIENTS2',
'output_table': 'MY_DB.PUBLIC.PATIENTS2',
'columns': { 'patient_id': {'join_key': TRUE}, 'age':{'join_key': TRUE}}
}
],
'replace_output_tables': TRUE
});Checkpoint 2 of 3· Match them up
You run GENERATE_SYNTHETIC_DATA on a 10,000-row CUSTOMERS table with default settings, except where a column's description says otherwise. Match each source column to what its output column contains.
Tap a term, then the definition that fits it.
Number, boolean, date and time columns keep their type and get similar values. A string column with fewer unique values than half the row count is categorical, so the output reuses real source values. A string column with more unique values than half the row count is redacted unless you set a replace output format. Join keys get artificial values that stay consistent, so joins between the output tables still work.
“Non-categorical string: A string column with many unique values‡. Redacted in the output unless you specify an output format with the replace option”Source: docs.snowflake.com
Sources4
3.Input limits, the privacy filter and required privileges
The procedure accepts tables and views as sources, up to five per call. Supported sources are regular, temporary, dynamic and transient tables, and regular, materialized, secure and secure materialized views. External tables, Apache Iceberg tables, hybrid tables and streams are not supported. Each input must meet these limits:
- at least 20 distinct rows
- at most 100 columns
- at most 14M rows
An unsupported column type does not make the call fail. The column comes back as NULL in every row, which is easy to miss in a wide table. TIMESTAMP_TZ is not among the supported date and time types. Source timestamps earlier than 1677-09-21 or later than 2262-04-11 are coerced to the nearest of those boundaries.
Setting 'similarity_filter': True adds a privacy filter. It removes output rows that are too similar to the input, judged by the nearest neighbor distance ratio (NNDR) and the distance to closest record (DCR). This filter is why the output can have fewer rows than the source. It also has a strict requirement: every non-string column must have a value in every row. A single NULL in a numeric or date column makes the procedure fail, so fill or exclude those values before you switch the filter on.
Every user can call the procedure, because the SNOWFLAKE.CORE_VIEWER database role that grants access is granted to PUBLIC. The calling role also needs:
- USAGE on the warehouse
- SELECT on the input table
- USAGE on the input database and schema, and on the output database
- CREATE TABLE on the output schema
- OWNERSHIP of the output tables
The account must also have accepted the Anaconda terms and conditions. Watch for a future grant of ownership on the output schema. It silently overrides who owns the generated tables.
Checkpoint 3 of 3· Check yourself
Table SALES has 50,000 rows. Its DISCOUNT_PCT column is a NUMBER, and 300 rows hold NULL there. You call GENERATE_SYNTHETIC_DATA on SALES with 'similarity_filter': True. What happens?
With the similarity filter on, every non-string column must have a value in every row, so one NULL in a numeric column makes the whole call fail. You need to fill or exclude those NULLs before you turn the filter on. A column that comes back all NULL is what happens with an unsupported column type, which is a different case.
“A NULL value in a non-string column will cause the procedure to fail.”Source: docs.snowflake.com
Sources4
Practise it for real
Generate synthetic rows with GENERATOR and see how row count, randomness and gap-free numbering each behave
1.Run SELECT seq4(), uniform(1, 10, RANDOM(12)) FROM TABLE(GENERATOR(ROWCOUNT => 10)) v ORDER BY 1; twice.
Why: Shows that GENERATOR supplies only the row count while the SELECT-list functions supply the content, and that a seeded RANDOM repeats.
You should see: Ten rows with SEQ4 running 0 to 9 and values between 1 and 10. The second run returns the same values.
2.Replace RANDOM(12) with the constant 42 and run the query again.
Why: Shows that the third UNIFORM argument is the source of randomness, not a seed.
You should see: The UNIFORM column shows the same value on all ten rows.
3.Remove ROWCOUNT so the FROM clause reads TABLE(GENERATOR()).
Why: Confirms what happens when neither ROWCOUNT nor TIMELIMIT is given.
You should see: The query returns zero rows.
4.Run SELECT ROW_NUMBER() OVER (ORDER BY seq4()) FROM TABLE(generator(rowcount => 10));
Why: Builds a numbering that never has gaps, unlike SEQ4 on large volumes.
You should see: Ten rows numbered 1 to 10.
Stuck? Get a nudge
If the UNIFORM values look identical on every row, check whether the third argument is a constant instead of a RANDOM call.
Sources
(4)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“This system-defined table function enables synthetic row generation.”
↩︎ Synthetic rows from nothing with GENERATOR“The content of the rows is determined by the functions in the projection clause, not by the GENERATOR function itself.”
↩︎ Synthetic rows from nothing with GENERATOR“If both parameters (ROWCOUNT and TIMELIMIT) are omitted, the GENERATOR function returns 0 rows.”
↩︎ Synthetic rows from nothing with GENERATOR - 2.
“Wrap-around occurs after the largest representable integer of the integer width (1, 2, 4, or 8 byte).”
↩︎ Synthetic rows from nothing with GENERATOR“When operating on a large quantity of data, gaps can appear in a sequence.”
↩︎ Exam trap 1 - 3.
“It accepts an optional seed that allows sequences to be repeated.”
↩︎ Synthetic rows from nothing with GENERATOR“if the gen argument is a constant, then the output is a constant”
↩︎ Prediction - 4.
“The output tables have the same number of columns as the input tables, with the same column names and data types.”
↩︎ Synthetic copies of real tables with GENERATE_SYNTHETIC_DATA“but does not have a direct reference or link to any row from the original data.”
↩︎ Synthetic copies of real tables with GENERATE_SYNTHETIC_DATA“If you provide a symmetric string secret to consistency_secret in GENERATE_SYNTHETIC_DATA, join key values will be consistent across tables and multiple runs.”
↩︎ Synthetic copies of real tables with GENERATE_SYNTHETIC_DATA“You can specify up to five input tables per procedure call.”
↩︎ Input limits, the privacy filter and required privileges“Columns of an unsupported data type return NULL for all values in the column.”
↩︎ Input limits, the privacy filter and required privileges“The privacy filter removes rows from the output table if the rows are too similar to the input data set.”
↩︎ Input limits, the privacy filter and required privileges“You must accept the Anaconda terms and conditions in your Snowflake account in order to enable this feature.”
↩︎ Input limits, the privacy filter and required privileges“Redacted in the output unless you specify an output format with the replace option in GENERATE_SYNTHETIC_DATA.”
↩︎ Exam trap 2“A NULL value in a non-string column will cause the procedure to fail.”
↩︎ Exam trap 3“Snowflake can generate synthetic data from a source table, producing a table with the same number of columns as the source table”
↩︎ Checkpoint“Non-categorical string: A string column with many unique values‡. Redacted in the output unless you specify an output format with the replace option”
↩︎ Checkpoint“A NULL value in a non-string column will cause the procedure to fail.”
↩︎ Checkpoint