PostgreSQL 18 reference · 3 entries
PostgreSQL UUID Functions
Generate and inspect UUIDs in PostgreSQL: gen_random_uuid() and uuidv4() for random IDs, uuidv7() for time-ordered IDs, and uuid_extract_timestamp().
All of these are built in; the uuid-ossp extension is no longer needed. For new tables,
uuidv7() (PostgreSQL 18) makes better primary keys than random v4 UUIDs.
| Name | Description | Since |
|---|---|---|
GEN_RANDOM_UUID() |
Generate a random version 4 UUID. Since PostgreSQL 18, uuidv4() is another name for it. | 13 |
UUIDV7() |
Generate a version 7 UUID, which starts with a timestamp so new IDs sort in creation order. Added in PostgreSQL 18. | 18 |
UUID_EXTRACT_TIMESTAMP() |
Return the creation time stored inside a version 1 or 7 UUID, or NULL for other versions. Added in PostgreSQL 17. | 17 |