```
CREATE TABLE a
(
    `number` UInt64,
    `x` MATERIALIZED x
)
ENGINE = MergeTree
ORDER BY number;
-- that should fail!

insert into a values (1);
Received exception from server (version 21.7.1):
Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Missing columns: 'x' while processing query: 'CAST(x, 'UInt8') AS x', required columns: 'x' 'x'. 
```
{
    const auto & reorder_column = [&](auto get_new_pos)
    {
        auto column_range = getNameRange(columns, column_name);
        if (column_range.first == column_range.second)
            throw Exception("There is no column " + column_name + " in table.", ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);
        std::vector<ColumnDescription> moving_columns;
        for (auto list_it = column_range.first; list_it != column_range.second;)
        {
            moving_columns.emplace_back(*list_it);
            list_it = columns.get<0>().erase(list_it);
        }
        columns.get<0>().insert(get_new_pos(), moving_columns.begin(), moving_columns.end());
    };
    if (first)
        reorder_column([&]() { return columns.cbegin(); });
    else if (!after_column.empty() && column_name != after_column)
    {
        
        auto range = getNameRange(columns, after_column);
        if (range.first == range.second)
            throw Exception("Wrong column name. Cannot find column " + after_column + " to insert after",
                ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);
        reorder_column([&]() { return getNameRange(columns, after_column).second; });
    }
}
void ColumnsDescription::flattenNested()