Merge pull request #43077 from evillique/query_parameters_inserts

Add support for interactive parameters in INSERT VALUES queries
This commit is contained in:
Nikolay Degterinsky 2022-11-15 22:13:25 +01:00 committed by GitHub
commit 82877d0824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -1628,6 +1628,14 @@ void ClientBase::processParsedSingleQuery(const String & full_query, const Strin
global_context->applySettingChange(change);
}
global_context->resetSettingsToDefaultValue(set_query->default_settings);
/// Query parameters inside SET queries should be also saved on the client side
/// to override their previous definitions set with --param_* arguments
/// and for substitutions to work inside INSERT ... VALUES queries
for (const auto & [name, value] : set_query->query_parameters)
query_parameters.insert_or_assign(name, value);
global_context->addQueryParameters(set_query->query_parameters);
}
if (const auto * use_query = parsed_query->as<ASTUseQuery>())
{

View File

@ -0,0 +1,8 @@
DROP TABLE IF EXISTS 02476_query_parameters_insert;
CREATE TABLE 02476_query_parameters_insert (x Int32) ENGINE=MergeTree() ORDER BY tuple();
SET param_x = 1;
INSERT INTO 02476_query_parameters_insert VALUES ({x: Int32});
SELECT * FROM 02476_query_parameters_insert;
DROP TABLE 02476_query_parameters_insert;