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
SELECT crc32('123456789'), md5('hello') = md5('hello')
FORMAT csv;3421780262,1crc32
Compute the IEEE CRC-32 checksum.
Syntax
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
SELECT crc32('123456789') FORMAT csv;3421780262crc32c
Compute the Castagnoli CRC-32C checksum.
Syntax
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
SELECT crc32c('123456789') FORMAT csv;3808858755digest
Compute an algorithm-selected binary hash.
Syntax
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
SELECT encode(digest('abc','sha256'),'hex') FORMAT csv;"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"hmac
Compute an RFC 2104 keyed message authentication code.
Syntax
hmac(data,key,algorithm)Arguments
Same byte/algorithm rules as digest. SQL NULL propagates.
Returned value
BLOB authentication code.
Example
SELECT encode(hmac('data','key','sha256'),'hex') FORMAT csv;"5031fe3d989c6d1537a013fa6e739da23463fdaec3b70137d828e36ace221bd0"md5
Compute the lowercase hexadecimal MD5 digest of text bytes.
Syntax
md5(text)Arguments
Text conversion uses UTF-8 bytes; NULL propagates.
Returned value
32-character lowercase hexadecimal TEXT.
Example
SELECT md5('abc') FORMAT csv;"900150983cd24fb0d6963f7d28e17f72"sha224
Compute the SHA-224 digest of exact input bytes.
Syntax
sha224(bytes)Arguments
Text supplies UTF-8 bytes; BLOB supplies exact bytes. NULL propagates.
Returned value
BLOB of 28 digest bytes.
Example
SELECT length(sha224('abc')) FORMAT csv;28sha256
Compute SHA-256 over exact input bytes.
Syntax
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
SELECT encode(sha256('abc'),'hex') FORMAT csv;"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"sha384
Compute the SHA-384 digest of exact input bytes.
Syntax
sha384(bytes)Arguments
Text supplies UTF-8 bytes; BLOB supplies exact bytes. NULL propagates.
Returned value
BLOB of 48 digest bytes.
Example
SELECT length(sha384('abc')) FORMAT csv;48sha512
Compute SHA-512 over exact input bytes.
Syntax
sha512(bytes)Arguments
Text supplies UTF-8 bytes; BLOB retains every byte.
Returned value
64-byte BLOB; SQL NULL propagates.
Example
SELECT length(sha512('abc')) FORMAT csv;64