

such as
```
create view view1 as 
with t as (select number n from numbers(3))
select n from t
```
WriteBufferFromOwnString statement_buf;
        formatAST(create, statement_buf, false);
        writeChar('\n', statement_buf);
        String statement = statement_buf.str();
        
        WriteBufferFromFile out(metadata_file_tmp_path, statement.size(), O_WRONLY | O_CREAT | O_EXCL);
        writeString(statement, out);
        out.next();
        if (getContext()->getSettingsRef().fsync_metadata)
            out.sync();
        out.close();
    }
    
    auto db_guard = DatabaseCatalog::instance().getExclusiveDDLGuardForDatabase(database_name);
    bool added = false;
    bool renamed = false;
    try
    {
        
        DatabaseCatalog::instance().attachDatabase(database_name, database);
        added = true;
        if (need_write_metadata)
        {
            
            renameNoReplace(metadata_file_tmp_path, metadata_file_path);
            renamed = true;
        }
        
        database->loadStoredObjects(getContext()->getGlobalContext(), has_force_restore_data_flag, create.attach && force_attach);
    }