Skip to main content
Community Create a UUIDv7 object from a timestamp for use in range queries. ts is converted to a UNIX timestamp split into millisecond and sub-millisecond parts. UUIDv7 microseconds 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

  • Create a boundary UUID from a timestamp:
    postgres=# 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

NameTypeDefaultRequiredDescription
tsTIMESTAMPTZ-The timestamp used to return a UUIDv7 object