Available from version 25.6This table engine is available from version 25.6 and higher in both OSS and Cloud.
CoalescingMergeTree tables, ClickHouse replaces all rows with the same primary key (or more precisely, the same sorting key) with a single row that contains the latest non-NULL values for each column.
This enables column-level upserts, meaning you can update only specific columns rather than entire rows.
CoalescingMergeTree is intended for use with Nullable types in non-key columns. If the columns are not Nullable, the behavior is the same as with ReplacingMergeTree.
Creating a table
Parameters of CoalescingMergeTree
Columns
columns - Optional. A tuple with the names of columns where values will be united. The provided columns must not be in the partition or sorting key. If columns is not specified, ClickHouse unites the values in all columns that are not in the sorting key.
Query clauses
When creating aCoalescingMergeTree table the same clauses are required, as when creating a MergeTree table.
Usage example
Consider the following table:FINAL modifier forces ClickHouse to apply merge logic at query time, ensuring you get the correct, coalesced “latest” value for each column. This is the safest and most accurate method when querying from a CoalescingMergeTree table.
An approach with
GROUP BY may return incorrect results if the underlying parts have not been fully merged.Tuple element aggregation
When theallow_tuple_element_aggregation setting is enabled, Tuple columns are recursively flattened so that each leaf element participates in coalescing independently. This allows you to store multiple fields in a single Tuple column and have them coalesced element-wise during merges — each Nullable sub-column retains the latest non-NULL value independently.
The same rules apply to the flattened sub-columns as to regular columns:
- Sub-columns that belong to a
Tuplein the sorting key or partition key are excluded from coalescing. - If
columnsis specified, only sub-columns of the listedTuplecolumns are coalesced.
This setting is immutable and must be specified at table creation time.