GUID V4 - Random-Based Identifier (Recommended)
GUID v4 is the most widely used random-based identifier. Learn about its structure, collision probability, advantages and why it is recommended for general-purpose applications.
Generate UUIDs in PostgreSQL with gen_random_uuid() for v4-style values and uuidv7() on PostgreSQL 18 or newer when you want better index locality.
SELECT gen_random_uuid();This is commonly available through pgcrypto or newer PostgreSQL packaging that exposes the function directly.
SELECT uuidv7();Check your PostgreSQL version first. uuidv7() is built in on PostgreSQL 18 and later, so older deployments still need an application-side fallback.
uuidv7() is built in on PostgreSQL 18 and later.uuidv7() is built in on PostgreSQL 18 and later, so verify the exact release you deploy before depending on it.These articles expand on related concepts, formats and practical considerations.