ALTER TABLE ALTER COLUMN SET DEFAULT

Sets a default value expression for a column. The expression is stored verbatim in the column's metadata and applied to subsequent INSERTs that omit the column.

Category: ddl

Syntax

ALTER TABLE <table> ALTER COLUMN <column> SET DEFAULT <expression>

Description

## Overview ALTER TABLE ALTER COLUMN SET DEFAULT records a default expression in the column's metadata. INSERT statements that omit the column receive the expression's evaluated value at insert time. ## Behavior - The default expression is stored verbatim as a string in the Delta table's schema metadata. It is parsed and evaluated each time an INSERT supplies no value for the column. - Existing rows are not rewritten. Rows present before the default was set keep whatever value they had (often NULL); only INSERTs after the ALTER pick up the new default. - Replacing the default on a column overwrites the previous expression. There is no history of past defaults. - If the expression references columns or session state that is not available at INSERT time, the INSERT fails. Defaults are typically literals, simple function calls (CURRENT_TIMESTAMP, CURRENT_DATE, UUID()), or short scalar expressions. - Dropping the column later orphans the default metadata. Re-adding a column with the same name produces a fresh column entry with no default; the orphaned metadata has no effect. ## Access Control No specific privilege is required beyond table-level access in the standalone SQL layer. In a Control Plane deployment the table's MODIFY privilege governs schema changes. ## Compatibility Standard SQL syntax. The DeltaForge implementation stores the expression in the Delta table's schema metadata; this is not part of the Delta Lake protocol's column-level features but is preserved across reads via the metadata field.

Parameters

NameTypeDescription
tableSpecifies the Delta table to alter.
column_nameSpecifies the column whose default expression to set. The column must already exist.
default_expressionSpecifies the SQL expression evaluated and stored when an INSERT does not supply a value. Accepts literals, function calls, and arbitrary SQL expressions; the expression is stored as text and re-parsed at INSERT time.

Examples

-- Literal default
ALTER TABLE orders ALTER COLUMN status SET DEFAULT 'pending';
-- Numeric default
ALTER TABLE customers ALTER COLUMN tier SET DEFAULT 0;
-- Function-call default
ALTER TABLE events ALTER COLUMN created_at SET DEFAULT CURRENT_TIMESTAMP;
-- Composite expression
ALTER TABLE orders ALTER COLUMN priority SET DEFAULT COALESCE(NULL, 5);

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →