Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/model/clickhouse/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ func (c *Cluster) exec(ctx context.Context, host string, queries []string, _opts
sqlAttach := strings.ReplaceAll(sql, "CREATE TABLE", "ATTACH TABLE")
err = conn.Exec(ctx, sqlAttach, opts)
}
if err != nil && strings.Contains(err.Error(), "Code: 117") && strings.Contains(sql, "CREATE TABLE") {
// WARNING: error message or code may change in newer ClickHouse versions
c.l.V(1).M(host).F().Info("Directory for table already exists. Trying ATTACH TABLE instead")
sqlAttach := strings.ReplaceAll(sql, "CREATE TABLE", "ATTACH TABLE")
err = conn.Exec(ctx, sqlAttach, opts)
}
if err == nil || strings.Contains(err.Error(), "ALREADY_EXISTS") {
queries[i] = "" // Query is executed or object already exists, removing from the list
} else {
Expand Down