pg_slug_gen
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_slug_gen | 1.0.0 | FUNC | MIT | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4550 | pg_slug_gen | No | Yes | No | Yes | No | Yes | - |
| Related | pg_hashids sequential_uuids uuid-ossp pg_uuidv7 |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0.0 | 1817161514 | pg_slug_gen | - |
| RPM | PIGSTY | 1.0.0 | 1817161514 | pg_slug_gen_$v | - |
| DEB | PIGSTY | 1.0.0 | 1817161514 | postgresql-$v-pg-slug-gen | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.0.0 el8.x86_64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0.0 el8.x86_64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0.0 el8.x86_64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 1.0.0 el8.x86_64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY MISS |
| el8.aarch64 | PIGSTY 1.0.0 el8.aarch64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0.0 el8.aarch64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0.0 el8.aarch64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 1.0.0 el8.aarch64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY MISS |
| el9.x86_64 | PIGSTY 1.0.0 el9.x86_64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0.0 el9.x86_64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0.0 el9.x86_64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 1.0.0 el9.x86_64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY MISS |
| el9.aarch64 | PIGSTY 1.0.0 el9.aarch64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0.0 el9.aarch64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0.0 el9.aarch64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 1.0.0 el9.aarch64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY MISS |
| el10.x86_64 | PIGSTY 1.0.0 el10.x86_64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 1.0.0 el10.x86_64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 1.0.0 el10.x86_64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 1.0.0 el10.x86_64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY MISS |
| el10.aarch64 | PIGSTY 1.0.0 el10.aarch64.pg18 : pg_slug_gen_18 pg_slug_gen_18-1.0.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 1.0.0 el10.aarch64.pg17 : pg_slug_gen_17 pg_slug_gen_17-1.0.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 1.0.0 el10.aarch64.pg16 : pg_slug_gen_16 pg_slug_gen_16-1.0.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 1.0.0 el10.aarch64.pg15 : pg_slug_gen_15 pg_slug_gen_15-1.0.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY MISS |
| d12.x86_64 | PIGSTY 1.0.0 d12.x86_64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0.0 d12.x86_64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0.0 d12.x86_64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~bookworm_amd64.deb
| PIGSTY 1.0.0 d12.x86_64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~bookworm_amd64.deb
| PIGSTY MISS |
| d12.aarch64 | PIGSTY 1.0.0 d12.aarch64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0.0 d12.aarch64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0.0 d12.aarch64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~bookworm_arm64.deb
| PIGSTY 1.0.0 d12.aarch64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~bookworm_arm64.deb
| PIGSTY MISS |
| d13.x86_64 | PIGSTY 1.0.0 d13.x86_64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~trixie_amd64.deb
| PIGSTY 1.0.0 d13.x86_64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~trixie_amd64.deb
| PIGSTY 1.0.0 d13.x86_64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~trixie_amd64.deb
| PIGSTY 1.0.0 d13.x86_64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~trixie_amd64.deb
| PIGSTY MISS |
| d13.aarch64 | PIGSTY 1.0.0 d13.aarch64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~trixie_arm64.deb
| PIGSTY 1.0.0 d13.aarch64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~trixie_arm64.deb
| PIGSTY 1.0.0 d13.aarch64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~trixie_arm64.deb
| PIGSTY 1.0.0 d13.aarch64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~trixie_arm64.deb
| PIGSTY MISS |
| u22.x86_64 | PIGSTY 1.0.0 u22.x86_64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~jammy_amd64.deb
| PIGSTY 1.0.0 u22.x86_64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~jammy_amd64.deb
| PIGSTY 1.0.0 u22.x86_64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~jammy_amd64.deb
| PIGSTY 1.0.0 u22.x86_64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~jammy_amd64.deb
| PIGSTY MISS |
| u22.aarch64 | PIGSTY 1.0.0 u22.aarch64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~jammy_arm64.deb
| PIGSTY 1.0.0 u22.aarch64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~jammy_arm64.deb
| PIGSTY 1.0.0 u22.aarch64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~jammy_arm64.deb
| PIGSTY 1.0.0 u22.aarch64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~jammy_arm64.deb
| PIGSTY MISS |
| u24.x86_64 | PIGSTY 1.0.0 u24.x86_64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~noble_amd64.deb
| PIGSTY 1.0.0 u24.x86_64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~noble_amd64.deb
| PIGSTY 1.0.0 u24.x86_64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~noble_amd64.deb
| PIGSTY 1.0.0 u24.x86_64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~noble_amd64.deb
| PIGSTY MISS |
| u24.aarch64 | PIGSTY 1.0.0 u24.aarch64.pg18 : postgresql-18-pg-slug-gen postgresql-18-pg-slug-gen_1.0.0-2PIGSTY~noble_arm64.deb
| PIGSTY 1.0.0 u24.aarch64.pg17 : postgresql-17-pg-slug-gen postgresql-17-pg-slug-gen_1.0.0-2PIGSTY~noble_arm64.deb
| PIGSTY 1.0.0 u24.aarch64.pg16 : postgresql-16-pg-slug-gen postgresql-16-pg-slug-gen_1.0.0-2PIGSTY~noble_arm64.deb
| PIGSTY 1.0.0 u24.aarch64.pg15 : postgresql-15-pg-slug-gen postgresql-15-pg-slug-gen_1.0.0-2PIGSTY~noble_arm64.deb
| PIGSTY MISS |
Build
You can build the RPM / DEB packages for pg_slug_gen using pig build:
pig build pkg pg_slug_gen # build RPM / DEB packages
Install
You can install pg_slug_gen directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_slug_gen; # Install for current active PG version
pig ext install -y pg_slug_gen -v 18 # PG 18
pig ext install -y pg_slug_gen -v 17 # PG 17
pig ext install -y pg_slug_gen -v 16 # PG 16
pig ext install -y pg_slug_gen -v 15 # PG 15
dnf install -y pg_slug_gen_18 # PG 18
dnf install -y pg_slug_gen_17 # PG 17
dnf install -y pg_slug_gen_16 # PG 16
dnf install -y pg_slug_gen_15 # PG 15
apt install -y postgresql-18-pg-slug-gen # PG 18
apt install -y postgresql-17-pg-slug-gen # PG 17
apt install -y postgresql-16-pg-slug-gen # PG 16
apt install -y postgresql-15-pg-slug-gen # PG 15
Create Extension:
CREATE EXTENSION pg_slug_gen;
Usage
Syntax:
CREATE EXTENSION pg_slug_gen; SELECT gen_random_slug(); SELECT gen_random_slug(13);Source: PGXN release README
pg_slug_gen generates timestamp-based slugs using cryptographic randomness. The PGXN release README describes it as a PostgreSQL extension that maps timestamp digits into letter buckets and inserts a hyphen in the middle, producing URL-friendly slugs.
Function
The documented SQL function is:
gen_random_slug(slug_length int DEFAULT 16) RETURNS text
The README shows these interfaces:
gen_random_slug() -- default: 16 (microseconds)
gen_random_slug(10) -- seconds
gen_random_slug(13) -- milliseconds
gen_random_slug(16) -- microseconds
gen_random_slug(19) -- nanoseconds
Precision and Length
The release README maps precision to timestamp digits and maximum collision-free throughput:
10digits for seconds, up to 1 insert per second13digits for milliseconds, up to 1,000 inserts per second16digits for microseconds, up to 1,000,000 inserts per second19digits for nanoseconds, up to 1 billion inserts per second
The slug includes a midpoint hyphen:
- seconds:
5-5pattern, 11 characters total - milliseconds:
6-7pattern, 14 characters - microseconds:
8-8pattern, 17 characters - nanoseconds:
9-10pattern, 20 characters
Examples
SELECT gen_random_slug();
SELECT gen_random_slug(10);
SELECT gen_random_slug(13);
SELECT gen_random_slug(16);
SELECT gen_random_slug(19);
As a table default:
CREATE TABLE products (
id serial PRIMARY KEY,
name text NOT NULL,
slug text DEFAULT gen_random_slug() UNIQUE
);
How It Works
The release README describes the algorithm as:
- take the current timestamp at the chosen precision
- map each digit to a QWERTY-based character bucket
- choose one random character from that bucket using
pg_strong_random() - insert a hyphen at the midpoint
The README also notes that same-timestamp collisions remain possible, but with microsecond precision the probability is stated as roughly 1 in 10 million.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.