13293 {
13294 D_ASSERT(!internal);
13295
13296
13297 if (info.type == AlterType::SET_COLUMN_COMMENT) {
13298 auto &comment_on_column_info = info.Cast<SetColumnCommentInfo>();
13299 return SetColumnComment(context, comment_on_column_info);
13300 }
13301
13302 if (info.type != AlterType::ALTER_TABLE) {
13303 throw CatalogException("Can only modify table with ALTER TABLE statement");
13304 }
13305 auto &table_info = info.Cast<AlterTableInfo>();
13306 switch (table_info.alter_table_type) {
13307 case AlterTableType::RENAME_COLUMN: {
13308 auto &rename_info = table_info.Cast<RenameColumnInfo>();
13309 return RenameColumn(context, rename_info);
13310 }
13311 case AlterTableType::RENAME_FIELD: {
13312 auto &rename_info = table_info.Cast<RenameFieldInfo>();
13313 return RenameField(context, rename_info);
13314 }
13315 case AlterTableType::RENAME_TABLE: {
13316 auto &rename_info = table_info.Cast<RenameTableInfo>();
13317 auto copied_table = Copy(context);
13318 copied_table->name = rename_info.new_table_name;
13319 storage->SetTableName(rename_info.new_table_name);
13320 return copied_table;
13321 }
13322 case AlterTableType::ADD_COLUMN: {
13323 auto &add_info = table_info.Cast<AddColumnInfo>();
13324 return AddColumn(context, add_info);
13325 }
13326 case AlterTableType::ADD_FIELD: {
13327 auto &add_info = table_info.Cast<AddFieldInfo>();
13328 return AddField(context, add_info);
13329 }
13330 case AlterTableType::REMOVE_COLUMN: {
13331 auto &remove_info = table_info.Cast<RemoveColumnInfo>();
13332 return RemoveColumn(context, remove_info);
13333 }
13334 case AlterTableType::REMOVE_FIELD: {
13335 auto &remove_info = table_info.Cast<RemoveFieldInfo>();
13336 return RemoveField(context, remove_info);
13337 }
13338 case AlterTableType::SET_DEFAULT: {
13339 auto &set_default_info = table_info.Cast<SetDefaultInfo>();
13340 return SetDefault(context, set_default_info);
13341 }
13342 case AlterTableType::ALTER_COLUMN_TYPE: {
13343 auto &change_type_info = table_info.Cast<ChangeColumnTypeInfo>();
13344 return ChangeColumnType(context, change_type_info);
13345 }
13346 case AlterTableType::FOREIGN_KEY_CONSTRAINT: {
13347 auto &foreign_key_constraint_info = table_info.Cast<AlterForeignKeyInfo>();
13348 if (foreign_key_constraint_info.type == AlterForeignKeyType::AFT_ADD) {
13349 return AddForeignKeyConstraint(foreign_key_constraint_info);
13350 } else {
13351 return DropForeignKeyConstraint(context, foreign_key_constraint_info);
13352 }
13353 }
13354 case AlterTableType::SET_NOT_NULL: {
13355 auto &set_not_null_info = table_info.Cast<SetNotNullInfo>();
13356 return SetNotNull(context, set_not_null_info);
13357 }
13358 case AlterTableType::DROP_NOT_NULL: {
13359 auto &drop_not_null_info = table_info.Cast<DropNotNullInfo>();
13360 return DropNotNull(context, drop_not_null_info);
13361 }
13362 case AlterTableType::ADD_CONSTRAINT: {
13363 auto &add_constraint_info = table_info.Cast<AddConstraintInfo>();
13364 return AddConstraint(context, add_constraint_info);
13365 }
13366 case AlterTableType::SET_PARTITIONED_BY:
13367 throw NotImplementedException("SET PARTITIONED BY is not supported for DuckDB tables");
13368 case AlterTableType::SET_SORTED_BY:
13369 throw NotImplementedException("SET SORTED BY is not supported for DuckDB tables");
13370 case AlterTableType::SET_TABLE_OPTIONS:
13371 throw NotImplementedException("SET (<options>) is not supported for DuckDB tables");
13372 case AlterTableType::RESET_TABLE_OPTIONS: {
13373 throw NotImplementedException("RESET (<options>) is not supported for DuckDB tables");
13374 }
13375 default:
13376 throw InternalException("Unrecognized alter table type!");
13377 }
13378}