title: ClickHouse: How to move data from tables with different partition keys?
body: <p>I'm planning on doing a table redesign in ClickHouse to avoid some performance and deduplication/versioning issues while using ReplicatedReplacingMergeTree. Here, OPTIMIZE FINAL can be run to remove duplicates but can't be run continuously. </p>
  
  <p>So we are planning to keep a table A, partitioned daily, with incoming data.
  Then a table B, partitioned monthly, where historical data will be stored.
  Queries will be directed to a MERGE table (not MergeTree) that will contain both.</p>
  
  <p>And then, we'd set up an action to move the latest partition, from A to B, every day right after the end of the day.</p>
  
  <p>However, moving partition as in <a href="https://clickhouse.tech/docs/en/sql-reference/statements/alter/#alter_move_to_table-partition" rel="nofollow noreferrer">MOVE PARTITION TO TABLE</a> where it is stated that "Both tables must have the same partition key.", it is not possible.
  An approach is to copy data from A's daily partition to B, and then detach/drop daily partition in A. However in the meantime we'll see duplicates.</p>
  
  <p>What would be the best way to transfer this data from A to B with minimal impact? What other options would be?</p>