SAMPLE clause
Description
The SAMPLE clause in Teradata reduces the number of rows to be processed and it returns one or more samples of rows as a list of fractions or as a list of numbers of rows. The clause is used in the SELECT query. Please review the following Teradata documentation for more information.
Teradata syntax
Snowflake syntax
Review the following Snowflake documentation for more information. SAMPLE
and TABLESAMPLE
are synonymous.
Where:
In Snowflake, the following keywords can be used interchangeably:
SAMPLE | TABLESAMPLE
BERNOULLI | ROW
SYSTEM | BLOCK
REPEATABLE | SEED
Review the following table to check on key differences.
Sample by probability
Also known as fraction description. It must be a fractional number between 0,1 and 1.
Decimal number between 0 and 100.
Fixed number of rows
Also known as count description. It is a positive integer that determines the number of rows to be sampled.
It specifies the number of rows (up to 1,000,000) to sample from the table. Can be any integer between 0
(no rows selected) and 1000000
inclusive.
Repeated rows
It is known as WITH REPLACEMENT.
This is used to query more samples than there are rows in the table.
It is known as REPEATABLE
or SEED
. This is used to make the query deterministic. It means that the same set of rows will be the same for each query run.
Sampling methods
Proportional and RANDOMIZED ALLOCATION.
BERNOULLI
or SYSTEM
.
Sample Source Patterns
Sample data
Teradata
Snowflake
SAMPLE clause
Fixed number of rows
Notice that for this example, the number of rows are a fixed number but not necessarily are the same result for each run.
Teradata
Snowflake
Rows number based on probability
This option will return a variety of rows depending on the probability set.
Teradata
Snowflake
Known Issues
Fixed number of rows with replacement
This option will return a fixed number of rows and will allows the repetition of the rows. In Snowflake, it is not possible to request more samples than rows in a table.
Teradata sample
SAMPLEID related functionality
In Teradata, it is possible to assign a unique ID to each sample that is specified. It helps to identify which belongs to which sample. This is not ANSI grammar, instead it is an extension of Teradata.
Teradata sample
In Snowflake, there is not a SAMPLEID function. A possible workaround may be the following, but it has to be adaptaed to each single case:
Snowflake possible workaround
Conditional sampling
In Snowflake there is not conditional sampling. This can be achieve by using CTE's.
Teradata sample
Related EWIs
SSC-EWI-0021: Syntax not supported in Snowflake.
Last updated