to_uuidv7()
Create a version 7 UUID from a Postgres timestamp
Since 2.23.0
Create a UUIDv7 object from a PostgreSQL timestamp and random bits.
ts is converted to a UNIX timestamp split into millisecond and sub-millisecond parts.
Samples
Section titled “Samples”SELECT to_uuidv7(ts)FROM generate_series('2025-01-01:00:00:00'::timestamptz, '2025-01-01:00:00:03'::timestamptz, '1 microsecond'::interval) ts;Arguments
Section titled “Arguments”The syntax is:
SELECT to_uuidv7( timestamp = <timestamptz>);| Name | Type | Default | Required | Description |
|---|---|---|---|---|
ts | TIMESTAMPTZ | - | ✔ | The timestamp used to return a UUIDv7 object |
Returns
Section titled “Returns”| Column | Type | Description |
|---|---|---|
to_uuidv7 | UUID | A UUIDv7 object created from the input timestamp with random bits. |