> ## 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.

# generate_uuidv7()

> Generate a version 7 UUID based on current time

export const TIMESCALE_DB = 'TimescaleDB';

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

Generate a UUIDv7 object based on the current time.

The UUID contains a UNIX timestamp split into millisecond and sub-millisecond parts, followed by
random bits.

You can use this function to generate a time-ordered series of UUIDs
suitable for use in a time-partitioned column in {TIMESCALE_DB}.

![UUIDv7 microseconds][uuidv7-microseconds]

## Samples

* **Generate a UUIDv7 object based on the current time**

  ```sql theme={"dark"}
  SELECT generate_uuidv7();
             generate_uuidv7
  --------------------------------------
   019913ce-f124-7835-96c7-a2df691caa98
  ```

* **Insert a generated UUIDv7 object**

  ```sql theme={"dark"}
  INSERT INTO alerts VALUES (generate_uuidv7(), 'high CPU');
  ```

## Returns

| Column            | Type | Description                                                 |
| ----------------- | ---- | ----------------------------------------------------------- |
| `generate_uuidv7` | UUID | A UUIDv7 object based on the current time with random bits. |

[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
