TT_HASH
The TT_HASH
function returns the hash value of an expression or list of expressions. This value is the value that is used by a hash index.
SQL syntax
TT_HASH(Expression [,...])
Parameters
TT_HASH
has the parameter:
Parameter | Description |
---|---|
|
One or more expressions to be used to determine the hash value of the expression or list of expressions. |
Description
-
Each expression must have a known data type and must be non-nullable. The hash value of the expression depends on both the value of the expression and its type. For example,
TT_HASH
of anTT_INTEGER
with value 25 may be different fromTT_HASH
of aNUMBER
orBINARY_DOUBLE
with value 25. If you specify a list of expressions, theTT_HASH
result depends on the order of the expressions in the list. -
Since constants and expressions that are not simple column references are subject to internal typing rules, over which applications have no control, the best way to ensure that
TT_HASH
computes the desired value for expressions that are not simple column references is toCAST
the expression to the desired type. -
The result type of
TT_HASH
isTT_INTEGER
in 32-bit mode andTT_BIGINT
in 64-bit mode. -
TT_HASH
can be used in a SQL statement anywhere an expression can be used. For example,TT_HASH
can be used in aSELECT
list, aWHERE
orHAVING
clause, anORDER BY
clause, or aGROUP BY
clause. -
The output of error messages, trace messages, and
ttXactAdmin
display the hash value as a signed decimal so that the value matchesTT_HASH
output.
Examples
The following query finds the set of rows whose primary key columns hash to a given hash value:
SELECT * FROM t1 WHERE TT_HASH(pkey_col1, pkey_col2, pkey_col3) = 12345678;