Skip to content

xxHash functions in the Hashfuncs DuckDB extension

Sample data for the examples

Each browser example starts with these sample tables; sample files are shared across examples on this page. Run this setup first when trying the examples in your own DuckDB session.

-- Fixtures for the hashfuncs cookbook / technical-details examples.
--
-- The hashfuncs extension itself is pure CPU (no catalog, no network),
-- so these fixtures only exist to satisfy the *table references* the
-- documentation makes ("FROM events", "FROM users", ...). The numbers
-- chosen are tiny and deterministic so re-running the suite is stable.
--
-- Idempotent: every CREATE uses OR REPLACE.

-- The bitfilters cookbook section pairs hashfuncs with the bitfilters
-- extension. Load it best-effort so xor8_filter / xor8_filter_contains
-- resolve at parse time. If the community binary isn't available on the
-- current platform we still want the rest of the fixtures to apply.
INSTALL bitfilters FROM query_farm;
LOAD bitfilters FROM query_farm;

-- cookbook.mdx — "Hash partitioning" and "Independent hashes via seeds"
CREATE OR REPLACE TABLE users AS
SELECT i AS user_id
FROM range(0, 8) t(i);

-- cookbook.mdx — "Cross-system routing (Cassandra / Spark)"
CREATE OR REPLACE TABLE rows_to_route AS
SELECT 'k' || i::VARCHAR AS key
FROM range(0, 4) t(i);

-- cookbook.mdx — "String cache keys"
CREATE OR REPLACE TABLE query_log AS
SELECT i AS user_id,
       'select ' || i::VARCHAR AS query_text
FROM range(0, 4) t(i);

-- cookbook.mdx — "Bloom / XOR / Cuckoo filter input"
CREATE OR REPLACE TABLE allowed_users AS
SELECT 'user' || i::VARCHAR || '@example.com' AS email
FROM range(0, 4) t(i);

-- cookbook.mdx — second bitfilters block reads from `filter_table f`
-- (a one-row table holding a pre-built xor8 filter).
CREATE OR REPLACE TABLE filter_table AS
SELECT xor8_filter(xxh3_64(email)) AS filter
FROM allowed_users;

-- cookbook.mdx — "Independent hashes via seeds" uses `FROM keys`
CREATE OR REPLACE TABLE keys AS
SELECT 'k' || i::VARCHAR AS key
FROM range(0, 4) t(i);

-- cookbook.mdx + technical-details.mdx — "events" with event_id, payload
-- Used by sharding / dedup / "magic moment" examples.
CREATE OR REPLACE TABLE events AS
SELECT i AS event_id,
       'evt-' || i::VARCHAR AS payload,
       'user' || i::VARCHAR || '@example.com' AS email
FROM range(0, 8) t(i);

-- technical-details.mdx — "double-hash with two seeds" reads `FROM data`
CREATE OR REPLACE TABLE data AS
SELECT 'k' || i::VARCHAR AS key
FROM range(0, 4) t(i);

Function category

xxHash

5 functions

xxh3_128

Scalar function xxHash
Signature
2 overloaded forms · click to inspect
Arguments (Positional)
Argument value Type ANY Mode Positional Description
Description
1 128-bit hash
SELECT xxh3_128('hello world');

Output

xxh3_128('hello world')
225447084758876380551077147957698971904
2 Seeded
SELECT xxh3_128('hello world', 42);

Output

xxh3_128('hello world', 42)
173805935617512661584987041130904516770

xxh3_128_hex

Scalar function xxHash
Signature
2 overloaded forms · click to inspect
Arguments (Positional)
Argument value Type VARCHAR | BLOB
2 concrete types
BLOBVARCHAR
Mode Positional Description
Description
1 32-char hex digest
SELECT xxh3_128_hex('hello');

Output

xxh3_128_hex('hello')
b5e9c1ad071b3e7fc779cfaa5e523818
2 Seeded variant
SELECT xxh3_128_hex('hello', 42);

Output

xxh3_128_hex('hello', 42)
6ce89a0bdba81f088c2f5b7e4cd59e16

xxh3_64

Scalar function xxHash
Signature
2 overloaded forms · click to inspect
Arguments (Positional)
Argument value Type ANY Mode Positional Description
Description
1 Default unseeded
SELECT xxh3_64('hello world');

Output

xxh3_64('hello world')
15296390279056496779
2 Seeded for partitioning
SELECT xxh3_64('hello world', 999);

Output

xxh3_64('hello world', 999)
3002856137354040482
3 Hash several columns as one key (row hashing)
SELECT xxh3_64((42, 'checkout', DATE '2026-10-27'));

Output

xxh3_64("row"(42, 'checkout', CAST('2026-10-27' AS DATE)))
4629378746187339439

xxh32

Scalar function xxHash
Signature
2 overloaded forms · click to inspect
Arguments (Positional)
Argument value Type ANY Mode Positional Description
Description
1 Hash a string
SELECT xxh32('hello world');

Output

xxh32('hello world')
3468387874
2 Seeded variant — independent hash space
SELECT xxh32('hello world', 42);

Output

xxh32('hello world', 42)
4225033588

xxh64

Scalar function xxHash
Signature
2 overloaded forms · click to inspect
Arguments (Positional)
Argument value Type ANY Mode Positional Description
Description
1 64-bit hash of a string
SELECT xxh64('hello world');

Output

xxh64('hello world')
5020219685658847592
2 Seeded
SELECT xxh64('hello world', 42);

Output

xxh64('hello world', 42)
7620854247404556961