HASH4 scalar function
The HASH4 function returns the 32-bit checksum hash of the input data. The function provides 232 distinct return values and is intended for data retrieval (lookups).
The schema is SYSIBM.
- string-expression
- An expression that represents the string value to be hashed. This expression must return a built-in character string, graphic string, binary string, numeric value, Boolean value, or datetime value. If the value is not a character, graphic, or binary string, it is implicitly cast to VARCHAR before the function is evaluated.
- algorithm
- An expression that specifies the algorithm to use for hashing.
The expression must return a value that is a built-in numeric, a CHAR,
or a VARCHAR data type. In a Unicode database, the expression can
also be a GRAPHIC or VARGRAPHIC data type. CHAR, VARCHAR, GRAPHIC,
and VARGRAPHIC are supported using implicit casting. If the expression
is not a INTEGER, it is cast to INTEGER before evaluating the function.
The algorithm value can be either 0 or 1. 0 is the default value and indicates the Adler algorithm. 1 indicates the CRC32 algorithm. The Adler algorithm provides a faster checksum hash; however, it has poor coverage when the messages are less than a few hundred bytes (poor coverage means that two different integers hash to the same value, referred to as a
collision
). In this case, use the CRC32 algorithm, or switch to hash8 instead.
Result
The data type of the result is INTEGER. If the first argument can be null, the result can be null. If the first argument is null, the result is the null value.
Example
values hash4('Charlie at IBM', 0)
The result is 622396582