- Lag Generator Functions — Create individual lag feature columns.
- Vector Assembler Functions — Group generated lag columns into vectors.
- Simple Linear Regression (univariate forecasting with lag inputs)
- Multiple Linear Regression (multivariate regression with lagged predictors)
- Polynomial Regression (regression with higher-order lagged terms)
- Linear Combination Regression (custom functions of lagged inputs)
- Nonlinear Regression (arbitrary functions that include lag variables)
- Feedforward Neural Networks (lagged features as input vectors)
- Vector Autoregression (VAR) (multivariate time series with structured lag vectors)
- Autoregression (univariate time series modeled through lagged values)
- Vector Valued Regression (multivariate dependent variables with lagged inputs)
Lag Generator Functions
Lag generator functions provide options for creating lagged columns for one or more variables in a single statement. These functions follow the syntax rules of window aggregate functions as they define the window for the lag computation with anOVER and ORDER BY clause. For details, see Window Aggregate Functions.
The window parameters of lag generator functions are represented in these examples by <window_specification>.
LAGS
Generates a series of lagged columns for a single variable in one statement. This function simplifies univariate time-series feature creation. SyntaxSQL
| Argument | Type | Description |
|---|---|---|
expression | ANY | The column or expression to lag. |
start_lag | INTEGER | First lag to generate. This value must be less than the end_lag value. |
end_lag | INTEGER | Last lag to generate. This value must be greater than the start_lag value. |
step | INTEGER | Optional. Defines the gap between successive lags. Must be a positive integer. If unspecified, this value defaults to 1. |
sales_lag1, sales_lag2, sales_lag3) from the sales column.
SQL
SQL
LAGS_ZEROFILL
Generates lagged columns for a single variable and replaces NULL values with0.
Syntax
SQL
| Argument | Type | Description |
|---|---|---|
expression | ANY | The column or expression to lag. |
start_lag | INTEGER | First lag to generate. This value must be less than the end_lag value. |
end_lag | INTEGER | Last lag to generate. This value must be greater than the start_lag value. |
step | INTEGER | Optional. Defines the gap between successive lags. Must be a positive integer. If unspecified, this value defaults to 1. |
SQL
SQL
MULTI_LAGS
Generates lagged columns for multiple variables at once. This function is intended primarily for creating features for multivariate time-series models. SyntaxSQL
| Argument | Type | Description |
|---|---|---|
expr1, expr2, [ ,... ] | ANY | One or more columns or expressions to lag. Applies the same lag range and step to each input. |
start_lag | INTEGER | First lag to generate. This value must be less than the end_lag value. |
end_lag | INTEGER | Last lag to generate. This value must be greater than the start_lag value. |
step | INTEGER | Optional. Defines the gap between successive lags. Must be a positive integer. If unspecified, this value defaults to 1. |
interest_rate and gdp_growth.
SQL
SQL
MULTI_LAGS_ZEROFILL
Generates lagged columns for multiple variables and replaces NULL values with0.
Syntax
SQL
| Argument | Type | Description |
|---|---|---|
expr1, expr2, [ ,... ] | ANY | One or more columns or expressions to lag. Applies the same lag range and step to each input. |
start_lag | INTEGER | First lag to generate. This value must be less than the end_lag value. |
end_lag | INTEGER | Last lag to generate. This value must be greater than the start_lag value. |
step | INTEGER | Optional. Defines the gap between successive lags. Must be a positive integer. If unspecified, this value defaults to 1. |
x1, x2, and x3, replacing missing values with 0.
SQL
SQL
Vector Assembler Function
A vector assembler function provides options for grouping multiple lagged columns into structured vectors in a single statement. This function makes preparing input data for time series models easier, especially those that require organized lag structures, such as VAR.LAG_VECTORS
Groups lagged columns generated by theMULTI_LAGS or MULTI_LAGS_ZEROFILL functions into vector columns. Models such as VAR require these structured lag vectors.
The resulting vectors are named lag_vector_.
Syntax
SQL
| Argument | Type | Description |
|---|---|---|
expr1, expr2, [ ,... ] | NUMERIC | Two or more lagged columns to group. Applies the same lag range and step to each input. |
start_lag | INTEGER | First lag to assemble. This value must be less than the end_lag value. |
end_lag | INTEGER | Last lag to assemble. This value must be greater than the start_lag value. |
step | INTEGER | Optional. Defines the gap between successive lags. Must be a positive integer. If unspecified, this value defaults to 1. |
MULTI_LAGS_ZEROFILL to generate lagged columns for x1, x2, and x3, then uses LAG_VECTORS to group them into lag_vector1 through lag_vector4.
SQL
SQL
x1, x2, x3) and four lags. The example demonstrates how the lag generator functions and vector assembler can simplify feature creation compared to writing out every LAG expression manually.
MULTI_LAGS_ZEROFILLgenerates all individual lagged columns (x1_lag1…x3_lag4) in a single call, replacing NULL values with zero.LAG_VECTORSautomatically groups these lagged columns into vector inputs (lag_vector1…lag_vector4), which the model requires.
SQL
LAG invocations instead of the LAGS function. Although it produces the exact same set of lagged features (sales_lag1, sales_lag2, sales_lag3), the query requires writing each LAG expression manually. This makes the SQL longer, more repetitive, and harder to maintain compared to the concise single-line LAGS version.
SQL

