uuid-ossp extension can be used to generate a
UUID is a "Universally Unique Identifer" and it is, for practical purposes, unique.
This makes them particularly well suited as Primary Keys. It is occasionally referred to as a
GUID, which stands for "Globally Unique Identifer".
1. Go to the Database page.
2. Click on "Extensions" in the sidebar.
3. Search for "uuid-ossp".
4. Click the toggle.
-- Example: enable the "uuid-ossp" extension
create extension "uuid-ossp" with schema extensions;
-- Example: disable the "uuid-ossp" extension
drop extension if exists "uuid-ossp";
Even though the SQL code is
create extension, this is the equivalent of "enabling the extension".
To disable an extension you can call
It's good practice to create the extension within a separate schema (like
extensions) to keep your database clean.
Once the extension is enabled, you now have access to a
Creates a UUID value based on the combination of computer’s MAC address, current timestamp, and a random value.
Creates UUID values based solely on random numbers.
Within a query
As a Primary Key
Automatically create a unique, random ID in a table:
create table contacts (
id uuid default uuid_generate_v4(),
primary key (id)