From 098f690c47d30bc8110fa11116020dc15fc2c80b Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 14 Jan 2021 15:12:46 -0600 Subject: [PATCH] Add Generate Random UUIDs Without An Extension as a postgres til --- README.md | 3 ++- ...erate-random-uuids-without-an-extension.md | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 postgres/generate-random-uuids-without-an-extension.md diff --git a/README.md b/README.md index 9619781..6f05626 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1008 TILs and counting..._ +_1009 TILs and counting..._ --- @@ -521,6 +521,7 @@ _1008 TILs and counting..._ - [Find The Location Of Postgres Config Files](postgres/find-the-location-of-postgres-config-files.md) - [Fizzbuzz With Common Table Expressions](postgres/fizzbuzz-with-common-table-expressions.md) - [Generate A UUID](postgres/generate-a-uuid.md) +- [Generate Random UUIDs Without An Extension](postgres/generate-random-uuids-without-an-extension.md) - [Generate Series Of Numbers](postgres/generate-series-of-numbers.md) - [Generating UUIDs With pgcrypto](postgres/generating-uuids-with-pgcrypto.md) - [Get The Size Of A Database](postgres/get-the-size-of-a-database.md) diff --git a/postgres/generate-random-uuids-without-an-extension.md b/postgres/generate-random-uuids-without-an-extension.md new file mode 100644 index 0000000..cc5c786 --- /dev/null +++ b/postgres/generate-random-uuids-without-an-extension.md @@ -0,0 +1,20 @@ +# Generate Random UUIDs Without An Extension + +In other posts I've covered how to generate v4 random UUIDs in PostgreSQL +[using the `uuid-ossp` extension](generate-a-uuid.md) as well as the more +up-to-date method of [using the `pgcrypto` +extension](generating-uuids-with-pgcrypto.md). + +As of PostgreSQL v13, you no longer need to add an extension for v4 UUID +generation. It comes built-in as the `gen_random_uuid()` function. + +```sql +> select gen_random_uuid(); + gen_random_uuid +-------------------------------------- + 0aa72fe6-ede7-4ccf-b328-348becc58066 +(1 row) +``` + +If you need other non-v4 UUID functions, you'll have to stick with +[uuid-ossp](https://www.postgresql.org/docs/current/uuid-ossp.html).