Column Default Propagation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 07:46 AM
Hi 🙂 Today I found I somewhat strange behavior when it comes to default values in columns. Apparently, column defaults are propagated to a new table, when you select the column without any operation on it. This is a bit unexpected for me. Here a short example:
I have a table where one of the columns has a default:
create or replace table schema.test (
id int default 0,
name string
)
TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported') -- needed as otherwise we can not define defaults
;
I insert some data and the use this as a basis for a new table:
create or replace table schema.test2
as
(select id, name from schema.test);
this fails with the following error: [WRONG_COLUMN_DEFAULTS_FOR_DELTA_FEATURE_NOT_ENABLED] Failed to execute CREATE TABLE command because it assigned a column DEFAULT value, but the corresponding table feature was not enabled. Please retry the command again after executing ALTER TABLE tableName SET TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported').
When I enable the table properties it works:
create or replace table schema.test2
TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported')
as (select id, name from schema.test);
in this case the default will also be set on the id column of the new table, even though I have not explicitly set this.
or when I do some operation on the column it works also without setting the table properties:
create or replace table schema.test2
as
(select cast(id as int), name from schema.test);
is this expected behavior? Is there a way to disable this?