PostgreSQL includes several functions to generate a UUID.
gen_random_uuid() →uuiduuidv4() →uuid
These functions return a version 4 (random) UUID.
uuidv7([shiftinterval]) →uuid
This function returns a version 7 UUID (UNIX timestamp with millisecond
precision + sub-millisecond timestamp + random). This function can accept
optional shift parameter of type interval
which shift internal timestamp by the given interval.
Модуль uuid-ossp предоставляет дополнительные функции, реализующие другие стандартные алгоритмы генерирования UUID.
There are also functions to extract data from UUIDs:
uuid_extract_timestamp(uuid) →timestamp with time zone
This function extracts a timestamp with time zone from UUID
version 1 and 7. For other versions, this function returns null. Note that
the extracted timestamp is not necessarily exactly equal to the time the
UUID was generated; this depends on the implementation that generated the
UUID.
uuid_extract_version(uuid) →smallint
This function extracts the version from a UUID of the variant described by
RFC 9562. For
other variants, this function returns null. For example, for a UUID
generated by gen_random_uuid, this function will
return 4.
В PostgreSQL также реализованы показанные в Таблице 9.1 операторы для сравнения значений UUID.