uuid-ossp

generate universally unique identifiers (UUIDs)

Overview

PackageVersionCategoryLicenseLanguage
uuid-ossp1.1FUNCPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4930uuid-osspNoYesNoYesYesNo-
Relatedpg_idkit pgx_ulid pg_uuidv7 pg_hashids sequential_uuids permuteseq ddsketch vasco
Depended Bybabelfishpg_tsql

Version

PG18PG17PG16PG15PG14
1.11.11.11.11.1

Install

Note: This is a built-in contrib extension of PostgreSQL

CREATE EXTENSION uuid-ossp;

Usage

uuid-ossp: UUID generation functions

Provides functions to generate UUIDs using several standard algorithms. Note: for simple random UUIDs, consider using the built-in gen_random_uuid() instead.

CREATE EXTENSION "uuid-ossp";

UUID Generation Functions

FunctionDescription
uuid_generate_v1()Version 1: MAC address + timestamp
uuid_generate_v1mc()Version 1 with random multicast MAC
uuid_generate_v3(namespace uuid, name text)Version 3: MD5 hash of namespace + name
uuid_generate_v4()Version 4: fully random
uuid_generate_v5(namespace uuid, name text)Version 5: SHA-1 hash of namespace + name (preferred over v3)

Namespace Constants

FunctionDescription
uuid_nil()Nil UUID (all zeros)
uuid_ns_dns()DNS namespace
uuid_ns_url()URL namespace
uuid_ns_oid()ISO OID namespace
uuid_ns_x500()X.500 DN namespace

Examples

-- Random UUID (v4)
SELECT uuid_generate_v4();

-- Timestamp-based UUID (v1)
SELECT uuid_generate_v1();

-- Deterministic UUID from name (v5, preferred over v3)
SELECT uuid_generate_v5(uuid_ns_url(), 'http://www.postgresql.org');

-- Use as default primary key
CREATE TABLE items (
  id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,
  name text
);

Last Modified 2026-03-12: add pg extension catalog (95749bf)