hash
hash(*args: Value) -> ExpressionCompute a hash value for the given arguments.
Parameters
(*argsValue, default:()) - Values to hash together. At least one value is required.
Returns
Expression- AnExpressionrepresenting the computed hash value. ReturnsHash.
Raises
ValueError- If called with no arguments.
Examples
Compute hash of a single value:
select(common.hash(Person.email))Compute hash of multiple values together:
select(common.hash(Order.customer_id, Order.order_date))Notes
A missing argument means no hash, rather than a hash over the missing
value. Where the hash is a row source — a where, a define, an
aggregate — the row is eliminated; in a select the anchoring row keeps
its place and the hash reads back as missing. Nothing is raised either way,
so a model hashing a value that is absent for some rows loses those rows
instead of computing an identity for them.
The value is not part of any compatibility guarantee and can change
between releases. The common way to be caught by that is uuid_to_string(hash(...))
used as an identify_by value: after an upgrade the same source rows mint
different entities, with nothing raised. Recompute stored hashes rather than
comparing one against a hash computed by another version. It is not a
cryptographic hash.
Do not rely on the hash separating types: some backends compute it over
the arguments’ string forms, so hash(1) and hash("1") can compare
equal.
Adjacent arguments stay distinct: hash("ab", "c") and hash("a", "bc")
differ. An argument containing U+001F can collide with an argument
boundary (hash("a\x1fb") can equal hash("a", "b")), so keep that byte
out of the values you hash. An entity argument hashes as the entity’s
identity, not its key columns. Where a backend cannot reconstruct that
identity it raises at query time. The identity itself can still collide:
an entity key that nests entities two or more levels deep, or a composite
key whose adjacent parts concatenate alike (the identity encoding carries
no separators).
Arguments of type Date, DateTime, Hash (which includes a nested
hash), non-integer numbers, and entities are not rendered identically by
every backend, so a hash taken over them is not portable across backends.
For Date, DateTime, Hash, and non-integer numbers this is the same
restriction that already applies to entity construction.