Skip to content

no-random-uuid-in-sql

Embedded SQL generates a random UUIDv4 instead of a time-ordered UUIDv7.

Why

Random UUIDv4 primary keys scatter inserts across B-tree pages; UUIDv7 keys preserve time ordering.

Fix

Use uuidv7() where the supported PostgreSQL version provides it.

Examples

Before — flagged Table defaults to a random UUID
app/store.py
SQL = "CREATE TABLE call (id UUID PRIMARY KEY DEFAULT gen_random_uuid())"
After — preferred Table defaults to UUIDv7
app/store.py
SQL = "CREATE TABLE call (id UUID PRIMARY KEY DEFAULT uuidv7())"

Formerly: no-gen-random-uuid-in-sql