From 00a69a4f1702297ec82efe0dc96baaac22fa28a7 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 20 Oct 2015 08:44:24 -0500 Subject: [PATCH] Add Generate A UUID as a postgres til. --- README.md | 1 + postgres/generate-a-uuid.md | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 postgres/generate-a-uuid.md diff --git a/README.md b/README.md index dd971bf..ff792b3 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Edit Existing Functions](postgres/edit-existing-functions.md) - [Extracting Nested JSON Data](postgres/extracting-nested-json-data.md) - [Fizzbuzz With Common Table Expressions](postgres/fizzbuzz-with-common-table-expressions.md) +- [Generate A UUID](postgres/generate-a-uuid.md) - [Generate Series Of Numbers](postgres/generate-series-of-numbers.md) - [Getting A Slice Of An Array](postgres/getting-a-slice-of-an-array.md) - [Integers In Postgres](postgres/integers-in-postgres.md) diff --git a/postgres/generate-a-uuid.md b/postgres/generate-a-uuid.md new file mode 100644 index 0000000..32b742f --- /dev/null +++ b/postgres/generate-a-uuid.md @@ -0,0 +1,19 @@ +# Generate A UUID + +Postgres has support for universally unique identifiers (UUIDs) as a column +data type via `uuid`. If you have a UUID column, you may need to generate a +UUID. This requires the `uuid-ossp` module. This module provides a number +of functions for generating UUIDs including the `uuid_generate_v4()` +function which bases the UUID entirely off random numbers. + +```sql +> create extension "uuid-ossp"; +CREATE EXTENSION +> select uuid_generate_v4(); + uuid_generate_v4 +-------------------------------------- + a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11 +``` + +See the [postgres docs](http://www.postgresql.org/docs/9.4/static/uuid-ossp.html) for more +details on UUID generation functions.