Skip to content

Commit

Permalink
Merge pull request #2658 from dbt-labs/md5-jinja
Browse files Browse the repository at this point in the history
Adding new context method local_md5  for v1.4
  • Loading branch information
matthewshaver authored Jan 11, 2023
2 parents 6009221 + 8fbda28 commit 324a1ce
Showing 1 changed file with 18 additions and 0 deletions.
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. The string `local_md5` emphasizes that the hash is calculated _locally_, in the dbt-Jinja context. This variable is typically useful for advanced use cases. For example, when you generate unique identifiers within custom materialization or operational logic, you can either avoid collisions between temporary relations or identify changes by comparing checksums.

It is different than the `md5` SQL function, supported by many SQL dialects, which runs remotely in the data platform. You want to always use SQL hashing functions when generating <Term id="surrogate-key">surrogate keys</Term>.

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

-- compiled
'5eb63bbbe01eeed093cb22bb8f5acdc3'
```

0 comments on commit 324a1ce

Please sign in to comment.