Skip to main content
The uuid-ossp extension provides functions for generating Universally Unique Identifiers (UUIDs) in PostgreSQL. Your Nile database arrives with the uuid-ossp extension already enabled.

Overview

The uuid-ossp extension provides several functions for generating UUIDs according to different standards:
  • Version 1: Time-based UUIDs
  • Version 3: Namespace and name-based UUIDs using MD5
  • Version 4: Random UUIDs
  • Version 5: Namespace and name-based UUIDs using SHA-1
Nile includes public.uuid_generate_v7() which generates UUIDs with time-ordered lexicographically sortable strings. It is recommended to use this function for fields that are used in sorting and indexing.

UUID Generation Functions

UUID Version 4 (Random)

The most commonly used function is uuid_generate_v4(), which generates a random UUID:

UUID Version 1 (Time-based)

uuid_generate_v1() creates a UUID based on the current timestamp and MAC address:

UUID Version 3 (Name-based, MD5)

uuid_generate_v3() creates a UUID based on a namespace and name using MD5:

UUID Version 5 (Name-based, SHA-1)

uuid_generate_v5() creates a UUID based on a namespace and name using SHA-1:

Common Use Cases

Primary Keys

Deterministic IDs

Additional Resources