diff --git a/src/Interpreters/InterpreterCreateQuery.cpp b/src/Interpreters/InterpreterCreateQuery.cpp index 7ddb0c8c26e..d0308d11a35 100644 --- a/src/Interpreters/InterpreterCreateQuery.cpp +++ b/src/Interpreters/InterpreterCreateQuery.cpp @@ -725,9 +725,8 @@ void InterpreterCreateQuery::setEngine(ASTCreateQuery & create) const if (create.storage || create.is_dictionary || create.isView()) { if (create.temporary && create.storage && create.storage->engine && create.storage->engine->name != "Memory") - throw Exception( - "Temporary tables can only be created with ENGINE = Memory, not " + create.storage->engine->name, - ErrorCodes::INCORRECT_QUERY); + throw Exception(ErrorCodes::INCORRECT_QUERY, + "Temporary tables can only be created with ENGINE = Memory, not {}", create.storage->engine->name); return; } @@ -1254,17 +1253,14 @@ BlockIO InterpreterCreateQuery::fillTableIfNeeded(const ASTCreateQuery & create) { /// If the query is a CREATE SELECT, insert the data into the table. if (create.select && !create.attach - && !create.is_ordinary_view && !create.is_live_view && !create.is_window_view && (!create.is_materialized_view || create.is_populate)) + && !create.is_ordinary_view && !create.is_live_view && !create.is_window_view + && (!create.is_materialized_view || create.is_populate)) { auto insert = std::make_shared(); insert->table_id = {create.getDatabase(), create.getTable(), create.uuid}; insert->select = create.select->clone(); - if (create.temporary && !getContext()->getSessionContext()->hasQueryContext()) - getContext()->getSessionContext()->makeQueryContext(); - - return InterpreterInsertQuery(insert, - create.temporary ? getContext()->getSessionContext() : getContext(), + return InterpreterInsertQuery(insert, getContext(), getContext()->getSettingsRef().insert_allow_materialized_columns).execute(); } diff --git a/src/Interpreters/Session.h b/src/Interpreters/Session.h index 71964130412..f937c73d1a8 100644 --- a/src/Interpreters/Session.h +++ b/src/Interpreters/Session.h @@ -36,9 +36,9 @@ public: ~Session(); Session(const Session &&) = delete; - Session& operator=(const Session &&) = delete; + Session & operator=(const Session &&) = delete; Session(const Session &) = delete; - Session& operator=(const Session &) = delete; + Session & operator=(const Session &) = delete; /// Provides information about the authentication type of a specified user. AuthenticationType getAuthenticationType(const String & user_name) const; @@ -97,4 +97,3 @@ private: }; } - diff --git a/src/Server/HTTPHandler.cpp b/src/Server/HTTPHandler.cpp index 673edfb6719..727781ea4a3 100644 --- a/src/Server/HTTPHandler.cpp +++ b/src/Server/HTTPHandler.cpp @@ -10,10 +10,7 @@ #include #include #include -#include #include -#include -#include #include #include #include @@ -27,7 +24,6 @@ #include #include #include -#include #include #include @@ -41,13 +37,11 @@ #include #include #include -#include #include #include #include #include -#include #include @@ -56,7 +50,6 @@ namespace DB namespace ErrorCodes { - extern const int LOGICAL_ERROR; extern const int CANNOT_PARSE_TEXT; extern const int CANNOT_PARSE_ESCAPE_SEQUENCE; diff --git a/tests/queries/0_stateless/02177_temporary_table_current_database_http_session.reference b/tests/queries/0_stateless/02177_temporary_table_current_database_http_session.reference new file mode 100644 index 00000000000..78f5d214b4d --- /dev/null +++ b/tests/queries/0_stateless/02177_temporary_table_current_database_http_session.reference @@ -0,0 +1 @@ +test_02177 diff --git a/tests/queries/0_stateless/02177_temporary_table_current_database_http_session.sh b/tests/queries/0_stateless/02177_temporary_table_current_database_http_session.sh new file mode 100755 index 00000000000..abc5fb49750 --- /dev/null +++ b/tests/queries/0_stateless/02177_temporary_table_current_database_http_session.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Tags: no-parallel + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +DATABASE='test_02177' +SESSION_ID="$RANDOM$RANDOM$RANDOM" + +${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}" -d "DROP DATABASE IF EXISTS ${DATABASE}" +${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}" -d "CREATE DATABASE ${DATABASE}" + +CLICKHOUSE_URL_PARAMS="database=${DATABASE}" +[ -v CLICKHOUSE_LOG_COMMENT ] && CLICKHOUSE_URL_PARAMS="${CLICKHOUSE_URL_PARAMS}&log_comment=${CLICKHOUSE_LOG_COMMENT}" +CLICKHOUSE_URL="${CLICKHOUSE_PORT_HTTP_PROTO}://${CLICKHOUSE_HOST}:${CLICKHOUSE_PORT_HTTP}/?${CLICKHOUSE_URL_PARAMS}" + +${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&session_id=${SESSION_ID}" -d 'CREATE TEMPORARY TABLE t AS SELECT currentDatabase()' +${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&session_id=${SESSION_ID}" -d 'SELECT * FROM t' + +${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}" -d "DROP DATABASE ${DATABASE}"