Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new context method local_md5 for v1.4 #2658

Merged
merged 12 commits into from
Jan 11, 2023
18 changes: 18 additions & 0 deletions website/docs/reference/dbt-jinja-functions/local-md5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: "local_md5"
id: "local_md5"
---

The `local_md5` context variable calculates an [MD5 hash](https://en.wikipedia.org/wiki/MD5) of the given string. It's called `local_md5` to emphasize that the hash is calculated _locally_, in the dbt-Jinja context. This function is intended for generally advanced use cases: generating unique identifiers within custom materialization or operational logic, such as to avoid collisions between temporary relations, or to identify changes by comparing checksums.
matthewshaver marked this conversation as resolved.
Show resolved Hide resolved

It should not be confused with the `md5` SQL function, supported by many SQL dialects, which runs remotely in the data platform. You should always use SQL hashing functions when generating <Term id="surrogate-key">surrogate keys</Term>.
matthewshaver marked this conversation as resolved.
Show resolved Hide resolved

Usage:
```sql
-- source
{%- set value_hash = local_md5("hello world") -%}
'{{ value_hash }}'

-- compiled
'5eb63bbbe01eeed093cb22bb8f5acdc3'
```