CRC-32C & FNV-1a 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
CRC-32C & FNV-1a
3 functionsClassic checksum and hash formats that other systems embed: CRC-32C (Castagnoli), used by iSCSI, ext4, Google Cloud Storage object checksums and many storage formats, and FNV-1a, a tiny byte-at-a-time hash common in older code.
Signature
2 overloaded forms · click to inspectArguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Argument
crc
|
Type
UINTEGER
|
Mode Positional | Description |
Description
CRC-32C (Castagnoli) checksum as UINTEGER — the checksum used by iSCSI, ext4, Google Cloud Storage objects and many storage and wire formats. crc32c('123456789') is the standard check value 0xE3069283.
The optional second argument continues a previous checksum: crc32c(b, crc32c(a)) equals the checksum of a followed by b, so you can checksum data that arrives in pieces.
SELECT crc32c('123456789'), printf('%08X', crc32c('123456789'));
Output
| crc32c('123456789') | printf('%08X', crc32c('123456789')) |
|---|---|
| 3808858755 | E3069283 |
SELECT crc32c('6789', crc32c('12345')) = crc32c('123456789');
Output
| (crc32c('6789', crc32c('12345')) = crc32c('123456789')) |
|---|
| true |
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Description
32-bit FNV-1a. Simple and widely embedded, but slower and weaker than modern hashes — use it to match an existing FNV-1a key. FNV-1a has no seed.
SELECT fnv1a_32('hello world');
Output
| fnv1a_32('hello world') |
|---|
| 3582672807 |
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Description
64-bit FNV-1a. Use it to match an existing FNV-1a key; for new work prefer xxh3_64. FNV-1a has no seed.
SELECT fnv1a_64('hello world');
Output
| fnv1a_64('hello world') |
|---|
| 8618312879776256743 |