From a763655cd6db24d27fc550de2a5013c5b73dbea1 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 25 Jan 2016 19:49:14 -0600 Subject: [PATCH] Add Compute Hashes With pgcrypto as a postgres til --- README.md | 1 + postgres/compute-hashes-with-pgcrypto.md | 26 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 postgres/compute-hashes-with-pgcrypto.md diff --git a/README.md b/README.md index ba02069..4a2667b 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ _305 TILs and counting..._ - [Aggregate A Column Into An Array](postgres/aggregate-a-column-into-an-array.md) - [Auto Expanded Display](postgres/auto-expanded-display.md) - [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md) +- [Compute Hashes With pgcrypto](postgres/compute-hashes-with-pgcrypto.md) - [Configure The Timezone](postgres/configure-the-timezone.md) - [Count Records By Type](postgres/count-records-by-type.md) - [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md) diff --git a/postgres/compute-hashes-with-pgcrypto.md b/postgres/compute-hashes-with-pgcrypto.md new file mode 100644 index 0000000..ca3acef --- /dev/null +++ b/postgres/compute-hashes-with-pgcrypto.md @@ -0,0 +1,26 @@ +# Compute Hashes With pgcrypto + +The `pgcrypto` extension that comes with PostgreSQL adds access to some +general hashing functions. Included are `md5`, `sha1`, `sha224`, `sha256`, +`sha384` and `sha512`. Any of these hashing functions can be applied to an +arbitrary string using the `digest` function. Here are example of the `md5` +and `sha1` algorithms: + +```sql +> create extension pgcrypto; +CREATE EXTENSION + +> select digest('Hello, World!', 'md5'); + digest +------------------------------------ + \x65a8e27d8879283831b664bd8b7f0ad4 + +> select digest('Hello, World!', 'sha1'); + digest +-------------------------------------------- + \x0a0a9f2a6772942557ab5355d76af442f8f65e01 +``` + +See the [`pgcrypto` docs]( +http://www.postgresql.org/docs/current/static/pgcrypto.html) for more +details.