# Hash (/docs/reference/sql/functions/hash)



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](/docs/reference/clickhouse-compatibility#service-interfaces).

BLAKE3 [#blake3]

Calculates BLAKE3 hash string and returns the resulting set of bytes as FixedString.
This cryptographic hash-function is integrated into RawTree with BLAKE3 Rust library.
The function is rather fast and shows approximately two times faster performance compared to SHA-2, while generating hashes of the same length as SHA-256.
It returns a BLAKE3 hash as a byte array with type FixedString(32).

**Syntax**

```sql
BLAKE3(message)
```

**Arguments**

* `message` — The input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the 32-byte BLAKE3 hash of the input string as a fixed-length string. [`FixedString(32)`](/reference/data-types/fixedstring)

**Examples**

**hash**

```sql title=Query
SELECT hex(BLAKE3('ABC'))
```

```text title=Response
┌─hex(BLAKE3('ABC'))───────────────────────────────────────────────┐
│ D1717274597CF0289694F75D96D444B992A096F1AFD8E7BBFA6EBB1D360FEDFC │
└──────────────────────────────────────────────────────────────────┘
```

*Introduced in version 22.10.0.*

MD4 [#md4]

Calculates the MD4 hash of the given string.

**Syntax**

```sql
MD4(s)
```

**Arguments**

* `s` — The input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the MD4 hash of the given input string as a fixed-length string. [`FixedString(16)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT HEX(MD4('abc'));
```

```text title=Response
┌─hex(MD4('abc'))──────────────────┐
│ A448017AAF21D8525FC10AE87AA6729D │
└──────────────────────────────────┘
```

*Introduced in version 21.11.0.*

MD5 [#md5]

Calculates the MD5 hash of the given string.

**Syntax**

```sql
MD5(s)
```

**Arguments**

* `s` — The input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the MD5 hash of the given input string as a fixed-length string. [`FixedString(16)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT HEX(MD5('abc'));
```

```text title=Response
┌─hex(MD5('abc'))──────────────────┐
│ 900150983CD24FB0D6963F7D28E17F72 │
└──────────────────────────────────┘
```

*Introduced in version 1.1.0.*

RIPEMD160 [#ripemd160]

Calculates the RIPEMD-160 hash of the given string.

**Syntax**

```sql
RIPEMD160(s)
```

**Arguments**

* `s` — The input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the RIPEMD160 hash of the given input string as a fixed-length string. [`FixedString(20)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT HEX(RIPEMD160('The quick brown fox jumps over the lazy dog'));
```

```text title=Response
┌─HEX(RIPEMD160('The quick brown fox jumps over the lazy dog'))─┐
│ 37F332F68DB77BD9D7EDD4969571AD671CF9DD3B                      │
└───────────────────────────────────────────────────────────────┘
```

*Introduced in version 24.10.0.*

SHA1 [#sha1]

Calculates the SHA1 hash of the given string.

**Syntax**

```sql
SHA1(s)
```

**Arguments**

* `s` — The input string to hash [`String`](/reference/data-types/string)

**Returned value**

Returns the SHA1 hash of the given input string as a fixed-length string. [`FixedString(20)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT HEX(SHA1('abc'));
```

```text title=Response
┌─hex(SHA1('abc'))─────────────────────────┐
│ A9993E364706816ABA3E25717850C26C9CD0D89D │
└──────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

SHA224 [#sha224]

Calculates the SHA224 hash of the given string.

**Syntax**

```sql
SHA224(s)
```

**Arguments**

* `s` — The input value to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the SHA224 hash of the given input string as a fixed-length string. [`FixedString(28)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT HEX(SHA224('abc'));
```

```text title=Response
┌─hex(SHA224('abc'))───────────────────────────────────────┐
│ 23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7 │
└──────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

SHA256 [#sha256]

Calculates the SHA256 hash of the given string.

**Syntax**

```sql
SHA256(s)
```

**Arguments**

* `s` — The input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the SHA256 hash of the given input string as a fixed-length string. [`FixedString(32)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT HEX(SHA256('abc'));
```

```text title=Response
┌─hex(SHA256('abc'))───────────────────────────────────────────────┐
│ BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD │
└──────────────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

SHA384 [#sha384]

Calculates the SHA384 hash of the given string.

**Syntax**

```sql
SHA384(s)
```

**Arguments**

* `s` — The input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the SHA384 hash of the given input string as a fixed-length string. [`FixedString(48)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT HEX(SHA384('abc'));
```

```text title=Response
┌─hex(SHA384('abc'))───────────────────────────────────────────────────────────────────────────────┐
│ CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7 │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

SHA512 [#sha512]

Calculates the SHA512 hash of the given string.

**Syntax**

```sql
SHA512(s)
```

**Arguments**

* `s` — The input string to hash [`String`](/reference/data-types/string)

**Returned value**

Returns the SHA512 hash of the given input string as a fixed-length string. [`FixedString(64)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT HEX(SHA512('abc'));
```

```text title=Response
┌─hex(SHA512('abc'))───────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

SHA512_256 [#sha512_256]

Calculates the SHA512\_256 hash of the given string.

**Syntax**

```sql
SHA512_256(s)
```

**Arguments**

* `s` — The input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the SHA512\_256 hash of the given input string as a fixed-length string. [`FixedString(32)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT HEX(SHA512_256('abc'));
```

```text title=Response
┌─hex(SHA512_256('abc'))───────────────────────────────────────────┐
│ 53048E2681941EF99B2E29B76B4C7DABE4C2D0C634FC6D46E0E2F13107E7AF23 │
└──────────────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

URLHash [#urlhash]

A fast, decent-quality non-cryptographic hash function for a string obtained from a URL using some type of normalization.

This hash function has two modes:

| Mode              | Description                                                                                                                                                                                  |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `URLHash(url)`    | Calculates a hash from a string without one of the trailing symbols `/`,`?` or `#` at the end, if present.                                                                                   |
| `URLHash(url, N)` | Calculates a hash from a string up to the N level in the URL hierarchy, without one of the trailing symbols `/`,`?` or `#` at the end, if present. Levels are the same as in `URLHierarchy`. |

**Syntax**

```sql
URLHash(url[, N])
```

**Arguments**

* `url` — URL string to hash. [`String`](/reference/data-types/string)
* `N` — Optional. Level in the URL hierarchy. [`(U)Int*`](/reference/data-types/int-uint)

**Returned value**

Returns the computed hash value of `url`. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT URLHash('https://www.clickhouse.com')
```

```text title=Response
┌─URLHash('htt⋯house.com')─┐
│     13614512636072854701 │
└──────────────────────────┘
```

**Hash of url with specified level**

```sql title=Query
SELECT URLHash('https://www.clickhouse.com/docs', 0);
SELECT URLHash('https://www.clickhouse.com/docs', 1);
```

```text title=Response
-- hash of https://www.clickhouse.com
┌─URLHash('htt⋯m/docs', 0)─┐
│     13614512636072854701 │
└──────────────────────────┘
-- hash of https://www.clickhouse.com/docs
┌─URLHash('htt⋯m/docs', 1)─┐
│     13167253331440520598 │
└──────────────────────────┘
```

*Introduced in version 1.1.0.*

cityHash64 [#cityhash64]

Produces a 64-bit [CityHash](https://github.com/google/cityhash) hash value.

This is a fast non-cryptographic hash function.
It uses the CityHash algorithm for string parameters and implementation-specific fast non-cryptographic hash function for parameters with other data types.
The function uses the CityHash combinator to get the final results.

:::info
Google changed the algorithm of CityHash after it was added to RawTree.
In other words, RawTree's cityHash64 and Google's upstream CityHash now produce different results.
RawTree cityHash64 corresponds to CityHash v1.0.2.
:::

:::note
The calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.
:::

**Syntax**

```sql
cityHash64(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed hash of the input arguments. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Call example**

```sql title=Query
SELECT cityHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS CityHash, toTypeName(CityHash) AS type;
```

```text title=Response
┌─────────────CityHash─┬─type───┐
│ 12072650598913549138 │ UInt64 │
└──────────────────────┴────────┘
```

**Computing the checksum of the entire table with accuracy up to the row order**

```sql title=Query
CREATE TABLE users (
    id UInt32,
    name String,
    age UInt8,
    city String
)
ENGINE = MergeTree
ORDER BY tuple();

INSERT INTO users VALUES
(1, 'Alice', 25, 'New York'),
(2, 'Bob', 30, 'London'),
(3, 'Charlie', 35, 'Tokyo');

SELECT groupBitXor(cityHash64(*)) FROM users;
```

```text title=Response
┌─groupBitXor(⋯age, city))─┐
│     11639977218258521182 │
└──────────────────────────┘
```

*Introduced in version 1.1.0.*

farmFingerprint64 [#farmfingerprint64]

Produces a 64-bit [FarmHash](https://github.com/google/farmhash) value using the `Fingerprint64` method.

:::tip
`farmFingerprint64` is preferred for a stable and portable value over [`farmHash64`](#farmHash64).
:::

:::note
The calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.
:::

**Syntax**

```sql
farmFingerprint64(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed hash value of the input arguments. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT farmFingerprint64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS FarmFingerprint, toTypeName(FarmFingerprint) AS type;
```

```text title=Response
┌─────FarmFingerprint─┬─type───┐
│ 5752020380710916328 │ UInt64 │
└─────────────────────┴────────┘
```

*Introduced in version 20.12.0.*

farmHash64 [#farmhash64]

Produces a 64-bit [FarmHash](https://github.com/google/farmhash) using the `Hash64` method.

:::tip
[`farmFingerprint64`](#farmFingerprint64) is preferred for a stable and portable value.
:::

:::note
The calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.
:::

**Syntax**

```sql
farmHash64(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed hash value of the input arguments. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT farmHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS FarmHash, toTypeName(FarmHash) AS type;
```

```text title=Response
┌─────────────FarmHash─┬─type───┐
│ 18125596431186471178 │ UInt64 │
└──────────────────────┴────────┘
```

*Introduced in version 1.1.0.*

gccMurmurHash [#gccmurmurhash]

Computes the 64-bit [MurmurHash2](https://github.com/aappleby/smhasher) hash of the input value using the same seed as used by [GCC](https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/libstdc%2B%2B-v3/include/bits/functional_hash.h#L191).

It is portable between Clang and GCC builds.

**Syntax**

```sql
gccMurmurHash(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the calculated hash value of the input arguments. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT
    gccMurmurHash(1, 2, 3) AS res1,
    gccMurmurHash(('a', [1, 2, 3], 4, (4, ['foo', 'bar'], 1, (1, 2)))) AS res2
```

```text title=Response
┌─────────────────res1─┬────────────────res2─┐
│ 12384823029245979431 │ 1188926775431157506 │
└──────────────────────┴─────────────────────┘
```

*Introduced in version 20.1.0.*

halfMD5 [#halfmd5]

[Interprets](/reference/functions/regular-functions/type-conversion-functions#reinterpretAsString) all the input
parameters as strings and calculates the MD5 hash value for each of them. Then combines hashes, takes the first 8 bytes of the hash of the
resulting string, and interprets them as [UInt64](/reference/data-types/int-uint) in big-endian byte order. The function is
relatively slow (5 million short strings per second per processor core).

Consider using the [`sipHash64`](#sipHash64) function instead.

The function takes a variable number of input parameters.
Arguments can be any of the supported data types.
For some data types calculated value of hash function may be the same for the same values even if types of arguments differ (integers of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data).

**Syntax**

```sql
halfMD5(arg1[, arg2, ..., argN])
```

**Arguments**

* `arg1[, arg2, ..., argN]` — Variable number of arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed half MD5 hash of the given input params returned as a `UInt64` in big-endian byte order. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT HEX(halfMD5('abc', 'cde', 'fgh'));
```

```text title=Response
┌─hex(halfMD5('abc', 'cde', 'fgh'))─┐
│ 2C9506B7374CFAF4                  │
└───────────────────────────────────┘
```

*Introduced in version 1.1.0.*

hiveHash [#hivehash]

Calculates a "HiveHash" from a string.
This is just [`JavaHash`](#javaHash) with zeroed out sign bits.
This function is used in [Apache Hive](https://en.wikipedia.org/wiki/Apache_Hive) for versions before 3.0.

:::caution
This hash function is unperformant.
Use it only when this algorithm is already used in another system and you need to calculate the same result.
:::

**Syntax**

```sql
hiveHash(arg)
```

**Arguments**

* `arg` — Input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the computed "hive hash" of the input string. [`Int32`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT hiveHash('Hello, world!');
```

```text title=Response
┌─hiveHash('Hello, world!')─┐
│                 267439093 │
└───────────────────────────┘
```

*Introduced in version 20.1.0.*

icebergHash [#iceberghash]

Implements the logic of the iceberg [hashing transform](https://iceberg.apache.org/spec/#appendix-b-32-bit-hash-requirements)

**Syntax**

```sql
icebergHash(value)
```

**Arguments**

* `value` — Source value to take the hash of [`Integer`](/reference/data-types/int-uint) or [`Bool`](/reference/data-types/boolean) or [`Decimal`](/reference/data-types/decimal) or [`Float*`](/reference/data-types/float) or [`String`](/reference/data-types/string) or [`FixedString`](/reference/data-types/fixedstring) or [`UUID`](/reference/data-types/uuid) or [`Date`](/reference/data-types/date) or [`Time`](/reference/data-types/time) or [`DateTime`](/reference/data-types/datetime)

**Returned value**

Returns a 32-bit Murmur3 hash, x86 variant, seeded with 0 [`Int32`](/reference/data-types/int-uint)

**Examples**

**Example**

```sql title=Query
SELECT icebergHash(1.0 :: Float32)
```

```text title=Response
-142385009
```

*Introduced in version 25.5.0.*

intHash32 [#inthash32]

Calculates a 32-bit hash of an integer.

The hash function is relatively fast but not cryptographic hash function.

**Syntax**

```sql
intHash32(arg)
```

**Arguments**

* `arg` — Integer to hash. [`(U)Int*`](/reference/data-types/int-uint)

**Returned value**

Returns the computed 32-bit hash code of the input integer [`UInt32`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT intHash32(42);
```

```text title=Response
┌─intHash32(42)─┐
│    1228623923 │
└───────────────┘
```

*Introduced in version 1.1.0.*

intHash64 [#inthash64]

Calculates a 64-bit hash of an integer.

The hash function is relatively fast (even faster than [`intHash32`](#intHash32)) but not a cryptographic hash function.

**Syntax**

```sql
intHash64(int)
```

**Arguments**

* `int` — Integer to hash. [`(U)Int*`](/reference/data-types/int-uint)

**Returned value**

64-bit hash code. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT intHash64(42);
```

```text title=Response
┌────────intHash64(42)─┐
│ 11490350930367293593 │
└──────────────────────┘
```

*Introduced in version 1.1.0.*

javaHash [#javahash]

Calculates JavaHash from:

* [string](http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/String.java#l1452),
* [Byte](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Byte.java#l405),
* [Short](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Short.java#l410),
* [Integer](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Integer.java#l959),
* [Long](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Long.java#l1060).

:::caution
This hash function is unperformant.
Use it only when this algorithm is already in use in another system and you need to calculate the same result.
:::

:::note
Java only supports calculating the hash of signed integers,
so if you want to calculate a hash of unsigned integers you must cast them to the proper signed RawTree types.
:::

**Syntax**

```sql
javaHash(arg)
```

**Arguments**

* `arg` — Input value to hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed hash of `arg` [`Int32`](/reference/data-types/int-uint)

**Examples**

**Usage example 1**

```sql title=Query
SELECT javaHash(toInt32(123));
```

```text title=Response
┌─javaHash(toInt32(123))─┐
│               123      │
└────────────────────────┘
```

**Usage example 2**

```sql title=Query
SELECT javaHash('Hello, world!');
```

```text title=Response
┌─javaHash('Hello, world!')─┐
│               -1880044555 │
└───────────────────────────┘
```

*Introduced in version 20.1.0.*

javaHashUTF16LE [#javahashutf16le]

Calculates [JavaHash](http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/String.java#l1452) from a string, assuming it contains bytes representing a string in UTF-16LE encoding.

**Syntax**

```sql
javaHashUTF16LE(arg)
```

**Arguments**

* `arg` — A string in UTF-16LE encoding. [`String`](/reference/data-types/string)

**Returned value**

Returns the computed hash of the UTF-16LE encoded string. [`Int32`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT javaHashUTF16LE(convertCharset('test', 'utf-8', 'utf-16le'));
```

```text title=Response
┌─javaHashUTF16LE(convertCharset('test', 'utf-8', 'utf-16le'))─┐
│                                                      3556498 │
└──────────────────────────────────────────────────────────────┘
```

*Introduced in version 20.1.0.*

jumpConsistentHash [#jumpconsistenthash]

Calculates the [jump consistent hash](https://arxiv.org/pdf/1406.2294.pdf) for an integer.

**Syntax**

```sql
jumpConsistentHash(key, buckets)
```

**Arguments**

* `key` — The input key. [`UInt64`](/reference/data-types/int-uint)
* `buckets` — The number of buckets. [`Int32`](/reference/data-types/int-uint)

**Returned value**

Returns the computed hash value. [`Int32`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT jumpConsistentHash(256, 4)
```

```text title=Response
┌─jumpConsistentHash(256, 4)─┐
│                          3 │
└────────────────────────────┘
```

*Introduced in version 1.1.0.*

kafkaMurmurHash [#kafkamurmurhash]

Calculates the 32-bit [MurmurHash2](https://github.com/aappleby/smhasher) hash of the input value using the same seed as used by [Kafka](https://github.com/apache/kafka/blob/461c5cfe056db0951d9b74f5adc45973670404d7/clients/src/main/java/org/apache/kafka/common/utils/Utils.java#L482) and without the highest bit to be compatible with [Default Partitioner](https://github.com/apache/kafka/blob/139f7709bd3f5926901a21e55043388728ccca78/clients/src/main/java/org/apache/kafka/clients/producer/internals/BuiltInPartitioner.java#L328).

**Syntax**

```sql
kafkaMurmurHash(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of parameters for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the calculated hash value of the input arguments. [`UInt32`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT
    kafkaMurmurHash('foobar') AS res1,
    kafkaMurmurHash(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS res2
```

```text title=Response
┌───────res1─┬─────res2─┐
│ 1357151166 │ 85479775 │
└────────────┴──────────┘
```

*Introduced in version 23.4.0.*

keccak256 [#keccak256]

Calculates the Keccak-256 cryptographic hash of the given string.
This hash function is widely used in blockchain applications, particularly Ethereum.

**Syntax**

```sql
keccak256(message)
```

**Arguments**

* `message` — The input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the 32-byte Keccak-256 hash of the input string as a fixed-length string. [`FixedString(32)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT hex(keccak256('hello'))
```

```text title=Response
┌─hex(keccak256('hello'))──────────────────────────────────────────┐
│ 1C8AFF950685C2ED4BC3174F3472287B56D9517B9C948127319A09A7A36DEAC8 │
└──────────────────────────────────────────────────────────────────┘
```

*Introduced in version 25.4.0.*

kostikConsistentHash [#kostikconsistenthash]

An O(1) time and space consistent hash algorithm by Konstantin 'Kostik' Oblakov.
Only efficient with `n <= 32768`.

**Syntax**

```sql
kostikConsistentHash(input, n)
```

**Arguments**

* `input` — An integer key. [`UInt64`](/reference/data-types/int-uint)
* `n` — The number of buckets. [`UInt16`](/reference/data-types/int-uint)

**Returned value**

Returns the computed hash value. [`UInt16`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT kostikConsistentHash(16045690984833335023, 2);
```

```text title=Response
┌─kostikConsistentHash(16045690984833335023, 2)─┐
│                                             1 │
└───────────────────────────────────────────────┘
```

*Introduced in version 22.6.0.*

metroHash64 [#metrohash64]

Produces a 64-bit [MetroHash](http://www.jandrewrogers.com/2015/05/27/metrohash/) hash value.

:::note
The calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.
:::

**Syntax**

```sql
metroHash64(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed hash of the input arguments. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT metroHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MetroHash, toTypeName(MetroHash) AS type;
```

```text title=Response
┌────────────MetroHash─┬─type───┐
│ 14235658766382344533 │ UInt64 │
└──────────────────────┴────────┘
```

*Introduced in version 1.1.0.*

murmurHash2_32 [#murmurhash2_32]

Computes the [MurmurHash2](https://github.com/aappleby/smhasher) hash of the input value.

:::note
The calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.
:::

**Syntax**

```sql
murmurHash2_32(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed hash value of the input arguments. [`UInt32`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT murmurHash2_32(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash2, toTypeName(MurmurHash2) AS type;
```

```text title=Response
┌─MurmurHash2─┬─type───┐
│  3681770635 │ UInt32 │
└─────────────┴────────┘
```

*Introduced in version 18.5.0.*

murmurHash2_64 [#murmurhash2_64]

Computes the [MurmurHash2](https://github.com/aappleby/smhasher) hash of the input value.

:::note
The calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.
:::

**Syntax**

```sql
murmurHash2_64(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed hash of the input arguments. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT murmurHash2_64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash2, toTypeName(MurmurHash2) AS type;
```

```text title=Response
┌──────────MurmurHash2─┬─type───┐
│ 11832096901709403633 │ UInt64 │
└──────────────────────┴────────┘
```

*Introduced in version 18.10.0.*

murmurHash3_128 [#murmurhash3_128]

Computes the 128-bit [MurmurHash3](https://github.com/aappleby/smhasher) hash of the input value.

**Syntax**

```sql
murmurHash3_128(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed 128-bit `MurmurHash3` hash value of the input arguments. [`FixedString(16)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT hex(murmurHash3_128('foo', 'foo', 'foo'));
```

```text title=Response
┌─hex(murmurHash3_128('foo', 'foo', 'foo'))─┐
│ F8F7AD9B6CD4CF117A71E277E2EC2931          │
└───────────────────────────────────────────┘
```

*Introduced in version 18.10.0.*

murmurHash3_32 [#murmurhash3_32]

Produces a [MurmurHash3](https://github.com/aappleby/smhasher) hash value.

:::note
The calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.
:::

**Syntax**

```sql
murmurHash3_32(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed hash value of the input arguments. [`UInt32`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT murmurHash3_32(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash3, toTypeName(MurmurHash3) AS type;
```

```text title=Response
┌─MurmurHash3─┬─type───┐
│     2152717 │ UInt32 │
└─────────────┴────────┘
```

*Introduced in version 18.10.0.*

murmurHash3_64 [#murmurhash3_64]

Computes the [MurmurHash3](https://github.com/aappleby/smhasher) hash of the input value.

:::note
The calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.
:::

**Syntax**

```sql
murmurHash3_64(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed hash value of the input arguments. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT murmurHash3_64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash3, toTypeName(MurmurHash3) AS type;
```

```text title=Response
┌──────────MurmurHash3─┬─type───┐
│ 11832096901709403633 │ UInt64 │
└──────────────────────┴────────┘
```

*Introduced in version 18.10.0.*

ngramMinHash [#ngramminhash]

Splits a ASCII string into n-grams of `ngramsize` symbols and calculates hash values for each n-gram and returns a tuple with these hashes.
Uses `hashnum` minimum hashes to calculate the minimum hash and `hashnum` maximum hashes to calculate the maximum hash.
It is case sensitive.

Can be used to detect semi-duplicate strings with [`tupleHammingDistance`](/reference/functions/regular-functions/tuple-functions#tupleHammingDistance).
For two strings, if the returned hashes are the same for both strings, then those strings are the same.

**Syntax**

```sql
ngramMinHash(string[, ngramsize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two hashes — the minimum and the maximum. [`Tuple`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramMinHash('ClickHouse') AS Tuple;
```

```text title=Response
┌─Tuple──────────────────────────────────────┐
│ (18333312859352735453,9054248444481805918) │
└────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

ngramMinHashArg [#ngramminhasharg]

Splits a ASCII string into n-grams of `ngramsize` symbols and returns the n-grams with minimum and maximum hashes, calculated by the [`ngramMinHash`](#ngramMinHash) function with the same input.
It is case sensitive.

**Syntax**

```sql
ngramMinHashArg(string[, ngramsize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` n-grams each. [`Tuple(String)`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramMinHashArg('ClickHouse') AS Tuple;
```

```text title=Response
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','Hou','kHo','use'),('Hou','lic','ick','ous','ckH','Cli')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

ngramMinHashArgCaseInsensitive [#ngramminhashargcaseinsensitive]

Splits a ASCII string into n-grams of `ngramsize` symbols and returns the n-grams with minimum and maximum hashes, calculated by the [`ngramMinHashCaseInsensitive`](#ngramMinHashCaseInsensitive) function with the same input.
It is case insensitive.

**Syntax**

```sql
ngramMinHashArgCaseInsensitive(string[, ngramsize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` n-grams each. [`Tuple(Tuple(String))`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramMinHashArgCaseInsensitive('ClickHouse') AS Tuple;
```

```text title=Response
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','kHo','use','Cli'),('kHo','lic','ick','ous','ckH','Hou')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

ngramMinHashArgCaseInsensitiveUTF8 [#ngramminhashargcaseinsensitiveutf8]

Splits a UTF-8 string into n-grams of `ngramsize` symbols and returns the n-grams with minimum and maximum hashes, calculated by the ngramMinHashCaseInsensitiveUTF8 function with the same input.
It is case insensitive.

**Syntax**

```sql
ngramMinHashArgCaseInsensitiveUTF8(string[, ngramsize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` n-grams each. [`Tuple(Tuple(String))`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramMinHashArgCaseInsensitiveUTF8('ClickHouse') AS Tuple;
```

```text title=Response
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ckH','ous','ick','lic','kHo','use'),('kHo','lic','ick','ous','ckH','Hou')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

ngramMinHashArgUTF8 [#ngramminhashargutf8]

Splits a UTF-8 string into n-grams of `ngramsize` symbols and returns the n-grams with minimum and maximum hashes, calculated by the `ngramMinHashUTF8` function with the same input.
It is case sensitive.

**Syntax**

```sql
ngramMinHashArgUTF8(string[, ngramsize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` n-grams each. [`Tuple(Tuple(String))`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramMinHashArgUTF8('ClickHouse') AS Tuple;
```

```text title=Response
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','Hou','kHo','use'),('kHo','Hou','lic','ick','ous','ckH')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

ngramMinHashCaseInsensitive [#ngramminhashcaseinsensitive]

Splits a ASCII string into n-grams of `ngramsize` symbols and calculates hash values for each n-gram and returns a tuple with these hashes
Uses `hashnum` minimum hashes to calculate the minimum hash and `hashnum` maximum hashes to calculate the maximum hash.
It is case insensitive.

Can be used to detect semi-duplicate strings with [`tupleHammingDistance`](/reference/functions/regular-functions/tuple-functions#tupleHammingDistance).
For two strings, if the returned hashes are the same for both strings, then those strings are the same.

**Syntax**

```sql
ngramMinHashCaseInsensitive(string[, ngramsize, hashnum])
```

**Arguments**

* `string` — String. [String](/reference/data-types/string). - `ngramsize` — The size of an n-gram. Optional. Possible values: any number from `1` to `25`. Default value: `3`. [UInt8](/reference/data-types/int-uint). - `hashnum` — The number of minimum and maximum hashes used to calculate the result. Optional. Possible values: any number from `1` to `25`. Default value: `6`. [UInt8](/reference/data-types/int-uint).

**Returned value**

Tuple with two hashes — the minimum and the maximum. [Tuple](/reference/data-types/tuple)([UInt64](/reference/data-types/int-uint), [UInt64](/reference/data-types/int-uint)). [`Tuple`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramMinHashCaseInsensitive('ClickHouse') AS Tuple;
```

```text title=Response
┌─Tuple──────────────────────────────────────┐
│ (2106263556442004574,13203602793651726206) │
└────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

ngramMinHashCaseInsensitiveUTF8 [#ngramminhashcaseinsensitiveutf8]

Splits a UTF-8 string into n-grams of `ngramsize` symbols and calculates hash values for each n-gram and returns a tuple with these hashes..
Uses `hashnum` minimum hashes to calculate the minimum hash and `hashnum` maximum hashes to calculate the maximum hash.
It is case insensitive.

Can be used to detect semi-duplicate strings with [`tupleHammingDistance`](/reference/functions/regular-functions/tuple-functions#tupleHammingDistance).
For two strings, if the returned hashes are the same for both strings, then those strings are the same.

**Syntax**

```sql
ngramMinHashCaseInsensitiveUTF8(string [, ngramsize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two hashes — the minimum and the maximum. [`Tuple`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramMinHashCaseInsensitiveUTF8('ClickHouse') AS Tuple;
```

```text title=Response
┌─Tuple───────────────────────────────────────┐
│ (12493625717655877135,13203602793651726206) │
└─────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

ngramMinHashUTF8 [#ngramminhashutf8]

Splits a UTF-8 string into n-grams of `ngramsize` symbols and calculates hash values for each n-gram and returns a tuple with these hashes.
Uses `hashnum` minimum hashes to calculate the minimum hash and `hashnum` maximum hashes to calculate the maximum hash.
It is case sensitive.

Can be used to detect semi-duplicate strings with [`tupleHammingDistance`](/reference/functions/regular-functions/tuple-functions#tupleHammingDistance).
For two strings, if the returned hashes are the same for both strings, then those strings are the same.

**Syntax**

```sql
ngramMinHashUTF8(string[, ngramsize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two hashes — the minimum and the maximum. [`Tuple`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramMinHashUTF8('ClickHouse') AS Tuple;
```

```text title=Response
┌─Tuple──────────────────────────────────────┐
│ (18333312859352735453,6742163577938632877) │
└────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

ngramSimHash [#ngramsimhash]

Splits a ASCII string into n-grams of `ngramsize` symbols and returns the n-gram `simhash`.

Can be used for detection of semi-duplicate strings with [`bitHammingDistance`](/reference/functions/regular-functions/bit-functions#bitHammingDistance).
The smaller the [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) of the calculated `simhashes` of two strings, the more likely these strings are the same.

**Syntax**

```sql
ngramSimHash(string[, ngramsize])
```

**Arguments**

* `string` — String for which to compute the case sensitive `simhash`. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is`3`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns the computed hash of the input string. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramSimHash('ClickHouse') AS Hash;
```

```text title=Response
┌───────Hash─┐
│ 1627567969 │
└────────────┘
```

*Introduced in version 21.1.0.*

ngramSimHashCaseInsensitive [#ngramsimhashcaseinsensitive]

Splits a ASCII string into n-grams of `ngramsize` symbols and returns the n-gram `simhash`.
It is case insensitive.

Can be used for detection of semi-duplicate strings with [`bitHammingDistance`](/reference/functions/regular-functions/bit-functions#bitHammingDistance).
The smaller the [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) of the calculated `simhashes` of two strings, the more likely these strings are the same.

**Syntax**

```sql
ngramSimHashCaseInsensitive(string[, ngramsize])
```

**Arguments**

* `string` — String for which to compute the case insensitive `simhash`. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Hash value. [UInt64](/reference/data-types/int-uint). [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramSimHashCaseInsensitive('ClickHouse') AS Hash;
```

```text title=Response
┌──────Hash─┐
│ 562180645 │
└───────────┘
```

*Introduced in version 21.1.0.*

ngramSimHashCaseInsensitiveUTF8 [#ngramsimhashcaseinsensitiveutf8]

Splits a UTF-8 string into n-grams of `ngramsize` symbols and returns the n-gram `simhash`.
It is case insensitive.

Can be used for detection of semi-duplicate strings with [bitHammingDistance](/reference/functions/regular-functions/bit-functions#bitHammingDistance). The smaller is the [Hamming Distance](https://en.wikipedia.org/wiki/Hamming_distance) of the calculated `simhashes` of two strings, the more likely these strings are the same.

**Syntax**

```sql
ngramSimHashCaseInsensitiveUTF8(string[, ngramsize])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns the computed hash value. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramSimHashCaseInsensitiveUTF8('ClickHouse') AS Hash;
```

```text title=Response
┌───────Hash─┐
│ 1636742693 │
└────────────┘
```

*Introduced in version 21.1.0.*

ngramSimHashUTF8 [#ngramsimhashutf8]

Splits a UTF-8 encoded string into n-grams of `ngramsize` symbols and returns the n-gram `simhash`.
It is case sensitive.

Can be used for detection of semi-duplicate strings with [`bitHammingDistance`](/reference/functions/regular-functions/bit-functions#bitHammingDistance).
The smaller the [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) of the calculated `simhashes` of two strings, the more likely these strings are the same.

**Syntax**

```sql
ngramSimHashUTF8(string[, ngramsize])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns the computed hash value. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT ngramSimHashUTF8('ClickHouse') AS Hash;
```

```text title=Response
┌───────Hash─┐
│ 1628157797 │
└────────────┘
```

*Introduced in version 21.1.0.*

sipHash128 [#siphash128]

Like [`sipHash64`](#sipHash64) but produces a 128-bit hash value, i.e. the final xor-folding state is done up to 128 bits.

:::tip use sipHash128Reference for new projects
This 128-bit variant differs from the reference implementation and is weaker.
This version exists because, when it was written, there was no official 128-bit extension for SipHash.
New projects are advised to use [`sipHash128Reference`](#sipHash128Reference).
:::

**Syntax**

```sql
sipHash128(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns a 128-bit `SipHash` hash value. [`FixedString(16)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT hex(sipHash128('foo', '\x01', 3));
```

```text title=Response
┌─hex(sipHash128('foo', '', 3))────┐
│ 9DE516A64A414D4B1B609415E4523F24 │
└──────────────────────────────────┘
```

*Introduced in version 1.1.0.*

sipHash128Keyed [#siphash128keyed]

Same as [`sipHash128`](#sipHash128) but additionally takes an explicit key argument instead of using a fixed key.

:::tip use sipHash128ReferenceKeyed for new projects
This 128-bit variant differs from the reference implementation and it's weaker.
This version exists because, when it was written, there was no official 128-bit extension for SipHash.
New projects should probably use [`sipHash128ReferenceKeyed`](#sipHash128ReferenceKeyed).
:::

**Syntax**

```sql
sipHash128Keyed((k0, k1), [arg1, arg2, ...])
```

**Arguments**

* `(k0, k1)` — A tuple of two UInt64 values representing the key. [`Tuple(UInt64, UInt64)`](/reference/data-types/tuple)
* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

A 128-bit `SipHash` hash value of type [FixedString(16)](/reference/data-types/fixedstring). [`FixedString(16)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT hex(sipHash128Keyed((506097522914230528, 1084818905618843912),'foo', '\x01', 3));
```

```text title=Response
┌─hex(sipHash128Keyed((506097522914230528, 1084818905618843912), 'foo', '', 3))─┐
│ B8467F65C8B4CFD9A5F8BD733917D9BF                                              │
└───────────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 23.2.0.*

sipHash128Reference [#siphash128reference]

Like [`sipHash128`](/reference/functions/regular-functions/hash-functions#sipHash128) but implements the 128-bit algorithm from the original authors of SipHash.

**Syntax**

```sql
sipHash128Reference(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed 128-bit `SipHash` hash value of the input arguments. [`FixedString(16)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT hex(sipHash128Reference('foo', '', 3));
```

```text title=Response
┌─hex(sipHash128Reference('foo', '', 3))─┐
│ 4D1BE1A22D7F5933C0873E1698426260       │
└────────────────────────────────────────┘
```

*Introduced in version 23.2.0.*

sipHash128ReferenceKeyed [#siphash128referencekeyed]

Same as [`sipHash128Reference`](#sipHash128Reference) but additionally takes an explicit key argument instead of using a fixed key.

**Syntax**

```sql
sipHash128ReferenceKeyed((k0, k1), arg1[, arg2, ...])
```

**Arguments**

* `(k0, k1)` — Tuple of two values representing the key [`Tuple(UInt64, UInt64)`](/reference/data-types/tuple)
* `arg1[, arg2, ...]` — A variable number of input arguments for which to compute the hash. [`Any`](/reference/data-types)

**Returned value**

Returns the computed 128-bit `SipHash` hash value of the input arguments. [`FixedString(16)`](/reference/data-types/fixedstring)

**Examples**

**Usage example**

```sql title=Query
SELECT hex(sipHash128Reference('foo', '', 3));
```

```text title=Response
┌─hex(sipHash128Reference('foo', '', 3))─┐
│ 4D1BE1A22D7F5933C0873E1698426260       │
└────────────────────────────────────────┘
```

*Introduced in version 23.2.0.*

sipHash64 [#siphash64]

Produces a 64-bit [SipHash](https://en.wikipedia.org/wiki/SipHash) hash value.

This is a cryptographic hash function. It works at least three times faster than the [`MD5`](#MD5) hash function.

The function [interprets](/reference/functions/regular-functions/type-conversion-functions#reinterpretAsString) all the input parameters as strings and calculates the hash value for each of them.
It then combines the hashes using the following algorithm:

1. The first and the second hash value are concatenated to an array which is hashed.
2. The previously calculated hash value and the hash of the third input parameter are hashed in a similar way.
3. This calculation is repeated for all remaining hash values of the original input.

:::note
the calculated hash values may be equal for the same input values of different argument types.
This affects for example integer types of different size, named and unnamed `Tuple` with the same data, `Map` and the corresponding `Array(Tuple(key, value))` type with the same data.
:::

**Syntax**

```sql
sipHash64(arg1[, arg2, ...])
```

**Arguments**

* `arg1[, arg2, ...]` — A variable number of input arguments. [`Any`](/reference/data-types)

**Returned value**

Returns a computed hash value of the input arguments. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT sipHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS SipHash, toTypeName(SipHash) AS type;
```

```text title=Response
┌──────────────SipHash─┬─type───┐
│ 11400366955626497465 │ UInt64 │
└──────────────────────┴────────┘
```

*Introduced in version 1.1.0.*

sipHash64Keyed [#siphash64keyed]

Like [`sipHash64`](#sipHash64) but additionally takes an explicit key argument instead of using a fixed key.

**Syntax**

```sql
sipHash64Keyed((k0, k1), arg1[,arg2, ...])
```

**Arguments**

* `(k0, k1)` — A tuple of two values representing the key. [`Tuple(UInt64, UInt64)`](/reference/data-types/tuple)
* `arg1[,arg2, ...]` — A variable number of input arguments. [`Any`](/reference/data-types)

**Returned value**

Returns the computed hash of the input values. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT sipHash64Keyed((506097522914230528, 1084818905618843912), array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS SipHash, toTypeName(SipHash) AS type;
```

```text title=Response
┌─────────────SipHash─┬─type───┐
│ 8017656310194184311 │ UInt64 │
└─────────────────────┴────────┘
```

*Introduced in version 23.2.0.*

wordShingleMinHash [#wordshingleminhash]

Splits a ASCII string into parts (shingles) of `shinglesize` words, calculates hash values for each word shingle and returns a tuple with these hashes.
Uses `hashnum` minimum hashes to calculate the minimum hash and `hashnum` maximum hashes to calculate the maximum hash.
It is case sensitive.

Can be used to detect semi-duplicate strings with [`tupleHammingDistance`](/reference/functions/regular-functions/tuple-functions#tupleHammingDistance).
For two strings, if the returned hashes are the same for both strings, then those strings are the same.

**Syntax**

```sql
wordShingleMinHash(string[, shinglesize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two hashes — the minimum and the maximum. [`Tuple(UInt64, UInt64)`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleMinHash('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
```

```text title=Response
┌─Tuple──────────────────────────────────────┐
│ (16452112859864147620,5844417301642981317) │
└────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

wordShingleMinHashArg [#wordshingleminhasharg]

Splits a ASCII string into parts (shingles) of `shinglesize` words each and returns the shingles with minimum and maximum word hashes, calculated by the wordShingleMinHash function with the same input.
It is case sensitive.

**Syntax**

```sql
wordShingleMinHashArg(string[, shinglesize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` word shingles each. [`Tuple(Tuple(String))`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleMinHashArg('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
```

```text title=Response
┌─Tuple─────────────────────────────────────────────────────────────────┐
│ (('OLAP','database','analytical'),('online','oriented','processing')) │
└───────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 1.1.0.*

wordShingleMinHashArgCaseInsensitive [#wordshingleminhashargcaseinsensitive]

Splits a ASCII string into parts (shingles) of `shinglesize` words each and returns the shingles with minimum and maximum word hashes, calculated by the [`wordShingleMinHashCaseInsensitive`](#wordShingleMinHashCaseInsensitive) function with the same input.
It is case insensitive.

**Syntax**

```sql
wordShingleMinHashArgCaseInsensitive(string[, shinglesize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` word shingles each. [`Tuple(Tuple(String))`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleMinHashArgCaseInsensitive('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
```

```text title=Response
┌─Tuple──────────────────────────────────────────────────────────────────┐
│ (('queries','database','analytical'),('oriented','processing','DBMS')) │
└────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

wordShingleMinHashArgCaseInsensitiveUTF8 [#wordshingleminhashargcaseinsensitiveutf8]

Splits a UTF-8 string into parts (shingles) of `shinglesize` words each and returns the shingles with minimum and maximum word hashes, calculated by the [`wordShingleMinHashCaseInsensitiveUTF8`](#wordShingleMinHashCaseInsensitiveUTF8) function with the same input.
It is case insensitive.

**Syntax**

```sql
wordShingleMinHashArgCaseInsensitiveUTF8(string[, shinglesize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` word shingles each. [`Tuple(Tuple(String))`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleMinHashArgCaseInsensitiveUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
```

```text title=Response
┌─Tuple──────────────────────────────────────────────────────────────────┐
│ (('queries','database','analytical'),('oriented','processing','DBMS')) │
└────────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

wordShingleMinHashArgUTF8 [#wordshingleminhashargutf8]

Splits a UTF-8 string into parts (shingles) of `shinglesize` words each and returns the shingles with minimum and maximum word hashes, calculated by the [`wordShingleMinHashUTF8`](#wordShingleMinHashUTF8) function with the same input.
It is case sensitive.

**Syntax**

```sql
wordShingleMinHashArgUTF8(string[, shinglesize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` word shingles each. [`Tuple(Tuple(String))`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleMinHashArgUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
```

```text title=Response
┌─Tuple─────────────────────────────────────────────────────────────────┐
│ (('OLAP','database','analytical'),('online','oriented','processing')) │
└───────────────────────────────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

wordShingleMinHashCaseInsensitive [#wordshingleminhashcaseinsensitive]

Splits a ASCII string into parts (shingles) of `shinglesize` words, calculates hash values for each word shingle and returns a tuple with these hashes.
Uses `hashnum` minimum hashes to calculate the minimum hash and `hashnum` maximum hashes to calculate the maximum hash.
It is case insensitive.

Can be used to detect semi-duplicate strings with [`tupleHammingDistance`](/reference/functions/regular-functions/tuple-functions#tupleHammingDistance).
For two strings, if the returned hashes are the same for both strings, then those strings are the same.

**Syntax**

```sql
wordShingleMinHashCaseInsensitive(string[, shinglesize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two hashes — the minimum and the maximum. [`Tuple(UInt64, UInt64)`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleMinHashCaseInsensitive('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
```

```text title=Response
┌─Tuple─────────────────────────────────────┐
│ (3065874883688416519,1634050779997673240) │
└───────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

wordShingleMinHashCaseInsensitiveUTF8 [#wordshingleminhashcaseinsensitiveutf8]

Splits a UTF-8 string into parts (shingles) of `shinglesize` words, calculates hash values for each word shingle and returns a tuple with these hashes.
Uses `hashnum` minimum hashes to calculate the minimum hash and `hashnum` maximum hashes to calculate the maximum hash.
It is case insensitive.

Can be used to detect semi-duplicate strings with [`tupleHammingDistance`](/reference/functions/regular-functions/tuple-functions#tupleHammingDistance).
For two strings, if the returned hashes are the same for both strings, then those strings are the same.

**Syntax**

```sql
wordShingleMinHashCaseInsensitiveUTF8(string[, shinglesize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two hashes — the minimum and the maximum. [`Tuple(UInt64, UInt64)`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleMinHashCaseInsensitiveUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
```

```text title=Response
┌─Tuple─────────────────────────────────────┐
│ (3065874883688416519,1634050779997673240) │
└───────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

wordShingleMinHashUTF8 [#wordshingleminhashutf8]

Splits a UTF-8 string into parts (shingles) of `shinglesize` words, calculates hash values for each word shingle and returns a tuple with these hashes.
Uses `hashnum` minimum hashes to calculate the minimum hash and `hashnum` maximum hashes to calculate the maximum hash.
It is case sensitive.

Can be used to detect semi-duplicate strings with [`tupleHammingDistance`](/reference/functions/regular-functions/tuple-functions#tupleHammingDistance).
For two strings, if the returned hashes are the same for both strings, then those strings are the same.

**Syntax**

```sql
wordShingleMinHashUTF8(string[, shinglesize, hashnum])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)
* `hashnum` — Optional. The number of minimum and maximum hashes used to calculate the result, any number from `1` to `25`. The default value is `6`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns a tuple with two hashes — the minimum and the maximum. [`Tuple(UInt64, UInt64)`](/reference/data-types/tuple)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleMinHashUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
```

```text title=Response
┌─Tuple──────────────────────────────────────┐
│ (16452112859864147620,5844417301642981317) │
└────────────────────────────────────────────┘
```

*Introduced in version 21.1.0.*

wordShingleSimHash [#wordshinglesimhash]

Splits a ASCII string into parts (shingles) of `shinglesize` words and returns the word shingle `simhash`.
Is is case sensitive.

Can be used for detection of semi-duplicate strings with [`bitHammingDistance`](/reference/functions/regular-functions/bit-functions#bitHammingDistance).
The smaller the [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) of the calculated `simhashes` of two strings, the more likely these strings are the same.

**Syntax**

```sql
wordShingleSimHash(string[, shinglesize])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns the computed hash value. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleSimHash('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
```

```text title=Response
┌───────Hash─┐
│ 2328277067 │
└────────────┘
```

*Introduced in version 21.1.0.*

wordShingleSimHashCaseInsensitive [#wordshinglesimhashcaseinsensitive]

Splits a ASCII string into parts (shingles) of `shinglesize` words and returns the word shingle `simhash`.
It is case insensitive.

Can be used for detection of semi-duplicate strings with [`bitHammingDistance`](/reference/functions/regular-functions/bit-functions#bitHammingDistance).
The smaller the [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) of the calculated `simhashes` of two strings, the more likely these strings are the same.

**Syntax**

```sql
wordShingleSimHashCaseInsensitive(string[, shinglesize])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns the computed hash value. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleSimHashCaseInsensitive('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
```

```text title=Response
┌───────Hash─┐
│ 2194812424 │
└────────────┘
```

*Introduced in version 21.1.0.*

wordShingleSimHashCaseInsensitiveUTF8 [#wordshinglesimhashcaseinsensitiveutf8]

Splits a UTF-8 encoded string into parts (shingles) of `shinglesize` words and returns the word shingle `simhash`.
It is case insensitive.

Can be used for detection of semi-duplicate strings with [`bitHammingDistance`](/reference/functions/regular-functions/bit-functions#bitHammingDistance).
The smaller the [Hamming Distance](https://en.wikipedia.org/wiki/Hamming_distance) of the calculated `simhashes` of two strings, the more likely these strings are the same.

**Syntax**

```sql
wordShingleSimHashCaseInsensitiveUTF8(string[, shinglesize])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns the computed hash value. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleSimHashCaseInsensitiveUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
```

```text title=Response
┌───────Hash─┐
│ 2194812424 │
└────────────┘
```

*Introduced in version 1.1.0.*

wordShingleSimHashUTF8 [#wordshinglesimhashutf8]

Splits a UTF-8 string into parts (shingles) of `shinglesize` words and returns the word shingle `simhash`.
It is case sensitive.

Can be used for detection of semi-duplicate strings with [`bitHammingDistance`](/reference/functions/regular-functions/bit-functions#bitHammingDistance).
The smaller the [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) of the calculated `simhashes` of two strings, the more likely these strings are the same.

**Syntax**

```sql
wordShingleSimHashUTF8(string[, shinglesize])
```

**Arguments**

* `string` — String for which to compute the hash. [`String`](/reference/data-types/string)
* `shinglesize` — Optional. The size of a word shingle, any number from `1` to `25`. The default value is `3`. [`UInt8`](/reference/data-types/int-uint)

**Returned value**

Returns the computed hash value. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT wordShingleSimHashUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
```

```text title=Response
┌───────Hash─┐
│ 2328277067 │
└────────────┘
```

*Introduced in version 21.1.0.*

wyHash64 [#wyhash64]

Computes a 64-bit [wyHash64](https://github.com/wangyi-fudan/wyhash) hash value.

**Syntax**

```sql
wyHash64(arg)
```

**Arguments**

* `arg` — String argument for which to compute the hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the computed 64-bit hash value [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT wyHash64('ClickHouse') AS Hash;
```

```text title=Response
12336419557878201794
```

*Introduced in version 22.7.0.*

xxHash32 [#xxhash32]

Calculates a [xxHash](http://cyan4973.github.io/xxHash/) from a string.

For the 64-bit version see [`xxHash64`](#xxHash64)

**Syntax**

```sql
xxHash32(arg)
```

**Arguments**

* `arg` — Input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the computed 32-bit hash of the input string. [`UInt32`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT xxHash32('Hello, world!');
```

```text title=Response
┌─xxHash32('Hello, world!')─┐
│                 834093149 │
└───────────────────────────┘
```

*Introduced in version 20.1.0.*

xxHash64 [#xxhash64]

Calculates a [xxHash](http://cyan4973.github.io/xxHash/) from a string.

For the 32-bit version see [`xxHash32`](#xxHash32)

**Syntax**

```sql
xxHash64(arg)
```

**Arguments**

* `arg` — Input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the computed 64-bit hash of the input string. [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT xxHash64('Hello, world!');
```

```text title=Response
┌─xxHash64('Hello, world!')─┐
│      17691043854468224118 │
└───────────────────────────┘
```

*Introduced in version 20.1.0.*

xxHash64Spark [#xxhash64spark]

Calculates a [xxHash](http://cyan4973.github.io/xxHash/) from a string using the same seed as Spark.

This function is the same as [`xxHash64`](#xxHash64), but it uses seed `42` and returns the result as `Int64`.
Only `String` and `NULL` inputs are supported.
For `NULL`, the function returns `42`, matching Spark's seed behavior.

**Syntax**

```sql
xxHash64Spark(arg)
```

**Arguments**

* `arg` — Input string to hash. [`String`](/reference/data-types/string)

**Returned value**

Returns the computed 64-bit hash of the input string. [`Int64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT xxHash64Spark('ABC');
```

```text title=Response
┌─xxHash64Spark('ABC')─┐
│  4105715581806190027 │
└──────────────────────┘
```

*Introduced in version 26.7.0.*

xxh3 [#xxh3]

Computes a [XXH3](https://github.com/Cyan4973/xxHash) 64-bit hash value.

**Syntax**

```sql
xxh3(expr)
```

**Arguments**

* `expr` — A list of expressions of any data type. [`Any`](/reference/data-types)

**Returned value**

Returns the computed 64-bit `xxh3` hash value [`UInt64`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT xxh3('ClickHouse')
```

```text title=Response
18009318874338624809
```

*Introduced in version 22.12.0.*

xxh3_128 [#xxh3_128]

Computes a [XXH3](https://github.com/Cyan4973/xxHash) 128-bit hash value.

**Syntax**

```sql
xxh3_128(expr)
```

**Arguments**

* `expr` — A list of expressions of any data type. [`Any`](/reference/data-types)

**Returned value**

Returns the computed 128-bit `xxh3` hash value [`UInt128`](/reference/data-types/int-uint)

**Examples**

**Usage example**

```sql title=Query
SELECT hex(xxh3_128('ClickHouse'))
```

```text title=Response
3A038784C52804B4DBA43A038784C528
```

*Introduced in version 26.2.0.*
