Cloud

gen_random_uuid (uuidv4)

The gen_random_uuid() function returns a random version 4 UUID as a uuid value. uuidv4() is equivalent: both take no arguments and return a random version 4 UUID.

These functions are volatile: they return a new value on each call, so a query that calls one once per row produces a distinct UUID for each row.

Syntax

The syntax for these functions is:

gen_random_uuid()
uuidv4()

Each function takes no arguments and returns a value of type uuid.

Examples

Generate a random UUID

SELECT gen_random_uuid();

The function returns a random UUID in the 36-character canonical form. For example:

           gen_random_uuid
--------------------------------------
 a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11

uuidv4() returns the same kind of value:

SELECT uuidv4();