---
title: "hamming function in Strata | Oplema"
description: "Calculate the Hamming distance between two strings: the number of positions where their characters differ. For example, hamming('duck', 'luck') returns 1."
url: "https://oplema.com/docs/strata/functions/hamming"
updated: "2026-11-04"
---

# hamming

Calculate the Hamming distance between two strings: the number of positions where their characters differ. Both strings must have the same length, and uppercase and lowercase letters count as different.

Also available as mismatches.

## Try an expression

In [Formula](https://oplema.com/docs/strata/prep/formula), enter the expression and set Output type to **BIGINT**.

### Expression

```
hamming('duck', 'luck')
```

### Result

```
1
```

To use your own data, replace the example values with column names. Keep format strings and other options as written.

Try it live in Formula

Result
| id | result |
| --- | --- |
| 1 | 1 |

## Arguments and types

```
hamming(s1, s2)
```

**s1**

Text

**s2**

Text

Supported signatures (1)

```
hamming(s1: VARCHAR, s2: VARCHAR) → BIGINT
```

The result type can depend on the input types. See DuckDB for the full argument rules.

## Things to know

If the first argument is missing, the result is NULL.

## Related functions

[jaccard

Score how similar two strings are by the characters they share, from 0 to 1. Uppercase and lowercase letters count as different.

](https://oplema.com/docs/strata/functions/jaccard)[jaro\_similarity

The Jaro similarity between two strings. Characters of different cases (e.g., a and A) are considered different. Returns a number between 0 and 1. For similarity < score\_cutoff, 0 is returned instead. score\_cutoff defaults to 0.

](https://oplema.com/docs/strata/functions/jaro-similarity)[jaro\_winkler\_similarity

The Jaro-Winkler similarity between two strings. Characters of different cases (e.g., a and A) are considered different. Returns a number between 0 and 1. For similarity < score\_cutoff, 0 is returned instead. score\_cutoff defaults to 0.

](https://oplema.com/docs/strata/functions/jaro-winkler-similarity)[damerau\_levenshtein

Count the edits needed to turn one string into another, like levenshtein, but swapping two neighboring characters counts as one edit. Uppercase and lowercase letters count as different.

](https://oplema.com/docs/strata/functions/damerau-levenshtein)

[Browse text](https://oplema.com/docs/strata/functions#text) [DuckDB documentation](https://duckdb.org/docs/current/sql/functions/text.html#hammings1-s2)

Function metadata from DuckDB, used under the [MIT license](https://github.com/duckdb/duckdb/blob/v1.5.4/LICENSE).
