> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify-poc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# to_uuidv7_boundary()

> Create a version 7 "boundary" UUID from a Postgres timestamp

export const PG = 'Postgres';

<Icon icon="tag" iconType="duotone" /> Since [2.23.0][tsdb-2.23.0]

Create a UUIDv7 object from a {PG} timestamp for use in range queries.

`ts` is converted to a UNIX timestamp split into millisecond and sub-millisecond parts.

![UUIDv7 microseconds][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**:

  ```sql theme={"dark"}
  SELECT to_uuidv7_boundary('2025-09-04 11:01');
  ```

  Returns something like:

  ```terminaloutput theme={"dark"}
            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'`**:

  ```sql theme={"dark"}
  SELECT * FROM uuid_events WHERE event_id < to_uuidv7_boundary('2025-09-04 10:00');
  ```

## Arguments

The syntax is:

```sql theme={"dark"}
SELECT to_uuidv7_boundary(
    ts = <timestamptz>
);
```

| Name | Type        | Default | Required | Description                                  |
| ---- | ----------- | ------- | -------- | -------------------------------------------- |
| `ts` | TIMESTAMPTZ | -       | ✔        | The timestamp used to return a UUIDv7 object |

## Returns

| Column               | Type | Description                                                                               |
| -------------------- | ---- | ----------------------------------------------------------------------------------------- |
| `to_uuidv7_boundary` | UUID | A boundary UUIDv7 object with random bits set to zero, suitable for use in range queries. |

[tsdb-2.23.0]: https://github.com/timescale/timescaledb/releases/tag/2.23.0

[uuidv7-microseconds]: https://assets.timescale.com/docs/images/uuidv7-structure-microseconds.svg
