Hashing functions in the Crypto DuckDB extension
Function category
Hashing
2 functionsCompute cryptographic digests of values, lists, and entire datasets. Supports BLAKE3, BLAKE2b, the SHA-2 / SHA-3 families, plus legacy MD4 / MD5 / SHA-1 for compatibility. The aggregate variant produces an order-deterministic dataset checksum.
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
algorithm
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Description
Compute a cryptographic hash of a value with the given algorithm. Supported algorithms: blake2b-512, blake3, md4, md5, sha1, sha2-{224,256,384,512}, sha3-{224,256,384,512}, keccak{224,256,384,512}. Different DuckDB types of the same numeric value produce different hashes.
SELECT lower(to_hex(crypto_hash('sha2-256', 'hello world')));
Output
| lower(to_hex(crypto_hash('sha2-256', 'hello world'))) |
|---|
| b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 |
SELECT lower(to_hex(crypto_hash('blake3', 42::INTEGER)));
Output
| lower(to_hex(crypto_hash('blake3', CAST(42 AS INTEGER)))) |
|---|
| 95dbc3244503309f26dee9436b39568cc80b0cbe17ef409e9273c4edb58653fd |
SELECT lower(to_hex(crypto_hash('sha2-256', ['hello', 'world']::VARCHAR[])));
Output
| lower(to_hex(crypto_hash('sha2-256', CAST(main.list_value('hello', 'world') AS VARCHAR[])))) |
|---|
| 306a0d104017a29193be6c7464b1fd5ee65495353a7ccad7dd2928e5fb9731fd |
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
algorithm
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
value
|
Type
BLOB | TINYINT | HUGEINT | …
14 concrete typesBIGINTBLOBDOUBLEFLOATHUGEINTINTEGERSMALLINTTINYINTUBIGINTUHUGEINTUINTEGERUSMALLINTUTINYINTVARCHAR
|
Mode Positional | Description |
Description
Order-deterministic aggregate hash. Hashes column values sequentially in the ORDER BY order — yielding the same digest as crypto_hash over an equivalent ordered list. Useful for dataset checksums, change detection, and Merkle-style hierarchical hashing.
SELECT department,
lower(to_hex(crypto_hash_agg('sha2-256', employee_id ORDER BY employee_id))) AS dept_hash
FROM employees
GROUP BY department;
SELECT crypto_hash_agg('sha2-256', value ORDER BY value)
= crypto_hash('sha2-256', [1, 2, 3, 4, 5]::INTEGER[])
FROM (VALUES (1),(2),(3),(4),(5)) t(value);
Output
| (crypto_hash_agg('sha2-256', "value" ORDER BY "value") = crypto_hash('sha2-256', CAST(main.list_value(1, 2, 3, 4, 5) AS INTEGER[]))) |
|---|
| true |