Hash Functions

HASH

HASH(x, digest) Computes the hash of the bytes value x using digest, where digest is one of the OpenSSL digest methods md5, sha1, sha256, or sha512 (case insensitive).

SELECT HASH('foo', 'md5')
'rL0Y20zC+Fzt72VPzMSk2A=='
SELECT HASH('foo', 'sha1')
'C+7Hteo/D9vJXQ3UfzxbwnXaijM='
SELECT HASH('foo', 'sha256')
'LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564='
SELECT HASH('foo', 'sha512')
'9/u6bgY2+JDlb7vzKD5STG+jIErimDgtYkdB0NxmODJuKCxBvl5CVNiCB3LFUYosWowMf37aGVlKfrU5RT4e1w=='

HASH_COMBINE

HASH_COMBINE(x, ...) Computes a unique hash over all input arguments. Order matters for the input arguments, and all types are supported, though any null argument results in a null return value.

SELECT HASH_COMBINE(1, 'foo', true)
'Ha+UEYFyOiFt0wYOEWR9PA=='
SELECT HASH_COMBINE('foo', null)
null

ID_HASH

ID_HASH(x, ...) Equivalent of TO_BASE64(HASH_COMBINE(args...)). Useful when constructing a custom value for _id in an ingest transformation, e.g. SELECT ID_HASH(field1, field2) AS _id.

SELECT ID_HASH('foo', 35)
'NSzQujFA9oP0ABXeC5q9Xg=='

MD5

MD5(x) Computes the MD5 hash of the bytes value x.

SELECT MD5('foo')
'rL0Y20zC+Fzt72VPzMSk2A=='
SELECT MD5('')
'1B2M2Y8AsgTpgAmY7PhCfg=='
SELECT MD5(null)
null

SHA1

SHA1(x) Computes the SHA1 hash of the bytes value x.

SELECT SHA1('foo')
'C+7Hteo/D9vJXQ3UfzxbwnXaijM='
SELECT SHA1('')
'2jmj7l5rSw0yVb/vlWAYkK/YBwk='
SELECT SHA1(null)
null

SHA256

SHA256(x) Computes the SHA256 hash of the bytes value x.

SELECT SHA256('foo')
'LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564='
SELECT SHA256('')
'47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='
SELECT SHA256(null)
null

SHA512

SHA512(x) Computes the SHA512 hash of the bytes value x.

SELECT SHA512('foo')
'9/u6bgY2+JDlb7vzKD5STG+jIErimDgtYkdB0NxmODJuKCxBvl5CVNiCB3LFUYosWowMf37aGVlKfrU5RT4e1w=='
SELECT SHA512('')
'z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg=='
SELECT SHA512(null)
null

XXH3_64

XXH3_64(x[, seed]) Computes the 64 bit XXH3 hash of x using seed as the seed. seed is optional, default value is 0.

SELECT XXH3_64('foo', 1122)
2259966778267089194
SELECT XXH3_64('', 1122)
4199586300600163007
SELECT XXH3_64(null, 1122)
null