Skip to content

Hash and digest functions ​

Checksum and digest functions summarize text or binary input. CRC functions return integer checksums, named SHA/MD5 functions return hexadecimal text, and digest/hmac expose binary results for a chosen algorithm.

SQL NULL and binary zero bytes follow the individual contracts below. Use encode to display a binary digest in hex.

Example: Comparing checksums and digests ​

sql
SELECT crc32('123456789'), md5('hello') = md5('hello')
FORMAT csv;
text
3421780262,1

crc32 ​

Compute the IEEE CRC-32 checksum.

Syntax ​

text
crc32(bytes)

Arguments ​

Native BLOB or UTF-8 text; includes embedded zero bytes. SQL NULL propagates.

Returned value ​

Nonnegative INTEGER unsigned 32-bit checksum; empty input gives zero.

Example ​

sql
SELECT crc32('123456789') FORMAT csv;
text
3421780262

crc32c ​

Compute the Castagnoli CRC-32C checksum.

Syntax ​

text
crc32c(bytes)

Arguments ​

Native BLOB or UTF-8 text; includes embedded zero bytes. SQL NULL propagates.

Returned value ​

Nonnegative INTEGER unsigned 32-bit checksum; empty input gives zero.

Example ​

sql
SELECT crc32c('123456789') FORMAT csv;
text
3808858755

digest ​

Compute an algorithm-selected binary hash.

Syntax ​

text
digest(data,algorithm)

Arguments ​

BLOB or UTF-8 text; md5/sha1/sha224/sha256/sha384/sha512, case-insensitive algorithm names. SQL NULL propagates.

Returned value ​

BLOB digest.

Example ​

sql
SELECT encode(digest('abc','sha256'),'hex') FORMAT csv;
text
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"

hmac ​

Compute an RFC 2104 keyed message authentication code.

Syntax ​

text
hmac(data,key,algorithm)

Arguments ​

Same byte/algorithm rules as digest. SQL NULL propagates.

Returned value ​

BLOB authentication code.

Example ​

sql
SELECT encode(hmac('data','key','sha256'),'hex') FORMAT csv;
text
"5031fe3d989c6d1537a013fa6e739da23463fdaec3b70137d828e36ace221bd0"

md5 ​

Compute the lowercase hexadecimal MD5 digest of text bytes.

Syntax ​

text
md5(text)

Arguments ​

Text conversion uses UTF-8 bytes; NULL propagates.

Returned value ​

32-character lowercase hexadecimal TEXT.

Example ​

sql
SELECT md5('abc') FORMAT csv;
text
"900150983cd24fb0d6963f7d28e17f72"

sha224 ​

Compute the SHA-224 digest of exact input bytes.

Syntax ​

text
sha224(bytes)

Arguments ​

Text supplies UTF-8 bytes; BLOB supplies exact bytes. NULL propagates.

Returned value ​

BLOB of 28 digest bytes.

Example ​

sql
SELECT length(sha224('abc')) FORMAT csv;
text
28

sha256 ​

Compute SHA-256 over exact input bytes.

Syntax ​

text
sha256(bytes)

Arguments ​

Text supplies UTF-8 bytes; BLOB retains every byte.

Returned value ​

32-byte BLOB; use encode(...,hex) for hexadecimal text; SQL NULL propagates.

Example ​

sql
SELECT encode(sha256('abc'),'hex') FORMAT csv;
text
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"

sha384 ​

Compute the SHA-384 digest of exact input bytes.

Syntax ​

text
sha384(bytes)

Arguments ​

Text supplies UTF-8 bytes; BLOB supplies exact bytes. NULL propagates.

Returned value ​

BLOB of 48 digest bytes.

Example ​

sql
SELECT length(sha384('abc')) FORMAT csv;
text
48

sha512 ​

Compute SHA-512 over exact input bytes.

Syntax ​

text
sha512(bytes)

Arguments ​

Text supplies UTF-8 bytes; BLOB retains every byte.

Returned value ​

64-byte BLOB; SQL NULL propagates.

Example ​

sql
SELECT length(sha512('abc')) FORMAT csv;
text
64