Problem
You are attempting to use the ALTER
command to update an existing column to a generated column in a Delta table. You encounter the following error.
[PARSE_SYNTAX_ERROR] Syntax error at or near 'GENERATED'. SQLSTATE: 42601
Cause
You must specify generated column expressions during table creation.
Once the table is created, you cannot alter a column to make it a generated column or change its generated expression. Generated columns are computed based on other columns in the table, and changing their definition requires rewriting the existing data.
Solution
Recreate the table with the column defined with the generated column definition.
%sql
CREATE TABLE new_table (
-- other columns
date_utc DATE GENERATED ALWAYS AS (<your-generation-expression>),
-- other columns
) USING DELTA PARTITIONED BY (date_utc);
For more information, refer to the Delta Lake Generated columns (AWS | Azure | GCP) documentation.