gen_random_uuid()
Synopsis
Use the gen_random_uuid()
function to generate a UUID.
This function returns a version 4 (random) UUID. This is the most commonly used type of UUID and is appropriate for most applications.
The uuid-ossp and pgcrypto modules provide additional functions that implement other standard algorithms for generating UUIDs.
Example
You can generate a UUID and check its type using the pg_typeof
function.
select gen_random_uuid(), pg_typeof(gen_random_uuid());
You will get an output similar to:
gen_random_uuid | pg_typeof
--------------------------------------+-----------
15684ea8-0505-4fb3-b3f7-1be2f253e0ed | uuid
Learn more
- uuid-ossp module