Skip to content

Generated Columns

Spark SQL 3.4.0 comes with support for GENERATED ALWAYS AS syntax for defining Generated Columns in CREATE TABLE and REPLACE TABLE statements for data sources that support it.

CREATE TABLE default.example (
    time TIMESTAMP,
    date DATE GENERATED ALWAYS AS (CAST(time AS DATE))
)

Generated Columns are part of column definition.

colDefinitionOption
    : NOT NULL
    | defaultExpression
    | generationExpression
    | commentSpec
    ;

generationExpression
    : GENERATED ALWAYS AS '(' expression ')'
    ;