diff --git a/src/catalog/catalog_entry/duck_table_entry.cpp b/src/catalog/catalog_entry/duck_table_entry.cpp index d6a56d0451cd..85d3e531b3fd 100644 --- a/src/catalog/catalog_entry/duck_table_entry.cpp +++ b/src/catalog/catalog_entry/duck_table_entry.cpp @@ -343,9 +343,9 @@ unique_ptr DuckTableEntry::AddColumn(ClientContext &context, AddCo create_info->columns.AddColumn(std::move(col)); auto binder = Binder::CreateBinder(context); - auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info), schema); - auto new_storage = - make_shared_ptr(context, *storage, info.new_column, *bound_create_info->bound_defaults.back()); + vector> bound_defaults; + auto bound_create_info = binder->BindCreateTableInfo(std::move(create_info), schema, bound_defaults); + auto new_storage = make_shared_ptr(context, *storage, info.new_column, *bound_defaults.back()); return make_uniq(catalog, schema, *bound_create_info, new_storage); } diff --git a/src/include/duckdb/planner/binder.hpp b/src/include/duckdb/planner/binder.hpp index 4bbce3a9c36a..cb63471a6df0 100644 --- a/src/include/duckdb/planner/binder.hpp +++ b/src/include/duckdb/planner/binder.hpp @@ -119,6 +119,8 @@ class Binder : public enable_shared_from_this { unique_ptr BindCreateTableInfo(unique_ptr info); unique_ptr BindCreateTableInfo(unique_ptr info, SchemaCatalogEntry &schema); + unique_ptr BindCreateTableInfo(unique_ptr info, SchemaCatalogEntry &schema, + vector> &bound_defaults); void BindCreateViewInfo(CreateViewInfo &base); SchemaCatalogEntry &BindSchema(CreateInfo &info); diff --git a/src/include/duckdb/planner/parsed_data/bound_create_table_info.hpp b/src/include/duckdb/planner/parsed_data/bound_create_table_info.hpp index fe71dfbda6fe..c7a1aac57705 100644 --- a/src/include/duckdb/planner/parsed_data/bound_create_table_info.hpp +++ b/src/include/duckdb/planner/parsed_data/bound_create_table_info.hpp @@ -38,8 +38,6 @@ struct BoundCreateTableInfo { vector> constraints; //! List of bound constraints on the table vector> bound_constraints; - //! Bound default values - vector> bound_defaults; //! Dependents of the table (in e.g. default values) LogicalDependencyList dependencies; //! The existing table data on disk (if any) diff --git a/src/planner/binder/statement/bind_create_table.cpp b/src/planner/binder/statement/bind_create_table.cpp index 4564cb0f04c6..780ef2380497 100644 --- a/src/planner/binder/statement/bind_create_table.cpp +++ b/src/planner/binder/statement/bind_create_table.cpp @@ -239,8 +239,8 @@ static void ExtractExpressionDependencies(Expression &expr, LogicalDependencyLis expr, [&](Expression &child) { ExtractExpressionDependencies(child, dependencies); }); } -static void ExtractDependencies(BoundCreateTableInfo &info) { - for (auto &default_value : info.bound_defaults) { +static void ExtractDependencies(BoundCreateTableInfo &info, vector> &bound_defaults) { + for (auto &default_value : bound_defaults) { if (default_value) { ExtractExpressionDependencies(*default_value, info.dependencies); } @@ -252,7 +252,14 @@ static void ExtractDependencies(BoundCreateTableInfo &info) { } } } + unique_ptr Binder::BindCreateTableInfo(unique_ptr info, SchemaCatalogEntry &schema) { + vector> bound_defaults; + return BindCreateTableInfo(std::move(info), schema, bound_defaults); +} + +unique_ptr Binder::BindCreateTableInfo(unique_ptr info, SchemaCatalogEntry &schema, + vector> &bound_defaults) { auto &base = info->Cast(); auto result = make_uniq(schema, std::move(info)); if (base.query) { @@ -279,10 +286,10 @@ unique_ptr Binder::BindCreateTableInfo(unique_ptrbound_defaults); + BindDefaultValues(base.columns, bound_defaults); } // extract dependencies from any default values or CHECK constraints - ExtractDependencies(*result); + ExtractDependencies(*result, bound_defaults); if (base.columns.PhysicalColumnCount() == 0) { throw BinderException("Creating a table without physical (non-generated) columns is not supported");