ClickHouse/src/Parsers/getInsertQuery.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
1.0 KiB
C++
Raw Normal View History

2021-08-25 21:51:43 +00:00
#include <Parsers/getInsertQuery.h>
#include <Parsers/ASTInsertQuery.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTExpressionList.h>
#include <IO/WriteBufferFromString.h>
namespace DB
{
std::string getInsertQuery(const std::string & db_name, const std::string & table_name, const ColumnsWithTypeAndName & columns, IdentifierQuotingStyle quoting)
{
ASTInsertQuery query;
query.table_id.database_name = db_name;
query.table_id.table_name = table_name;
query.columns = std::make_shared<ASTExpressionList>(',');
query.children.push_back(query.columns);
for (const auto & column : columns)
query.columns->children.emplace_back(std::make_shared<ASTIdentifier>(column.name));
WriteBufferFromOwnString buf;
2024-09-10 15:05:56 +00:00
IAST::FormatSettings settings(
/*ostr_=*/buf,
/*one_line=*/true,
/*hilite=*/false,
/*identifier_quoting_rule=*/IdentifierQuotingRule::WhenNecessary,
/*identifier_quoting_style=*/quoting);
2021-08-25 21:51:43 +00:00
query.IAST::format(settings);
return buf.str();
}
}