Skip to content

Commit a763655

Browse files
committed
Add Compute Hashes With pgcrypto as a postgres til
1 parent 1f1796c commit a763655

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ _305 TILs and counting..._
130130
- [Aggregate A Column Into An Array](postgres/aggregate-a-column-into-an-array.md)
131131
- [Auto Expanded Display](postgres/auto-expanded-display.md)
132132
- [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md)
133+
- [Compute Hashes With pgcrypto](postgres/compute-hashes-with-pgcrypto.md)
133134
- [Configure The Timezone](postgres/configure-the-timezone.md)
134135
- [Count Records By Type](postgres/count-records-by-type.md)
135136
- [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Compute Hashes With pgcrypto
2+
3+
The `pgcrypto` extension that comes with PostgreSQL adds access to some
4+
general hashing functions. Included are `md5`, `sha1`, `sha224`, `sha256`,
5+
`sha384` and `sha512`. Any of these hashing functions can be applied to an
6+
arbitrary string using the `digest` function. Here are example of the `md5`
7+
and `sha1` algorithms:
8+
9+
```sql
10+
> create extension pgcrypto;
11+
CREATE EXTENSION
12+
13+
> select digest('Hello, World!', 'md5');
14+
digest
15+
------------------------------------
16+
\x65a8e27d8879283831b664bd8b7f0ad4
17+
18+
> select digest('Hello, World!', 'sha1');
19+
digest
20+
--------------------------------------------
21+
\x0a0a9f2a6772942557ab5355d76af442f8f65e01
22+
```
23+
24+
See the [`pgcrypto` docs](
25+
http://www.postgresql.org/docs/current/static/pgcrypto.html) for more
26+
details.

0 commit comments

Comments
 (0)