ReferenceSQL ReferenceAggregate Functions

sumKahan

Calculates the sum of the numbers with [Kahan compensated summation algorithm](https://en.

This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See SQL interface scope.

Calculates the sum of the numbers with Kahan compensated summation algorithm. Slower than sum function. The compensation works only for Float types.

Syntax

sumKahan(x)

Arguments

Returned value

Returns the sum of numbers. (U)Int* or Float* or Decimal

Examples

Demonstrating precision improvement with Kahan summation

SELECT sum(0.1), sumKahan(0.1) FROM numbers(10);
┌───────────sum(0.1)─┬─sumKahan(0.1)─┐
│ 0.9999999999999999 │             1 │
└────────────────────┴───────────────┘

Introduced in version 1.1.0.