yoel
yoel

Reputation: 315

Is it possible to move data between two distributed tables in ClickHouse

I think the answer is no, but wanted to check here to be sure. Is it possible to move data (copy and then delete the source) between two distributed tables in ClickHouse? Say, I have local tables a and b defined in all of my nodes, and a_dist defined as:

CREATE TABLE IF NOT EXISTS a_dist ON CLUSTER my_cluster_name AS a ENGINE = Distributed(my_cluster_name, default, a, rand())
CREATE TABLE IF NOT EXISTS b_dist ON CLUSTER my_cluster_name AS a ENGINE = Distributed(my_cluster_name, default, b, rand())

Is it possible to move all of the data from a_dist to b_dist directly? Or should I move data in each node from table a to table b?

Thanks!

Upvotes: 1

Views: 1633

Answers (1)

Slach
Slach

Reputation: 2450

The simplest way

INSERT INTO b_dist SELECT * FROM a_dist;
TRUNCATE default.a ON CLUSTER 'my_cluster_name';

But it will produce numerous data transfer between the node where you execute this query and other nodes in cluster

for Atomic database engine and clickhouse 21.8+, run directly on each node will much faster

EXCHANGE TABLES default.a AND default.b

Upvotes: 2

Related Questions