Tuple functions

```
hello
```

## tupleHammingDistance[​](#tupleHammingDistance "Direct link to tupleHammingDistance")

Introduced in: v21.1.0

Returns the [Hamming Distance](https://en.wikipedia.org/wiki/Hamming_distance) between two tuples of the same size.

Note

The result type is determined the same way it is for [Arithmetic functions](/docs/sql-reference/functions/arithmetic-functions), based on the number of elements in the input tuples.

```
SELECT
    toTypeName(tupleHammingDistance(tuple(0), tuple(0))) AS t1,
    toTypeName(tupleHammingDistance((0, 0), (0, 0))) AS t2,
    toTypeName(tupleHammingDistance((0, 0, 0), (0, 0, 0))) AS t3,
    toTypeName(tupleHammingDistance((0, 0, 0, 0), (0, 0, 0, 0))) AS t4,
    toTypeName(tupleHammingDistance((0, 0, 0, 0, 0), (0, 0, 0, 0, 0))) AS t5
```

```
┌─t1────┬─t2─────┬─t3─────┬─t4─────┬─t5─────┐
│ UInt8 │ UInt16 │ UInt32 │ UInt64 │ UInt64 │
└───────┴────────┴────────┴────────┴────────┘
```

**Syntax**

```
tupleHammingDistance(t1, t2)
```

**Arguments**

- `t1` — First tuple. [`Tuple(*)`](/docs/sql-reference/data-types/tuple)
- `t2` — Second tuple. [`Tuple(*)`](/docs/sql-reference/data-types/tuple)

**Returned value**

Returns the Hamming distance. [`UInt8/16/32/64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT tupleHammingDistance((1, 2, 3), (3, 2, 1))
```

```
2
```

**With MinHash to detect semi-duplicate strings**

```
SELECT tupleHammingDistance(wordShingleMinHash(string), wordShingleMinHashCaseInsensitive(string)) FROM (SELECT 'ClickHouse is a column-oriented database management system for online analytical processing of queries.' AS string)
```

```
2
```

## tupleIntDiv[​](#tupleIntDiv "Direct link to tupleIntDiv")

Introduced in: v23.8.0

Performs an integer division with a tuple of numerators and a tuple of denominators. Returns a tuple of quotients.
If either tuple contains non-integer elements then the result is calculated by rounding to the nearest integer for each non-integer numerator or divisor.
Division by 0 causes an error to be thrown.

**Syntax**

```
tupleIntDiv(tuple_num, tuple_div)
```

**Arguments**

- `tuple_num` — Tuple of numerator values. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)
- `tuple_div` — Tuple of divisor values. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)

**Returned value**

Returns a tuple of the quotients. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)

**Examples**

**Basic usage**

```
SELECT tupleIntDiv((15, 10, 5), (5, 5, 5))
```

```
(3, 2, 1)
```

**With decimals**

```
SELECT tupleIntDiv((15, 10, 5), (5.5, 5.5, 5.5))
```

```
(2, 1, 0)
```

## tupleIntDivByNumber[​](#tupleIntDivByNumber "Direct link to tupleIntDivByNumber")

Introduced in: v23.8.0

Performs integer division of a tuple of numerators by a given denominator, and returns a tuple of the quotients.
If either of the input parameters contain non-integer elements then the result is calculated by rounding to the nearest integer for each non-integer numerator or divisor.
An error will be thrown for division by 0.

**Syntax**

```
tupleIntDivByNumber(tuple_num, div)
```

**Arguments**

- `tuple_num` — Tuple of numerator values. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)
- `div` — The divisor value. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns a tuple of the quotients. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)

**Examples**

**Basic usage**

```
SELECT tupleIntDivByNumber((15, 10, 5), 5)
```

```
(3, 2, 1)
```

**With decimals**

```
SELECT tupleIntDivByNumber((15.2, 10.7, 5.5), 5.8)
```

```
(2, 1, 0)
```

## tupleIntDivOrZero[​](#tupleIntDivOrZero "Direct link to tupleIntDivOrZero")

Introduced in: v23.8.0

Like [`tupleIntDiv`](#tupleIntDiv) performs integer division of a tuple of numerators and a tuple of denominators, and returns a tuple of the quotients.
In case of division by 0, returns the quotient as 0 instead of throwing an exception.
If either tuple contains non-integer elements then the result is calculated by rounding to the nearest integer for each non-integer numerator or divisor.

**Syntax**

```
tupleIntDivOrZero(tuple_num, tuple_div)
```

**Arguments**

- `tuple_num` — Tuple of numerator values. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)
- `tuple_div` — Tuple of divisor values. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)

**Returned value**

Returns tuple of the quotients. Returns 0 for quotients where the divisor is 0. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)

**Examples**

**With zero divisors**

```
SELECT tupleIntDivOrZero((5, 10, 15), (0, 0, 0))
```

```
(0, 0, 0)
```

## tupleIntDivOrZeroByNumber[​](#tupleIntDivOrZeroByNumber "Direct link to tupleIntDivOrZeroByNumber")

Introduced in: v23.8.0

Like [`tupleIntDivByNumber`](#tupleIntDivByNumber) it does integer division of a tuple of numerators by a given denominator, and returns a tuple of the quotients.
It does not throw an error for zero divisors, but rather returns the quotient as zero.
If either the tuple or div contain non-integer elements then the result is calculated by rounding to the nearest integer for each non-integer numerator or divisor.

**Syntax**

```
tupleIntDivOrZeroByNumber(tuple_num, div)
```

**Arguments**

- `tuple_num` — Tuple of numerator values. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)
- `div` — The divisor value. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)

**Returned value**

Returns a tuple of the quotients with `0` for quotients where the divisor is `0`. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)

**Examples**

**Basic usage**

```
SELECT tupleIntDivOrZeroByNumber((15, 10, 5), 5)
```

```
(3, 2, 1)
```

**With zero divisor**

```
SELECT tupleIntDivOrZeroByNumber((15, 10, 5), 0)
```

```
(0, 0, 0)
```

## tupleMinus[​](#tupleMinus "Direct link to tupleMinus")

Introduced in: v21.11.0

Calculates the difference between corresponding elements of two tuples of the same size.

**Syntax**

```
tupleMinus(t1, t2)
```

**Aliases**: `vectorDifference`

**Arguments**

- `t1` — First tuple. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)
- `t2` — Second tuple. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)

**Returned value**

Returns a tuple containing the results of the subtractions. [`Tuple((U)Int*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Float*)`](/docs/sql-reference/data-types/tuple) or [`Tuple(Decimal)`](/docs/sql-reference/data-types/tuple)