mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
fix prepared statement insert already exists (#49154)
This commit is contained in:
parent
b8f7abf507
commit
6434fd8a47
@ -345,6 +345,7 @@ private:
|
||||
PreparedInsert(pqxx::connection & connection_, const String & table, const String & schema,
|
||||
const ColumnsWithTypeAndName & columns, const String & on_conflict_)
|
||||
: Inserter(connection_)
|
||||
, statement_name("insert_" + getHexUIntLowercase(thread_local_rng()))
|
||||
{
|
||||
WriteBufferFromOwnString buf;
|
||||
buf << getInsertQuery(schema, table, columns, IdentifierQuotingStyle::DoubleQuotes);
|
||||
@ -357,12 +358,14 @@ private:
|
||||
}
|
||||
buf << ") ";
|
||||
buf << on_conflict_;
|
||||
connection.prepare("insert", buf.str());
|
||||
connection.prepare(statement_name, buf.str());
|
||||
prepared = true;
|
||||
}
|
||||
|
||||
void complete() override
|
||||
{
|
||||
connection.unprepare("insert");
|
||||
connection.unprepare(statement_name);
|
||||
prepared = false;
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
@ -371,8 +374,24 @@ private:
|
||||
pqxx::params params;
|
||||
params.reserve(row.size());
|
||||
params.append_multi(row);
|
||||
tx.exec_prepared("insert", params);
|
||||
tx.exec_prepared(statement_name, params);
|
||||
}
|
||||
|
||||
~PreparedInsert() override
|
||||
{
|
||||
try
|
||||
{
|
||||
if (prepared)
|
||||
connection.unprepare(statement_name);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
tryLogCurrentException(__PRETTY_FUNCTION__);
|
||||
}
|
||||
}
|
||||
|
||||
const String statement_name;
|
||||
bool prepared = false;
|
||||
};
|
||||
|
||||
StorageMetadataPtr metadata_snapshot;
|
||||
|
Loading…
Reference in New Issue
Block a user