# pg_uuidv7 — Postgres extension

> Time-ordered UUID v7 values.

Source: https://scribase.com/extensions/pg_uuidv7

Category: Data types. Version: 1.7. Optional, enabled per project.

## About

UUID v7 starts with a millisecond timestamp, so new ids sort after old ones. As a primary key that keeps B-tree inserts at the right edge of the index instead of scattered, which means less index bloat and better cache use than random v4 ids. Postgres 17 has no built-in v7 generator; this extension adds one.

## Enable it

```sql
create extension if not exists pg_uuidv7 with schema extensions;
```

## Example

```sql
create table orders (
  id uuid primary key default uuid_generate_v7(),
  total_cents int not null
);

select id, uuid_v7_to_timestamptz(id) as created_at from orders order by id desc limit 5;
```

Upstream: https://github.com/fboulnois/pg_uuidv7