> ## 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()

> Create a version 7 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 and random bits.

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

![UUIDv7 microseconds][uuidv7-microseconds]

## Samples

```sql theme={"dark"}
SELECT to_uuidv7(ts)
FROM generate_series('2025-01-01:00:00:00'::timestamptz, '2025-01-01:00:00:03'::timestamptz, '1 microsecond'::interval) ts;
```

## Arguments

The syntax is:

```sql theme={"dark"}
SELECT to_uuidv7(
    timestamp = <timestamptz>
);
```

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

## Returns

| Column      | Type | Description                                                        |
| ----------- | ---- | ------------------------------------------------------------------ |
| `to_uuidv7` | UUID | A UUIDv7 object created from the input timestamp 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
