Hash Functions

Confluent Cloud for Apache Flink®️ provides these built-in functions to generate hash codes in SQL queries:

MD5

Gets the MD5 hash of a string.

Syntax
MD5(string)
Description

The MD5 function returns the MD5 hash of the specified string as a string of 32 hexadecimal digits.

Returns NULL if string is NULL.

Example
-- returns 99dc0ea422440e5b3f675cffe6d...
SELECT MD5('string-to-hash');

SHA1

Gets the SHA-1 hash of a string.

Syntax
SHA1(string)
Description

The SHA1 function returns the SHA-1 hash of the specified string as a string of 40 hexadecimal digits.

Returns NULL if string is NULL.

Example
-- returns 771a2b04044f8c51e3383a2675a...
SELECT SHA1('string-to-hash');

SHA2

Hashes a string with one of the SHA-2 functions.

Syntax
SHA2(string, hashLength)
Description

The SHA2 function returns the hash using the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, and SHA-512).

  • The first argument, string, is the string to be hashed.
  • The second argument, hashLength, is the bit length of the result.

These are the valid bit lengths for hashLength:

  • 224
  • 256
  • 384
  • 512

Returns NULL if string or hashLength is NULL.

Example
-- returns 222145560dbaa2abc1617e2c7ce...
SELECT SHA2('string-to-hash', 512);

SHA224

Gets the SHA-224 hash of a string.

Syntax
SHA224(string)
Description

The SHA224 function returns the SHA-224 hash of the specified string as a string of 56 hexadecimal digits.

Returns NULL if string is NULL.

Example
-- returns af1f1c988d9154f2ddb6201f60f...
SELECT SHA224('string-to-hash');

SHA256

Gets the SHA-256 hash of a string.

Syntax
SHA256(string)
Description

The SHA256 function returns the SHA-256 hash of the specified string as a string of 64 hexadecimal digits.

Returns NULL if string is NULL.

Example
-- returns 2267d414e45335fd02e64057d55...
SELECT SHA256('string-to-hash');

SHA384

Gets the SHA-384 hash of a string.

Syntax
SHA384(string)
Description

The SHA5384 function returns the SHA-384 hash of the specified string as a string of 96 hexadecimal digits.

Returns NULL if string is NULL.

Example
-- returns 02ba979b23f1b4a098732463ea8...
SELECT SHA384('string-to-hash');

SHA512

Gets the SHA-512 hash of a string.

Syntax
SHA512(string)
Description

The SHA512 function returns the SHA-512 hash of the specified string as a string of 128 hexadecimal digits.

Returns NULL if string is NULL.

Example
-- returns 222145560dbaa2abc1617e2c7ce...
SELECT SHA512('string-to-hash');

Other built-in functions

Important

Confluent Cloud for Apache Flink®️ is currently available for Preview. A Preview feature is a Confluent Cloud component that is being introduced to gain early feedback from developers. Preview features can be used for evaluation and non-production testing purposes or to provide feedback to Confluent. The warranty, SLA, and Support Services provisions of your agreement with Confluent do not apply to Preview features. Confluent may discontinue providing Preview releases of the Preview features at any time in Confluent’s sole discretion. Check out Getting Help for questions, feedback and requests.

For SQL features and limitations in the preview program, see Notable Limitations in Public Preview.