HAMMING_DISTANCE
All functions > STRING > HAMMING_DISTANCE
Returns the Hamming distance between two strings of equal length.
Signatures
Returns: Number of positions at which the corresponding characters differ
HAMMING_DISTANCE(string1: VARCHAR, string2: VARCHAR) → BIGINT sql
| Parameter | Type | Required | Description |
|---|---|---|---|
string1 | VARCHAR | Yes | First string to compare |
string2 | VARCHAR | Yes | Second string to compare |
Notes
- Both strings must be of equal length
- Case-sensitive comparison
- Returns the count of differing positions
- Useful for comparing binary strings or DNA sequences
Examples
FeatureQL
SELECT
f1 := HAMMING_DISTANCE('karolin', 'kathrin'), -- 3 characters differ
f2 := HAMMING_DISTANCE('karolin', 'kerstin'), -- 3 characters differ
f3 := HAMMING_DISTANCE('1011101', '1001001'), -- 2 bits differ
f4 := HAMMING_DISTANCE('ABC', 'ABC'), -- Identical strings
f5 := HAMMING_DISTANCE('abc', 'ABC') -- Case-sensitive
;Result
| f1 BIGINT | f2 BIGINT | f3 BIGINT | f4 BIGINT | f5 BIGINT |
|---|---|---|---|---|
| 3 | 3 | 2 | 0 | 3 |
On this page