diff --git a/src/Databases/DatabaseOrdinary.cpp b/src/Databases/DatabaseOrdinary.cpp index 65d5f21bbea..f4191727b7c 100644 --- a/src/Databases/DatabaseOrdinary.cpp +++ b/src/Databases/DatabaseOrdinary.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include @@ -128,10 +127,10 @@ void DatabaseOrdinary::convertMergeTreeToReplicatedIfNeeded(ASTPtr ast, const Qu /// Get table's storage policy MergeTreeSettings default_settings = getContext()->getMergeTreeSettings(); - auto * query_settings = create_query->storage->settings->as(); auto policy = getContext()->getStoragePolicy(default_settings.storage_policy); - if (Field * policy_setting = query_settings->changes.tryGet("storage_policy")) - policy = getContext()->getStoragePolicy(policy_setting->get()); + if (auto * query_settings = create_query->storage->settings->as()) + if (Field * policy_setting = query_settings->changes.tryGet("storage_policy")) + policy = getContext()->getStoragePolicy(policy_setting->safeGet()); auto convert_to_replicated_flag_path = getConvertToReplicatedFlagPath(qualified_name.table, policy, false);