Skip to content

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.

UUIDv7 structure with microsecond-precision timestamp

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.

  • 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');

The syntax is:

SELECT to_uuidv7_boundary(
ts = <timestamptz>
);
NameTypeDefaultRequiredDescription
tsTIMESTAMPTZ-The timestamp used to return a UUIDv7 object
ColumnTypeDescription
to_uuidv7_boundaryUUIDA boundary UUIDv7 object with random bits set to zero, suitable for use in range queries.