RESAMPLE

constructsupportedQueries & DMLpreview

docs.snowflake.com ↗

Returns a data set that includes both input rows and generated rows for missing data points, given a user-defined time-based granularity.

Syntax

supportedpartialnot supportednot scored

FROM <object_reference> [ [ AS ] <alias_name> ]
  RESAMPLE(
    USING <time_series_column>
    INCREMENT BY <time_series_constant>
    [ PARTITION BY <partition_column> [ , ... ] ]
    [ METADATA_COLUMNS
        { IS_GENERATED() | BUCKET_START() } [ [ AS ] <alias_name> ] [ , ... ] ]
    )

Parameters

NameRequiredDescription
FROM object_referencerequiredSpecifies the name of a table or another object reference that contains the input data set, such as a subquery. For more information about object references, see FROM.
USING time_series_columnrequiredSpecifies the column that contains time-based values in the time series. The column must be a date and time data type or a numeric data type. For example, UNIX timestamp values might be stored in NUMBER(38,0) columns, where 1743447600 is equivalent to 2025-3-31 12:00:00.
INCREMENT BY time_series_constantrequiredSpecifies an INTERVAL constant or a numeric constant, depending on the data type of the USING column. This constant represents the width of each time interval. The slices are aligned relative to midnight on January 1, 1970 (1970-01-01 00:00:00). The TIME_SLICE function uses the same alignment; for more information, see the TIME_SLICE usage notes. When the USING parameter specifies a date or time column, the INCREMENT BY expression must be an INTERVAL constant. When the USING parameter specifies a numeric column, the INCREMENT BY expression must also be numeric. The starting point for a generated time series is based on the minimum time of the time_series_constant. If this constant is a numeric constant, it must be positive (greater than 0).
[ AS ] alias_nameoptionalSpecifies an alternative name for the object reference. The alias can be used in any other subclause within the FROM clause. Alias names must follow the rules for Object identifiers.
PARTITION BY partition_columnoptionalPartitions the result set on one or more input columns and generates new rows within each partition.
METADATA_COLUMNS {function} [ [ AS ] {alias_name} ]optionalAdds one or more metadata columns to the resampled result set. To add the columns, call one or both of the following functions: If you specify both metadata columns, separate them with a comma. Generated columns can have aliases. Alias names must follow the rules for Object identifiers.
  • IS_GENERATED() — Adds an is_generated column to the result set that marks which rows are new (generated by the RESAMPLE operation) and which rows already existed.
  • BUCKET_START() — Adds a bucket_start column to the result set. This column returns the value that marks the beginning of the current bucket or interval that the RESAMPLE operation produces, based on the values in the column specified in the USING clause. You can use the BUCKET_START column to identify which interval a particular row belongs to after resampling.

Usage notes