to_uuidv7_boundary()
Create a version 7 "boundary" UUID from a Postgres timestamp
Since 2.23.0
Create a UUIDv7 object from a PostgreSQL timestamp for use in range queries.
ts is converted to a UNIX timestamp split into millisecond and sub-millisecond parts.
The random bits of the UUID are set to zero in order to create a “lower” boundary UUID. For example, you can use the returned UUIDs to find all rows with UUIDs where the timestamp is less than the boundary UUID’s timestamp.
Samples
Section titled “Samples”-
Create a boundary UUID from a timestamp:
SELECT to_uuidv7_boundary('2025-09-04 11:01');Returns something like:
to_uuidv7_boundary--------------------------------------019913f5-30e0-7000-8000-000000000000 -
Use a boundary UUID to find all UUIDs with a timestamp below
'2025-09-04 10:00':SELECT * FROM uuid_events WHERE event_id < to_uuidv7_boundary('2025-09-04 10:00');
Arguments
Section titled “Arguments”The syntax is:
SELECT to_uuidv7_boundary( ts = <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_boundary | UUID | A boundary UUIDv7 object with random bits set to zero, suitable for use in range queries. |